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

[zig] Fix build.zig bug #4366

Merged
merged 2 commits into from
Oct 6, 2024
Merged

[zig] Fix build.zig bug #4366

merged 2 commits into from
Oct 6, 2024

Conversation

VisenDev
Copy link
Contributor

@VisenDev VisenDev commented Oct 5, 2024

Before this change, building raylib using the config options field fails.

    const ray = b.dependency("raylib", .{
        .target = target,
        .optimize = optimize,
        .config = @as([]const u8, "-DSUPPORT_CUSTOM_FRAME_CONTROL"),
    });
Robert@Roberts-MacBook-Pro-2 ~/z/dev (master)> zig build
thread 1133588 panic: attempt to use null value
/Users/Robert/.cache/zig/p/1220cda9f85d36e6f5be4bac65430b056c4e3d4ab3fafcf71c73ec6b1853e8a20856/src/build.zig:81:58: 0x10a8dfba5 in compileRaylib (build)
            flag = flag[0..std.mem.indexOf(u8, flag, " ").?]; // Flag is only one word, so capture till space
                                                         ^
/Users/Robert/.cache/zig/p/1220cda9f85d36e6f5be4bac65430b056c4e3d4ab3fafcf71c73ec6b1853e8a20856/src/build.zig:369:34: 0x10a8e5219 in build (build)
    const lib = try compileRaylib(b, target, optimize, options);
                                 ^
/Users/Robert/.cache/zig/p/1220cda9f85d36e6f5be4bac65430b056c4e3d4ab3fafcf71c73ec6b1853e8a20856/build.zig:6:21: 0x10a8e6af4 in build (build)
    try raylib.build(b);
                    ^
/usr/local/Cellar/zig/0.13.0/lib/zig/std/Build.zig:2117:43: 0x10a86c484 in runBuild__anon_15294 (build)
        .ErrorUnion => try build_zig.build(b),
                                          ^
/usr/local/Cellar/zig/0.13.0/lib/zig/std/Build.zig:2097:29: 0x10a823ab9 in dependencyInner__anon_14532 (build)
        sub_builder.runBuild(bz) catch @panic("unhandled error");
                            ^
/usr/local/Cellar/zig/0.13.0/lib/zig/std/Build.zig:1954:35: 0x10a7d7c00 in dependency__anon_11228 (build)
            return dependencyInner(b, name, pkg.build_root, if (@hasDecl(pkg, "build_zig")) pkg.build_zig else null, pkg_hash, pkg.deps, args);
                                  ^
/Users/Robert/zig/dev/build.zig:98:29: 0x10a7d2f68 in build (build)
    const ray = b.dependency("raylib", .{
                            ^
/usr/local/Cellar/zig/0.13.0/lib/zig/std/Build.zig:2117:43: 0x10a7b58c0 in runBuild__anon_8431 (build)
        .ErrorUnion => try build_zig.build(b),
                                          ^
/usr/local/Cellar/zig/0.13.0/lib/zig/compiler/build_runner.zig:301:29: 0x10a7b0424 in main (build)
        try builder.runBuild(root);
                            ^
/usr/local/Cellar/zig/0.13.0/lib/zig/std/start.zig:524:37: 0x10a7b808b in main (build)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x7ff8049af30f in ??? (???)
Unwind information for `???:0x7ff8049af30f` was not available, trace may be incomplete

???:?:?: 0x0 in ??? (???)
error: the following build command crashed:
/Users/Robert/zig/dev/.zig-cache/o/1e0d00ce3951a8ebfb69b30e398dd680/build /usr/local/Cellar/zig/0.13.0/bin/zig /Users/Robert/zig/dev /Users/Robert/zig/dev/.zig-cache /Users/Robert/.cache/zig --seed 0xd202b3c9 -Z7e6f5d7f6781950c

The code get broken by this line in config.h

#ifdef RL_SUPPORT_MESH_GPU_SKINNING

To fix this, I made the following changes

  • build.zig now skips processing any config.h lines that start with #if,
  • build.zig now continues rather than panics if std.mem.indexOf(u8, flag, " ") fails.

I also added a comment that the config option should be a list of cflags, since I had initially assumed this option was meant to be a path to a custom config.h file. I didn't realize my mistake until reading thru the build code very closely, so a clarifying comment should help explain how this field ought to be properly used.

@VisenDev VisenDev changed the title Fix build.zig bug [zig] Fix build.zig bug Oct 5, 2024
@VisenDev
Copy link
Contributor Author

VisenDev commented Oct 5, 2024

To reproduce this bug, you can run the following command in the raylib master branch.

zig build -Dconfig="-DSUPPORT_CUSTOM_FRAME_CONTROL"

Tested with both zig 0.12.0 and zig 0.13.0

Screenshot 2024-10-05 at 10 40 42 AM

@raysan5 raysan5 merged commit b290d47 into raysan5:master Oct 6, 2024
@raysan5
Copy link
Owner

raysan5 commented Oct 6, 2024

@VisenDev I'm merging it but note I don't maintain the buld.zig system so it could fail for other users.

psxdev pushed a commit to raylib4Consoles/raylib that referenced this pull request Nov 18, 2024
* fixed zig config.h bug

* zig fmt
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.

2 participants