Skip to content

[build][Zig] 0.17 migration #5951

Open
miker2049 wants to merge 11 commits into
raysan5:masterfrom
miker2049:zig-17
Open

[build][Zig] 0.17 migration #5951
miker2049 wants to merge 11 commits into
raysan5:masterfrom
miker2049:zig-17

Conversation

@miker2049

Copy link
Copy Markdown

Zig 0.17 is not out yet, but it (supposedly) will be soon. There was recently some breaking changes to the build system, causing nightly zig to not work with raylib's build.zig.

Because the aforementioned changes are not in a major release yet, this probably should not be merged yet. But it doesn't seem like there will be many further breaking changes before the major release, so this can be considered a tentative PR for when it happens. One further consideration here is that this branch uses an unmerged branch of zemscripten which updates it for 0.17. So, hopefully that can be merged before this should be!

@miker2049 miker2049 changed the title 0.17 migration for zig build [build][Zig] 0.17 migration for zig build Jul 3, 2026
@miker2049 miker2049 changed the title [build][Zig] 0.17 migration for zig build [build][Zig] 0.17 migration Jul 3, 2026
@raysan5

raysan5 commented Jul 17, 2026

Copy link
Copy Markdown
Owner

@michaelfiber, @Not-Nik, @HaxSam, @shreyassanthu77, @pamarcos, @jn-jairo, @jirizverina, @BrunoDG, @maiconpintoabreu, @beppvis Please, could you take a look to this PR?

NOTE: I'm pinging all of you in my list of Zig build system maintainers, if any of you doesn't want to be pinged for this kind of issues, just let me know and I'll take you out of the maintainers list.

@Not-Nik Not-Nik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the hash mismatch this compiles cleanly. Since I believe our policy is to keep up with master when required, r+

Comment thread build.zig.zon
@@ -21,8 +21,8 @@
.hash = "N-V-__8AAJl1DwBezhYo_VE6f53mPVm00R-Fk28NPW7P14EQ",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing a hash mismatch for this package with the patch on 0.17.0-dev.1158+1d1193aa7, where it fetches N-V-__8AALBDi159DH5nlv03KX8rG4GFfY8m-GWnFC9DSQL2. Either I'm being MITMed or the hash actually changed (through Zig or emsdk itself). Could someone verify (on a clean build/system).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran it on a clean build, cleaned all caches, with both the most recent zig version available at the moment 0.17.0-dev.1417+20befa4e6 as well the minimum version set in this PR 0.17.0-dev.1158+1d1193aa7 and I did not get any hash error, the hash downloaded is the N-V-__8AAJl1DwBezhYo_VE6f53mPVm00R-Fk28NPW7P14EQ.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaned up all my cached files as well, and the mismatch is gone. Strange it occurred at all though..

@jn-jairo jn-jairo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new emcc is not building the files.

This is with the new code

Image

And this is with the old code from raylib master

Image

As the note about the install path says, this code is using the wrong path to run, trying to get it from the zig-out/<filename> instead of the zig-out/web/<module>/<filename>.

An old version of the build.zig was duplicating the installed files at the root zig-out/<filename> but it was already fixed, you must have a dirty install with old files already built, so you are not running from files built with the new code.

The only error I get is

textures_bunnymark
└─ run dependency
   └─ install generated/
      └─ run dependency (textures_bunnymark) w
shared:INFO: (Emscripten: Running sanity checks)
failed command: /mnt/hd/projects/code/raylib-pr/zig-pkg/N-V-__8AAJl1DwBezhYo_VE6f53mPVm00R-Fk28NPW7P14EQ/upstream/emscripten/emcc.py -O3 -sASYNCIFY -sTOTAL_MEMORY=134217728 -sFORCE_FILESYSTEM=1 -sMALLOC=emmalloc -sUSE_GLFW=3 -sEXPORTED_RUNTIME_METHODS=ccall ./.zig-cache/o/d879f429e89efb52350f0b58e42915cc/libtextures_bunnymark.a ./.zig-cache/o/667685bf2c596541996f084e5ef321b6/libraylib.a -o ./.zig-cache/o/a995d324b9810090a6b25a0ae46d4312/textures_bunnymark --shell-file /mnt/hd/projects/code/raylib-pr/src/shell.html

I am using Kubuntu 24.04.4 LTS and besides the web build, the desktop build is working on my machine.

Tested with the most recent zig version available at the moment 0.17.0-dev.1417+20befa4e6 as well the minimum version set in this PR 0.17.0-dev.1158+1d1193aa7.

Comment thread build.zig Outdated
const emrun_step = emsdk.emrunStep(
b,
b.getInstallPath(install_dir, html_filename),
b.graph.path(.install_prefix, b.fmt("{s}/{s}.html", .{ filename, wasm.name })),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong path, it should be the one from install_dir web/<module>/<filename> so install_dir.custom instead of filename should work.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread build.zig Outdated
.install_dir = install_dir,
.out_file_name = wasm.name,
});
b.getInstallStep().dependOn(emcc_step);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not what you changed, but this line should be removed, it forces to run the emcc_step for every example even when we are not building the examples, the emcc_step will run anyway when building one or more examples because of the run_step and all step.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 23e73da

miker2049 added 10 commits July 19, 2026 18:48
- update calls to `buildDir` and `findProgram` to their new
interfaces/calling sites.
- fix issue where you can't import zon anymore as slice (?)
Examples depend on raylib anyway, and if using emsdk, it will be
activated already.  This activation was causing an error in zig
nightly, so the change here.
@miker2049
miker2049 requested a review from jn-jairo July 20, 2026 01:57
@miker2049

Copy link
Copy Markdown
Author

I realized that resource asset files were not working for the emscripten examples. It is blocked by this issue with upstream zemscripten, where the build file there does not actually support virtual paths.

@jn-jairo

Copy link
Copy Markdown
Contributor

I realized that resource asset files were not working for the emscripten examples. It is blocked by this issue with upstream zemscripten, where the build file there does not actually support virtual paths.

Ok, let's see what we get here, zig-gamedev/zemscripten didn't merge the zig 0.17 PR, so you changed the repo here to point to the PR branch at Yinameah/zemscripten and also there is a bug with preload_paths not using the ResourceFile.get() they added.

And as you said it is temporary while they don't merge it.

One further consideration here is that this branch uses an unmerged branch of zemscripten which updates it for 0.17. So, hopefully that can be merged before this should be!

So, we are waiting for the zig-gamedev team to do something about the zig upgrade and the preload_paths bug.

The last response from zig-gamedev team was a month ago at the zig 0.17 issue where they said:

Thanks for reaching out. It's difficult to stay on top of maintenance churn of all the zig-gamedev libraries so any help is very welcome. If you want to discuss anything in a more informal forum please feel free to join us on Discord https://discord.gg/JrYcW5sUD

And by looking at other repos from zig-gamedev they don't upgrade zig to a new version until way later. Like the zaudio upgrade to zig 0.16 that got merged just last week.

So, will we wait for zig-gamedev to fix things up or what?

@jn-jairo jn-jairo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From here it should be enough, but the zemscripten is bugged anyway, maybe we will need to change something more here later.

Comment thread build.zig
const EmccExamplesPreloadMap = std.static_string_map.StaticStringMap([]const emsdk.zemscripten.ResourceFile);
const EmccExamplesPreloadKV = struct { []const u8, []const emsdk.zemscripten.ResourceFile };
const emcc_examples_preloads_ = @import("examples/example_resources.zon");
const emcc_examples_preloads: []const EmccExamplesPreloadKV = @ptrCast(@alignCast(&emcc_examples_preloads_));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the preload_paths bug on zemscripten this part is not working, the new src_path is a std.Build.LazyPath, this cast is not filling it up. Here is what I did:

            const ResourceDesc = struct {
                src_path: []const u8,
                virtual_path: []const u8,
            };

            const EmccExamplesPreloadMap = std.StaticStringMap([]const ResourceDesc);
            const EmccExamplesPreloadKV = struct { []const u8, []const ResourceDesc };
            const emcc_examples_preloads: []const EmccExamplesPreloadKV = @import("examples/example_resources.zon");
            const emcc_examples_preloads_map = EmccExamplesPreloadMap.initComptime(emcc_examples_preloads);

            const preload_paths_: []const ResourceDesc = emcc_examples_preloads_map.get(filename) orelse &.{};

            var preload_paths = std.ArrayList(emsdk.zemscripten.ResourceFile).empty;
            defer preload_paths.deinit(b.allocator);

            for (preload_paths_) |preload_path| {
                try preload_paths.append(b.allocator, .{
                    .src_path = b.path(preload_path.src_path),
                    .virtual_path = preload_path.virtual_path,
                });
            }

            const emcc_step = emsdk.emccStep(b, raylib, wasm, .{
                .optimize = optimize,
                .flags = emcc_flags,
                .settings = emcc_settings,
                .preload_paths = preload_paths.items,
                .shell_file_path = b.path("src/shell.html"),
                .install_dir = install_dir,
                .out_file_name = wasm.name,
            });

also there is a bug with preload_paths not using the ResourceFile.get() they added.

I tried to fix it using your proposed solution emcc.addArg(path.get(b)) but turns out the whole ResourceFile.get() is wrong, as it was never used looks like zig never bothered to validate this function, so the self.src_path.path(b, "") it is using just returns another LazyPath instead of a string, but the function needs a string. This is from a commit after the one locked in the master raylib so that is why it works now in raylib, after they changed to that ResourceFile things didn't work anymore, but they didn't realize 🙄.

This hole is deeper than we thought.

@jn-jairo

Copy link
Copy Markdown
Contributor

I realized that resource asset files were not working for the emscripten examples. It is blocked by this issue with upstream zemscripten, where the build file there does not actually support virtual paths.

I fixed it in my fork try it with the other changes I proposed in the review.

@maiconpintoabreu

Copy link
Copy Markdown
Contributor

My 2 cents here, I do not agree to keep it updated with zig master as we never had a zig release without breaking changes anyway.

@raysan5

raysan5 commented Jul 21, 2026

Copy link
Copy Markdown
Owner

As mentioned, we should probably wait until a more stable state bfore considering merging it...

@jn-jairo

Copy link
Copy Markdown
Contributor

For my personal projects I rather use the zig stable version, but I like to use raylib master to keep updated with the fixes and new features, so I vote to wait until zig 0.17 is released and the dependencies are upgraded to it, but it's good to have the PR ready for it.

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.

5 participants