Starting from the 2024-01-04 nightly, zig build run fails with
/tmp/examples-raylib.zig/build.zig:26:19: error: no field or member function named 'getOsTag' in 'Build.ResolvedTarget'
switch (target.getOsTag()) {
~~~~~~^~~~~~~~~
/nix/store/gbai9mdz2rxziv3jaissdj68d7x3mc1g-zig-0.12.0-dev.2036+fc79b22a9/lib/std/Build.zig:2065:28: note: struct declared here
pub const ResolvedTarget = struct {
^~~~~~
referenced by:
runBuild__anon_8081: /nix/store/gbai9mdz2rxziv3jaissdj68d7x3mc1g-zig-0.12.0-dev.2036+fc79b22a9/lib/std/Build.zig:1851:37
steps__anon_7895: /nix/store/gbai9mdz2rxziv3jaissdj68d7x3mc1g-zig-0.12.0-dev.2036+fc79b22a9/lib/build_runner.zig:1033:29
remaining reference traces hidden; use '-freference-trace' to see all reference traces
The issue seems to be related to the commit ziglang/zig@142471f which introduced many changes to the build system API. I attempted to fix this issue myself, but I am not very familiar with Zig, and I eventually got stuck on another error:
/tmp/examples-raylib.zig/build.zig:126:56: error: no field named 'modules' in struct 'Build.Step.Compile'
.{ .name = "raylib", .module = lib.modules.get("raylib").? },
^~~~~~~
/nix/store/gbai9mdz2rxziv3jaissdj68d7x3mc1g-zig-0.12.0-dev.2036+fc79b22a9/lib/std/Build/Step/Compile.zig:1:1: note: struct declared here
const builtin = @import("builtin");
^~~~~
referenced by:
runBuild__anon_8081: /nix/store/gbai9mdz2rxziv3jaissdj68d7x3mc1g-zig-0.12.0-dev.2036+fc79b22a9/lib/std/Build.zig:1851:37
steps__anon_7895: /nix/store/gbai9mdz2rxziv3jaissdj68d7x3mc1g-zig-0.12.0-dev.2036+fc79b22a9/lib/build_runner.zig:1033:29
remaining reference traces hidden; use '-freference-trace' to see all reference traces
Here are the changes I made to get to this state, not sure if helpful or not:
diff --git a/build.zig b/build.zig
index b5d215e..82685cd 100644
--- a/build.zig
+++ b/build.zig
@@ -23,7 +23,7 @@ pub fn build(b: *std.Build) !void {
const exampleNr = b.option(usize, "example", try exampleDescription(b)) orelse 1;
try writeExampleFile(exampleNr);
- switch (target.getOsTag()) {
+ switch (target.result.os.tag) {
.wasi, .emscripten => {
const emscriptenSrc = "src/raylib/emscripten/";
const webCachedir = "zig-cache/web/";
@@ -36,22 +36,22 @@ pub fn build(b: *std.Build) !void {
}
const lib = b.addStaticLibrary(.{
.name = APP_NAME,
- .root_source_file = std.build.FileSource.relative("src/web.zig"),
+ .root_source_file = std.Build.LazyPath.relative("src/web.zig"),
.optimize = mode,
.target = target,
});
lib.addIncludePath(.{ .path = raylibSrc });
lib.addIncludePath(.{ .path = rayguiSrc });
- const emcc_file = switch (b.host.target.os.tag) {
+ const emcc_file = switch (b.host.result.os.tag) {
.windows => "emcc.bat",
else => "emcc",
};
- const emar_file = switch (b.host.target.os.tag) {
+ const emar_file = switch (b.host.result.os.tag) {
.windows => "emar.bat",
else => "emar",
};
- const emranlib_file = switch (b.host.target.os.tag) {
+ const emranlib_file = switch (b.host.result.os.tag) {
.windows => "emranlib.bat",
else => "emranlib",
};
@@ -119,10 +119,10 @@ pub fn build(b: *std.Build) !void {
lib.addIncludePath(.{ .path = raylibSrc });
lib.addIncludePath(.{ .path = rayguiSrc });
lib.addIncludePath(.{ .path = raylibSrc ++ "extras/" });
- lib.addAnonymousModule("raylib", .{ .source_file = .{ .path = raylibBindingSrc ++ "raylib.zig" } });
- lib.addAnonymousModule("raygui", .{
- .source_file = .{ .path = rayguiBindingSrc ++ "raygui.zig" },
- .dependencies = &.{
+ lib.root_module.addAnonymousImport("raylib", .{ .root_source_file = .{ .path = raylibBindingSrc ++ "raylib.zig" } });
+ lib.root_module.addAnonymousImport("raygui", .{
+ .root_source_file = .{ .path = rayguiBindingSrc ++ "raygui.zig" },
+ .imports = &.{
.{ .name = "raylib", .module = lib.modules.get("raylib").? },
},
});
Starting from the
2024-01-04nightly,zig build runfails withThe issue seems to be related to the commit ziglang/zig@142471f which introduced many changes to the build system API. I attempted to fix this issue myself, but I am not very familiar with Zig, and I eventually got stuck on another error:
Here are the changes I made to get to this state, not sure if helpful or not: