diff --git a/build.zig b/build.zig index 5de3dabdedea8..1223d96ad0fce 100644 --- a/build.zig +++ b/build.zig @@ -67,13 +67,22 @@ pub fn build(b: *std.Build) void { const cache_include = std.fs.path.join(b.allocator, &.{ b.sysroot.?, "cache", "sysroot", "include" }) catch @panic("Out of memory"); defer b.allocator.free(cache_include); - // TODO: Remove compatibility shim when Zig 0.16.0 is the minimum required version. - const open_dir_opts: std.fs.Dir.OpenOptions = if (@hasField(std.fs.Dir.OpenOptions, "follow_symlinks")) - .{ .access_sub_paths = true, .follow_symlinks = false } - else - .{ .access_sub_paths = true, .no_follow = true }; - var dir = std.fs.openDirAbsolute(cache_include, open_dir_opts) catch @panic("No emscripten cache. Generate it!"); - dir.close(); + // TODO: Remove compatibility shim when minimum Zig version is 0.16.0. + if (@hasDecl(std.Io, "Dir")) { + // Zig 0.16.0-dev + var dir = std.Io.Dir.openDirAbsolute(mod.owner.graph.io, cache_include, .{ + .access_sub_paths = true, + .follow_symlinks = false, + }) catch @panic("No emscripten cache. Generate it!"); + dir.close(mod.owner.graph.io); + } else if (@hasDecl(std.fs, "Dir")) { + // Zig 0.15.x + var dir = std.fs.openDirAbsolute(cache_include, .{ + .access_sub_paths = true, + .no_follow = true, + }) catch @panic("No emscripten cache. Generate it!"); + dir.close(); + } else @compileError("Fix `openDirAbsolute` compatibility shim"); mod.addIncludePath(.{ .cwd_relative = cache_include }); },