IO in build.zig

Hi !

As the new Io fs interface was merged, I’m finishing to migrate several of my build.zig’s. In particular, I would like to traverse a directory using `std.Io.fs`.

However, the std.Build doesn’t seem to provide an Io interface. So my question is did I miss it or is it no yet given by the build system ?

For the time being, I’m using global_single_threaded.

Thanks !

PS: I’m on the latest master branch as I’m building from source, I there is a solution that is from source, It’s fine by me !

You want b.graph.io

4 Likes

It’s in b.graph.io :slight_smile:

I had the same problem for a file-exist check which ended up looking like this (with backward compatibility for Zig 0.15.2):

fn fileExists(b: *Build, path: []const u8) !bool {
    // FIXME: drop support for 0.15.x
    if (builtin.zig_version.minor > 15) {
        return !std.meta.isError(std.Io.Dir.cwd().access(b.graph.io, path, .{}));
    } else {
        return !std.meta.isError(std.fs.cwd().access(path, .{}));
    }
}
3 Likes

Thank you both !