Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build.zig #4374

Merged
merged 1 commit into from
Oct 10, 2024
Merged

Fix build.zig #4374

merged 1 commit into from
Oct 10, 2024

Conversation

cedeon
Copy link
Contributor

@cedeon cedeon commented Oct 9, 2024

I can only get zig to build raylib if I do this + move the file to the parent directory.

@CrackedPixel
Copy link
Sponsor Contributor

I can only get zig to build raylib if I do this + move the file to the parent directory.

  1. Did you get the latest changes from master branch?
  2. What platform are you building on?
  3. Is the issue building or using it after building?

I tried this and it worked perfectly (linux x64, zig 0.13.0):

git clone git@github.com:raysan5/raylib.git
cd raylib
zig build

@sagehane
Copy link
Contributor

I'm having the same issues with the latest commit on Linux, using the addRaylib function with the Zig package manager.

Seems to be introduced by #4358 where it caused a mismatch between the fields of Options and the expected fields inside the logic of addRaylib.

.platform_drm = options.platform_drm,

platform: PlatformBackend = .glfw,

@sagehane
Copy link
Contributor

How to reproduce:

  1. Start a new Zig project with zig init.
  2. Add a sufficiently new version of Raylib as a dependency with zig fetch --save=raylib https://github.com/raysan5/raylib/archive/3fb1ba25aca0a6b023ca254a0910df36b0744e64.tar.gz
  3. Add the following lines inside the build function of build.zig:
    const raylib = @import("raylib");
    const raylib_lib = try raylib.addRaylib(b, target, optimize, .{});
  1. Run zig build to get the following output:
$ zig build
/home/<user>/.cache/zig/p/12207c7d223c949e1bdfbb2a789770427e0c61d4c288ef0e8935b1dc52ac2f82f807/src/build.zig:27:33: error: no field named 'platform_drm' in struct 'src.build.Options'
        .platform_drm = options.platform_drm,
                                ^~~~~~~~~~~~
/home/<user>/.cache/zig/p/12207c7d223c949e1bdfbb2a789770427e0c61d4c288ef0e8935b1dc52ac2f82f807/src/build.zig:294:21: note: struct declared here
pub const Options = struct {
                    ^~~~~~
referenced by:
    build: /home/<user>/Projects/mario/build.zig:33:44
    runBuild__anon_5106: /nix/store/h4xqfb0ganmpwzrzpbnxmhvy74r9hwfd-zig-0.14.0-dev.1823+b00cbecfd/lib/std/Build.zig:2294:33
    6 reference(s) hidden; use '-freference-trace=8' to see all references

@sagehane
Copy link
Contributor

sagehane commented Oct 10, 2024

I also needed the following patch to get it building:

diff --git a/src/build.zig b/src/build.zig
index d79fb0f3..fef4893c 100644
--- a/src/build.zig
+++ b/src/build.zig
@@ -24,11 +24,11 @@ pub fn addRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
         .rshapes = options.rshapes,
         .rtext = options.rtext,
         .rtextures = options.rtextures,
-        .platform_drm = options.platform_drm,
+        .platform = options.platform,
         .shared = options.shared,
         .linux_display_backend = options.linux_display_backend,
         .opengl_version = options.opengl_version,
-        .config = options.config,
+        //.config = options.config,
     });
     const raylib = raylib_dep.artifact("raylib");
 
@@ -366,7 +366,7 @@ pub fn build(b: *std.Build) !void {
         .shared = b.option(bool, "shared", "Compile as shared library") orelse defaults.shared,
         .linux_display_backend = b.option(LinuxDisplayBackend, "linux_display_backend", "Linux display backend to use") orelse defaults.linux_display_backend,
         .opengl_version = b.option(OpenglVersion, "opengl_version", "OpenGL version to use") orelse defaults.opengl_version,
-        .config = b.option([]const u8, "config", "Compile with custom define macros overriding config.h") orelse null,
+        .config = b.option([]const u8, "config", "Compile with custom define macros overriding config.h"),
     };
 
     const lib = try compileRaylib(b, target, optimize, options);

The orelse null is redundant so I removed that. It seems like b.dependencyFromBuildZig doesn't support ?[]const u8 (the type of options.config) so I commented it out. Doing something like orelse "" caused some other errors. I have no idea if this approach is correct though.

@raysan5 raysan5 merged commit c4be013 into raysan5:master Oct 10, 2024
@raysan5
Copy link
Owner

raysan5 commented Oct 10, 2024

@cedeon @CrackedPixel @sagehane Thanks for reporting! Please note that I don't maintain the build.zig so I usually trust Zig experienced users sending PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants