aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-12-08 17:14:31 -0800
committerAndrew Kelley <andrew@ziglang.org>2025-12-23 22:15:08 -0800
commit950d18ef695bb7a28397e080dc3c201559ec4ee2 (patch)
tree253209139275932ed503a5ea4529594ab70df8cc /src
parent314c906dba32e72317947a15254519b22745b13f (diff)
downloadzig-950d18ef695bb7a28397e080dc3c201559ec4ee2.tar.gz
zig-950d18ef695bb7a28397e080dc3c201559ec4ee2.zip
update all access() to access(io)
Diffstat (limited to 'src')
-rw-r--r--src/Compilation.zig2
-rw-r--r--src/Package/Fetch.zig5
-rw-r--r--src/introspect.zig4
-rw-r--r--src/libs/mingw.zig12
-rw-r--r--src/link/C.zig3
-rw-r--r--src/link/Lld.zig9
-rw-r--r--src/link/MachO.zig21
-rw-r--r--src/main.zig8
8 files changed, 37 insertions, 27 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 280d34cdbf..36429a42f8 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -788,7 +788,7 @@ pub const Directories = struct {
const local_cache: Cache.Directory = switch (local_cache_strat) {
.override => |path| openUnresolved(arena, io, cwd, path, .@"local cache"),
.search => d: {
- const maybe_path = introspect.resolveSuitableLocalCacheDir(arena, cwd) catch |err| {
+ const maybe_path = introspect.resolveSuitableLocalCacheDir(arena, io, cwd) catch |err| {
fatal("unable to resolve zig cache directory: {s}", .{@errorName(err)});
};
const path = maybe_path orelse break :d global_cache;
diff --git a/src/Package/Fetch.zig b/src/Package/Fetch.zig
index e54dcb9914..860fb8974e 100644
--- a/src/Package/Fetch.zig
+++ b/src/Package/Fetch.zig
@@ -418,7 +418,7 @@ pub fn run(f: *Fetch) RunError!void {
const prefixed_pkg_sub_path = prefixed_pkg_sub_path_buffer[0 .. 2 + hash_slice.len];
const prefix_len: usize = if (f.job_queue.read_only) "p/".len else 0;
const pkg_sub_path = prefixed_pkg_sub_path[prefix_len..];
- if (cache_root.handle.access(pkg_sub_path, .{})) |_| {
+ if (cache_root.handle.access(io, pkg_sub_path, .{})) |_| {
assert(f.lazy_status != .unavailable);
f.package_root = .{
.root_dir = cache_root,
@@ -637,8 +637,9 @@ pub fn computedPackageHash(f: *const Fetch) Package.Hash {
/// `computeHash` gets a free check for the existence of `build.zig`, but when
/// not computing a hash, we need to do a syscall to check for it.
fn checkBuildFileExistence(f: *Fetch) RunError!void {
+ const io = f.job_queue.io;
const eb = &f.error_bundle;
- if (f.package_root.access(Package.build_zig_basename, .{})) |_| {
+ if (f.package_root.access(io, Package.build_zig_basename, .{})) |_| {
f.has_build_zig = true;
} else |err| switch (err) {
error.FileNotFound => {},
diff --git a/src/introspect.zig b/src/introspect.zig
index a56a214cbe..3f8308961f 100644
--- a/src/introspect.zig
+++ b/src/introspect.zig
@@ -202,11 +202,11 @@ pub const default_local_zig_cache_basename = ".zig-cache";
/// Searches upwards from `cwd` for a directory containing a `build.zig` file.
/// If such a directory is found, returns the path to it joined to the `.zig_cache` name.
/// Otherwise, returns `null`, indicating no suitable local cache location.
-pub fn resolveSuitableLocalCacheDir(arena: Allocator, cwd: []const u8) Allocator.Error!?[]u8 {
+pub fn resolveSuitableLocalCacheDir(arena: Allocator, io: Io, cwd: []const u8) Allocator.Error!?[]u8 {
var cur_dir = cwd;
while (true) {
const joined = try fs.path.join(arena, &.{ cur_dir, Package.build_zig_basename });
- if (Io.Dir.cwd().access(joined, .{})) |_| {
+ if (Io.Dir.cwd().access(io, joined, .{})) |_| {
return try fs.path.join(arena, &.{ cur_dir, default_local_zig_cache_basename });
} else |err| switch (err) {
error.FileNotFound => {
diff --git a/src/libs/mingw.zig b/src/libs/mingw.zig
index b3ca51e833..93f88b9689 100644
--- a/src/libs/mingw.zig
+++ b/src/libs/mingw.zig
@@ -242,7 +242,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
defer arena_allocator.deinit();
const arena = arena_allocator.allocator();
- const def_file_path = findDef(arena, comp.getTarget(), comp.dirs.zig_lib, lib_name) catch |err| switch (err) {
+ const def_file_path = findDef(arena, io, comp.getTarget(), comp.dirs.zig_lib, lib_name) catch |err| switch (err) {
error.FileNotFound => {
log.debug("no {s}.def file available to make a DLL import {s}.lib", .{ lib_name, lib_name });
// In this case we will end up putting foo.lib onto the linker line and letting the linker
@@ -402,11 +402,12 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
pub fn libExists(
allocator: Allocator,
+ io: Io,
target: *const std.Target,
zig_lib_directory: Cache.Directory,
lib_name: []const u8,
) !bool {
- const s = findDef(allocator, target, zig_lib_directory, lib_name) catch |err| switch (err) {
+ const s = findDef(allocator, io, target, zig_lib_directory, lib_name) catch |err| switch (err) {
error.FileNotFound => return false,
else => |e| return e,
};
@@ -418,6 +419,7 @@ pub fn libExists(
/// see if a .def file exists.
fn findDef(
allocator: Allocator,
+ io: Io,
target: *const std.Target,
zig_lib_directory: Cache.Directory,
lib_name: []const u8,
@@ -443,7 +445,7 @@ fn findDef(
} else {
try override_path.print(fmt_path, .{ lib_path, lib_name });
}
- if (Io.Dir.cwd().access(override_path.items, .{})) |_| {
+ if (Io.Dir.cwd().access(io, override_path.items, .{})) |_| {
return override_path.toOwnedSlice();
} else |err| switch (err) {
error.FileNotFound => {},
@@ -460,7 +462,7 @@ fn findDef(
} else {
try override_path.print(fmt_path, .{lib_name});
}
- if (Io.Dir.cwd().access(override_path.items, .{})) |_| {
+ if (Io.Dir.cwd().access(io, override_path.items, .{})) |_| {
return override_path.toOwnedSlice();
} else |err| switch (err) {
error.FileNotFound => {},
@@ -477,7 +479,7 @@ fn findDef(
} else {
try override_path.print(fmt_path, .{lib_name});
}
- if (Io.Dir.cwd().access(override_path.items, .{})) |_| {
+ if (Io.Dir.cwd().access(io, override_path.items, .{})) |_| {
return override_path.toOwnedSlice();
} else |err| switch (err) {
error.FileNotFound => {},
diff --git a/src/link/C.zig b/src/link/C.zig
index a001f8fdd9..db5acebf07 100644
--- a/src/link/C.zig
+++ b/src/link/C.zig
@@ -371,6 +371,7 @@ pub fn flush(self: *C, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.P
const comp = self.base.comp;
const diags = &comp.link_diags;
const gpa = comp.gpa;
+ const io = comp.io;
const zcu = self.base.comp.zcu.?;
const ip = &zcu.intern_pool;
const pt: Zcu.PerThread = .activate(zcu, tid);
@@ -509,7 +510,7 @@ pub fn flush(self: *C, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.P
const file = self.base.file.?;
file.setEndPos(f.file_size) catch |err| return diags.fail("failed to allocate file: {s}", .{@errorName(err)});
- var fw = file.writer(&.{});
+ var fw = file.writer(io, &.{});
var w = &fw.interface;
w.writeVecAll(f.all_buffers.items) catch |err| switch (err) {
error.WriteFailed => return diags.fail("failed to write to '{f}': {s}", .{
diff --git a/src/link/Lld.zig b/src/link/Lld.zig
index b25b9da9d9..ca15a38bb0 100644
--- a/src/link/Lld.zig
+++ b/src/link/Lld.zig
@@ -359,6 +359,7 @@ fn linkAsArchive(lld: *Lld, arena: Allocator) !void {
fn coffLink(lld: *Lld, arena: Allocator) !void {
const comp = lld.base.comp;
const gpa = comp.gpa;
+ const io = comp.io;
const base = &lld.base;
const coff = &lld.ofmt.coff;
@@ -718,13 +719,13 @@ fn coffLink(lld: *Lld, arena: Allocator) !void {
argv.appendAssumeCapacity(try crt_file.full_object_path.toString(arena));
continue;
}
- if (try findLib(arena, lib_basename, coff.lib_directories)) |full_path| {
+ if (try findLib(arena, io, lib_basename, coff.lib_directories)) |full_path| {
argv.appendAssumeCapacity(full_path);
continue;
}
if (target.abi.isGnu()) {
const fallback_name = try allocPrint(arena, "lib{s}.dll.a", .{key});
- if (try findLib(arena, fallback_name, coff.lib_directories)) |full_path| {
+ if (try findLib(arena, io, fallback_name, coff.lib_directories)) |full_path| {
argv.appendAssumeCapacity(full_path);
continue;
}
@@ -741,9 +742,9 @@ fn coffLink(lld: *Lld, arena: Allocator) !void {
try spawnLld(comp, arena, argv.items);
}
}
-fn findLib(arena: Allocator, name: []const u8, lib_directories: []const Cache.Directory) !?[]const u8 {
+fn findLib(arena: Allocator, io: Io, name: []const u8, lib_directories: []const Cache.Directory) !?[]const u8 {
for (lib_directories) |lib_directory| {
- lib_directory.handle.access(name, .{}) catch |err| switch (err) {
+ lib_directory.handle.access(io, name, .{}) catch |err| switch (err) {
error.FileNotFound => continue,
else => |e| return e,
};
diff --git a/src/link/MachO.zig b/src/link/MachO.zig
index 78e035e2ad..6cd906340a 100644
--- a/src/link/MachO.zig
+++ b/src/link/MachO.zig
@@ -829,7 +829,8 @@ pub fn resolveLibSystem(
comp: *Compilation,
out_libs: anytype,
) !void {
- const diags = &self.base.comp.link_diags;
+ const io = comp.io;
+ const diags = &comp.link_diags;
var test_path = std.array_list.Managed(u8).init(arena);
var checked_paths = std.array_list.Managed([]const u8).init(arena);
@@ -838,16 +839,16 @@ pub fn resolveLibSystem(
if (self.sdk_layout) |sdk_layout| switch (sdk_layout) {
.sdk => {
const dir = try fs.path.join(arena, &.{ comp.sysroot.?, "usr", "lib" });
- if (try accessLibPath(arena, &test_path, &checked_paths, dir, "System")) break :success;
+ if (try accessLibPath(arena, io, &test_path, &checked_paths, dir, "System")) break :success;
},
.vendored => {
const dir = try comp.dirs.zig_lib.join(arena, &.{ "libc", "darwin" });
- if (try accessLibPath(arena, &test_path, &checked_paths, dir, "System")) break :success;
+ if (try accessLibPath(arena, io, &test_path, &checked_paths, dir, "System")) break :success;
},
};
for (self.lib_directories) |directory| {
- if (try accessLibPath(arena, &test_path, &checked_paths, directory.path orelse ".", "System")) break :success;
+ if (try accessLibPath(arena, io, &test_path, &checked_paths, directory.path orelse ".", "System")) break :success;
}
diags.addMissingLibraryError(checked_paths.items, "unable to find libSystem system library", .{});
@@ -1074,6 +1075,7 @@ fn isHoisted(self: *MachO, install_name: []const u8) bool {
/// TODO delete this, libraries must be instead resolved when instantiating the compilation pipeline
fn accessLibPath(
arena: Allocator,
+ io: Io,
test_path: *std.array_list.Managed(u8),
checked_paths: *std.array_list.Managed([]const u8),
search_dir: []const u8,
@@ -1085,7 +1087,7 @@ fn accessLibPath(
test_path.clearRetainingCapacity();
try test_path.print("{s}" ++ sep ++ "lib{s}{s}", .{ search_dir, name, ext });
try checked_paths.append(try arena.dupe(u8, test_path.items));
- Io.Dir.cwd().access(test_path.items, .{}) catch |err| switch (err) {
+ Io.Dir.cwd().access(io, test_path.items, .{}) catch |err| switch (err) {
error.FileNotFound => continue,
else => |e| return e,
};
@@ -1097,6 +1099,7 @@ fn accessLibPath(
fn accessFrameworkPath(
arena: Allocator,
+ io: Io,
test_path: *std.array_list.Managed(u8),
checked_paths: *std.array_list.Managed([]const u8),
search_dir: []const u8,
@@ -1113,7 +1116,7 @@ fn accessFrameworkPath(
ext,
});
try checked_paths.append(try arena.dupe(u8, test_path.items));
- Io.Dir.cwd().access(test_path.items, .{}) catch |err| switch (err) {
+ Io.Dir.cwd().access(io, test_path.items, .{}) catch |err| switch (err) {
error.FileNotFound => continue,
else => |e| return e,
};
@@ -1172,14 +1175,14 @@ fn parseDependentDylibs(self: *MachO) !void {
// Framework
for (framework_dirs) |dir| {
test_path.clearRetainingCapacity();
- if (try accessFrameworkPath(arena, &test_path, &checked_paths, dir, stem)) break :full_path test_path.items;
+ if (try accessFrameworkPath(arena, io, &test_path, &checked_paths, dir, stem)) break :full_path test_path.items;
}
// Library
const lib_name = eatPrefix(stem, "lib") orelse stem;
for (lib_directories) |lib_directory| {
test_path.clearRetainingCapacity();
- if (try accessLibPath(arena, &test_path, &checked_paths, lib_directory.path orelse ".", lib_name)) break :full_path test_path.items;
+ if (try accessLibPath(arena, io, &test_path, &checked_paths, lib_directory.path orelse ".", lib_name)) break :full_path test_path.items;
}
}
@@ -1194,7 +1197,7 @@ fn parseDependentDylibs(self: *MachO) !void {
try test_path.print("{s}{s}", .{ path, ext });
}
try checked_paths.append(try arena.dupe(u8, test_path.items));
- Io.Dir.cwd().access(test_path.items, .{}) catch |err| switch (err) {
+ Io.Dir.cwd().access(io, test_path.items, .{}) catch |err| switch (err) {
error.FileNotFound => continue,
else => |e| return e,
};
diff --git a/src/main.zig b/src/main.zig
index a063591b64..99850f5ffe 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -3208,6 +3208,7 @@ fn buildOutputType(
for (create_module.framework_dirs.items) |framework_dir_path| {
if (try accessFrameworkPath(
+ io,
&test_path,
&checked_paths,
framework_dir_path,
@@ -6626,7 +6627,7 @@ fn warnAboutForeignBinaries(
const host_query: std.Target.Query = .{};
const host_target = std.zig.resolveTargetQueryOrFatal(io, host_query);
- switch (std.zig.system.getExternalExecutor(&host_target, target, .{ .link_libc = link_libc })) {
+ switch (std.zig.system.getExternalExecutor(io, &host_target, target, .{ .link_libc = link_libc })) {
.native => return,
.rosetta => {
const host_name = try host_target.zigTriple(arena);
@@ -6832,6 +6833,7 @@ const ClangSearchSanitizer = struct {
};
fn accessFrameworkPath(
+ io: Io,
test_path: *std.array_list.Managed(u8),
checked_paths: *std.array_list.Managed(u8),
framework_dir_path: []const u8,
@@ -6845,7 +6847,7 @@ fn accessFrameworkPath(
framework_dir_path, framework_name, framework_name, ext,
});
try checked_paths.print("\n {s}", .{test_path.items});
- Io.Dir.cwd().access(test_path.items, .{}) catch |err| switch (err) {
+ Io.Dir.cwd().access(io, test_path.items, .{}) catch |err| switch (err) {
error.FileNotFound => continue,
else => |e| fatal("unable to search for {s} framework '{s}': {s}", .{
ext, test_path.items, @errorName(e),
@@ -7280,7 +7282,7 @@ fn findBuildRoot(arena: Allocator, io: Io, options: FindBuildRootOptions) !Build
var dirname: []const u8 = cwd_path;
while (true) {
const joined_path = try fs.path.join(arena, &[_][]const u8{ dirname, build_zig_basename });
- if (Io.Dir.cwd().access(joined_path, .{})) |_| {
+ if (Io.Dir.cwd().access(io, joined_path, .{})) |_| {
const dir = Io.Dir.cwd().openDir(io, dirname, .{}) catch |err| {
fatal("unable to open directory while searching for build.zig file, '{s}': {s}", .{ dirname, @errorName(err) });
};