Skip to content

Commit b4c5cd2

Browse files
mdm5995jayschwa
andauthored
Update build.zig for 0.16 fs.Dir -> Io.Dir (#31)
Co-authored-by: Jay Petacat <jay@jayschwa.net>
1 parent 25dc764 commit b4c5cd2

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

build.zig

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,22 @@ pub fn build(b: *std.Build) void {
6767
const cache_include = std.fs.path.join(b.allocator, &.{ b.sysroot.?, "cache", "sysroot", "include" }) catch @panic("Out of memory");
6868
defer b.allocator.free(cache_include);
6969

70-
// TODO: Remove compatibility shim when Zig 0.16.0 is the minimum required version.
71-
const open_dir_opts: std.fs.Dir.OpenOptions = if (@hasField(std.fs.Dir.OpenOptions, "follow_symlinks"))
72-
.{ .access_sub_paths = true, .follow_symlinks = false }
73-
else
74-
.{ .access_sub_paths = true, .no_follow = true };
75-
var dir = std.fs.openDirAbsolute(cache_include, open_dir_opts) catch @panic("No emscripten cache. Generate it!");
76-
dir.close();
70+
// TODO: Remove compatibility shim when minimum Zig version is 0.16.0.
71+
if (@hasDecl(std.Io, "Dir")) {
72+
// Zig 0.16.0-dev
73+
var dir = std.Io.Dir.openDirAbsolute(mod.owner.graph.io, cache_include, .{
74+
.access_sub_paths = true,
75+
.follow_symlinks = false,
76+
}) catch @panic("No emscripten cache. Generate it!");
77+
dir.close(mod.owner.graph.io);
78+
} else if (@hasDecl(std.fs, "Dir")) {
79+
// Zig 0.15.x
80+
var dir = std.fs.openDirAbsolute(cache_include, .{
81+
.access_sub_paths = true,
82+
.no_follow = true,
83+
}) catch @panic("No emscripten cache. Generate it!");
84+
dir.close();
85+
} else @compileError("Fix `openDirAbsolute` compatibility shim");
7786

7887
mod.addIncludePath(.{ .cwd_relative = cache_include });
7988
},

0 commit comments

Comments
 (0)