authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-24 17:49:24-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-29 23:50:20-07:00
logb68192254687e279bef4196cdf0575ed748964f7
tree0f390f7dde268e8ecfc58d6467f5a085b3d29b8d
parent519a47af31b0eaf41fc3649474e16f460b454795

Maker.Fetch: clarify that Cache import is not used


1 files changed, 24 insertions(+), 23 deletions(-)

lib/compiler/Maker/Fetch.zig+24-23
...@@ -44,7 +44,8 @@ const log = std.log.scoped(.fetch);...@@ -44,7 +44,8 @@ const log = std.log.scoped(.fetch);
44const assert = std.debug.assert;44const assert = std.debug.assert;
45const ascii = std.ascii;45const ascii = std.ascii;
46const Allocator = std.mem.Allocator;46const Allocator = std.mem.Allocator;
47const Cache = std.Build.Cache;47const Path = std.Build.Cache.Path;
48const Directory = std.Build.Cache.Directory;
48const git = @import("Fetch/git.zig");49const git = @import("Fetch/git.zig");
49const Package = @import("Package.zig");50const Package = @import("Package.zig");
50const Manifest = Package.Manifest;51const Manifest = Package.Manifest;
...@@ -58,8 +59,8 @@ name_tok: std.zig.Ast.TokenIndex,...@@ -58,8 +59,8 @@ name_tok: std.zig.Ast.TokenIndex,
58lazy_status: LazyStatus,59lazy_status: LazyStatus,
59/// Same as `parent_packge_root` except it is unchanged when recursing into60/// Same as `parent_packge_root` except it is unchanged when recursing into
60/// relative file paths (as opposed to URL).61/// relative file paths (as opposed to URL).
61remote_package_root: Cache.Path,62remote_package_root: Path,
62parent_package_root: Cache.Path,63parent_package_root: Path,
63parent_manifest_ast: ?*const std.zig.Ast,64parent_manifest_ast: ?*const std.zig.Ast,
64prog_node: std.Progress.Node,65prog_node: std.Progress.Node,
65job_queue: *JobQueue,66job_queue: *JobQueue,
...@@ -77,7 +78,7 @@ use_latest_commit: bool,...@@ -77,7 +78,7 @@ use_latest_commit: bool,
77// Below this are fields populated by `run`.78// Below this are fields populated by `run`.
7879
79/// Relative to the build root of the root package.80/// Relative to the build root of the root package.
80package_root: Cache.Path,81package_root: Path,
81error_bundle: ErrorBundle.Wip,82error_bundle: ErrorBundle.Wip,
82manifest: Manifest,83manifest: Manifest,
83manifest_ast: std.zig.Ast,84manifest_ast: std.zig.Ast,
...@@ -111,9 +112,9 @@ pub const LazyStatus = enum {...@@ -111,9 +112,9 @@ pub const LazyStatus = enum {
111};112};
112113
113pub const LocalStorage = struct {114pub const LocalStorage = struct {
114 cache_root: Cache.Path,115 cache_root: Path,
115 /// Path to "zig-pkg" inside the package in which the user ran `zig build`.116 /// Path to "zig-pkg" inside the package in which the user ran `zig build`.
116 pkg_root: Cache.Path,117 pkg_root: Path,
117};118};
118119
119/// Contains shared state among all `Fetch` tasks.120/// Contains shared state among all `Fetch` tasks.
...@@ -133,7 +134,7 @@ pub const JobQueue = struct {...@@ -133,7 +134,7 @@ pub const JobQueue = struct {
133 http_client: *std.http.Client,134 http_client: *std.http.Client,
134 /// This tracks `Fetch` tasks as well as recompression tasks.135 /// This tracks `Fetch` tasks as well as recompression tasks.
135 group: Io.Group = .init,136 group: Io.Group = .init,
136 global_cache: Cache.Directory,137 global_cache: Directory,
137 /// If `null`, indicates fetch globally only.138 /// If `null`, indicates fetch globally only.
138 local_storage: ?*const LocalStorage,139 local_storage: ?*const LocalStorage,
139 /// If true then, no fetching occurs, and:140 /// If true then, no fetching occurs, and:
...@@ -170,7 +171,7 @@ pub const JobQueue = struct {...@@ -170,7 +171,7 @@ pub const JobQueue = struct {
170 pub const ForkSet = std.array_hash_map.Custom(Fork, void, Fork.Context, false);171 pub const ForkSet = std.array_hash_map.Custom(Fork, void, Fork.Context, false);
171172
172 pub const Fork = struct {173 pub const Fork = struct {
173 path: Cache.Path,174 path: Path,
174 manifest_ast: std.zig.Ast,175 manifest_ast: std.zig.Ast,
175 manifest: Package.Manifest,176 manifest: Package.Manifest,
176 uses: usize,177 uses: usize,
...@@ -352,14 +353,14 @@ pub const JobQueue = struct {...@@ -352,14 +353,14 @@ pub const JobQueue = struct {
352 );353 );
353 }354 }
354355
355 fn recompress(jq: *JobQueue, package_hash: Package.Hash, package_root: Cache.Path) Io.Cancelable!void {356 fn recompress(jq: *JobQueue, package_hash: Package.Hash, package_root: Path) Io.Cancelable!void {
356 const pkg_hash_slice = package_hash.toSlice();357 const pkg_hash_slice = package_hash.toSlice();
357358
358 const prog_node = jq.prog_node.startFmt(0, "recompress {s}", .{pkg_hash_slice});359 const prog_node = jq.prog_node.startFmt(0, "recompress {s}", .{pkg_hash_slice});
359 defer prog_node.end();360 defer prog_node.end();
360361
361 var dest_sub_path_buf: ["p/".len + Package.Hash.max_len + ".tar.gz".len]u8 = undefined;362 var dest_sub_path_buf: ["p/".len + Package.Hash.max_len + ".tar.gz".len]u8 = undefined;
362 const dest_path: Cache.Path = .{363 const dest_path: Path = .{
363 .root_dir = jq.global_cache,364 .root_dir = jq.global_cache,
364 .sub_path = std.fmt.bufPrint(&dest_sub_path_buf, "p/{s}.tar.gz", .{pkg_hash_slice}) catch unreachable,365 .sub_path = std.fmt.bufPrint(&dest_sub_path_buf, "p/{s}.tar.gz", .{pkg_hash_slice}) catch unreachable,
365 };366 };
...@@ -381,9 +382,9 @@ pub const JobQueue = struct {...@@ -381,9 +382,9 @@ pub const JobQueue = struct {
381 fn recompressFallible(382 fn recompressFallible(
382 jq: *JobQueue,383 jq: *JobQueue,
383 arena: Allocator,384 arena: Allocator,
384 dest_path: Cache.Path,385 dest_path: Path,
385 pkg_hash_slice: []const u8,386 pkg_hash_slice: []const u8,
386 package_root: Cache.Path,387 package_root: Path,
387 prog_node: std.Progress.Node,388 prog_node: std.Progress.Node,
388 ) !void {389 ) !void {
389 const gpa = jq.http_client.allocator;390 const gpa = jq.http_client.allocator;
...@@ -493,7 +494,7 @@ fn stringCmp(_: void, lhs: ScannedFile, rhs: ScannedFile) bool {...@@ -493,7 +494,7 @@ fn stringCmp(_: void, lhs: ScannedFile, rhs: ScannedFile) bool {
493pub const Location = union(enum) {494pub const Location = union(enum) {
494 remote: Remote,495 remote: Remote,
495 /// A directory found inside the parent package.496 /// A directory found inside the parent package.
496 relative_path: Cache.Path,497 relative_path: Path,
497 /// Recursive Fetch tasks will never use this Location, but it may be498 /// Recursive Fetch tasks will never use this Location, but it may be
498 /// passed in by the CLI. Indicates the file contents here should be copied499 /// passed in by the CLI. Indicates the file contents here should be copied
499 /// into the global package cache. It may be a file relative to the cwd or500 /// into the global package cache. It may be a file relative to the cwd or
...@@ -641,7 +642,7 @@ pub fn run(f: *Fetch) RunError!void {...@@ -641,7 +642,7 @@ pub fn run(f: *Fetch) RunError!void {
641642
642 // Check global cache before remote fetch.643 // Check global cache before remote fetch.
643 const cached_tarball_sub_path = try std.fmt.allocPrint(arena, "p/{s}.tar.gz", .{expected_hash.toSlice()});644 const cached_tarball_sub_path = try std.fmt.allocPrint(arena, "p/{s}.tar.gz", .{expected_hash.toSlice()});
644 const cached_tarball_path: Cache.Path = .{645 const cached_tarball_path: Path = .{
645 .root_dir = job_queue.global_cache,646 .root_dir = job_queue.global_cache,
646 .sub_path = cached_tarball_sub_path,647 .sub_path = cached_tarball_sub_path,
647 };648 };
...@@ -716,7 +717,7 @@ fn runResource(...@@ -716,7 +717,7 @@ fn runResource(
716 };717 };
717 const tmp_dir_sub_path = ".tmp-" ++ std.fmt.hex(rand_int);718 const tmp_dir_sub_path = ".tmp-" ++ std.fmt.hex(rand_int);
718 const tmp_tmp_dir_sub_path = "tmp/" ++ tmp_dir_sub_path;719 const tmp_tmp_dir_sub_path = "tmp/" ++ tmp_dir_sub_path;
719 const tmp_directory_path: Cache.Path = if (job_queue.local_storage) |ls|720 const tmp_directory_path: Path = if (job_queue.local_storage) |ls|
720 try ls.pkg_root.join(arena, tmp_dir_sub_path)721 try ls.pkg_root.join(arena, tmp_dir_sub_path)
721 else722 else
722 .{723 .{
...@@ -725,7 +726,7 @@ fn runResource(...@@ -725,7 +726,7 @@ fn runResource(
725 };726 };
726727
727 const package_sub_path = blk: {728 const package_sub_path = blk: {
728 var tmp_directory: Cache.Directory = .{729 var tmp_directory: Directory = .{
729 .path = tmp_directory_path.sub_path,730 .path = tmp_directory_path.sub_path,
730 .handle = handle: {731 .handle = handle: {
731 const dir = tmp_directory_path.root_dir.handle.createDirPathOpen(io, tmp_directory_path.sub_path, .{732 const dir = tmp_directory_path.root_dir.handle.createDirPathOpen(io, tmp_directory_path.sub_path, .{
...@@ -746,7 +747,7 @@ fn runResource(...@@ -746,7 +747,7 @@ fn runResource(
746 // Fetch and unpack a resource into a temporary directory.747 // Fetch and unpack a resource into a temporary directory.
747 var unpack_result = try unpackResource(f, resource, uri_path, tmp_directory);748 var unpack_result = try unpackResource(f, resource, uri_path, tmp_directory);
748749
749 const pkg_path: Cache.Path = .{ .root_dir = tmp_directory, .sub_path = unpack_result.root_dir };750 const pkg_path: Path = .{ .root_dir = tmp_directory, .sub_path = unpack_result.root_dir };
750751
751 // Load, parse, and validate the unpacked build.zig.zon file. It is allowed752 // Load, parse, and validate the unpacked build.zig.zon file. It is allowed
752 // for the file to be missing, in which case this fetched package is753 // for the file to be missing, in which case this fetched package is
...@@ -874,7 +875,7 @@ fn checkBuildFileExistence(f: *Fetch) RunError!void {...@@ -874,7 +875,7 @@ fn checkBuildFileExistence(f: *Fetch) RunError!void {
874}875}
875876
876/// This function populates `f.manifest` or leaves it `null`.877/// This function populates `f.manifest` or leaves it `null`.
877fn loadManifest(f: *Fetch, pkg_root: Cache.Path) RunError!void {878fn loadManifest(f: *Fetch, pkg_root: Path) RunError!void {
878 const io = f.job_queue.io;879 const io = f.job_queue.io;
879 const eb = &f.error_bundle;880 const eb = &f.error_bundle;
880 const arena = f.arena.allocator();881 const arena = f.arena.allocator();
...@@ -1038,7 +1039,7 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {...@@ -1038,7 +1039,7 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
1038 }1039 }
1039}1040}
10401041
1041pub fn relativePathDigest(pkg_root: Cache.Path, cache_root: Cache.Directory) Package.Hash {1042pub fn relativePathDigest(pkg_root: Path, cache_root: Directory) Package.Hash {
1042 return .initPath(pkg_root.sub_path, pkg_root.root_dir.eql(cache_root));1043 return .initPath(pkg_root.sub_path, pkg_root.root_dir.eql(cache_root));
1043}1044}
10441045
...@@ -1331,7 +1332,7 @@ fn unpackResource(...@@ -1331,7 +1332,7 @@ fn unpackResource(
1331 f: *Fetch,1332 f: *Fetch,
1332 resource: *Resource,1333 resource: *Resource,
1333 uri_path: []const u8,1334 uri_path: []const u8,
1334 tmp_directory: Cache.Directory,1335 tmp_directory: Directory,
1335) RunError!UnpackResult {1336) RunError!UnpackResult {
1336 const eb = &f.error_bundle;1337 const eb = &f.error_bundle;
1337 const file_type = switch (resource.*) {1338 const file_type = switch (resource.*) {
...@@ -1667,7 +1668,7 @@ fn recursiveDirectoryCopy(f: *Fetch, dir: Io.Dir, tmp_dir: Io.Dir) anyerror!void...@@ -1667,7 +1668,7 @@ fn recursiveDirectoryCopy(f: *Fetch, dir: Io.Dir, tmp_dir: Io.Dir) anyerror!void
1667 }1668 }
1668}1669}
16691670
1670pub fn renameTmpIntoCache(io: Io, tmp_path: Cache.Path, dest_path: Cache.Path) !void {1671pub fn renameTmpIntoCache(io: Io, tmp_path: Path, dest_path: Path) !void {
1671 var handled_missing_dir = false;1672 var handled_missing_dir = false;
1672 while (true) {1673 while (true) {
1673 Io.Dir.rename(1674 Io.Dir.rename(
...@@ -1711,7 +1712,7 @@ const ComputedHash = struct {...@@ -1711,7 +1712,7 @@ const ComputedHash = struct {
1711/// the hash are not present on the file system. Empty directories are *not1712/// the hash are not present on the file system. Empty directories are *not
1712/// hashed* and must not be present on the file system when calling this1713/// hashed* and must not be present on the file system when calling this
1713/// function.1714/// function.
1714fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!ComputedHash {1715fn computeHash(f: *Fetch, pkg_path: Path, filter: Filter) RunError!ComputedHash {
1715 const io = f.job_queue.io;1716 const io = f.job_queue.io;
1716 // All the path name strings need to be in memory for sorting.1717 // All the path name strings need to be in memory for sorting.
1717 const arena = f.arena.allocator();1718 const arena = f.arena.allocator();
...@@ -2035,7 +2036,7 @@ const Filter = struct {...@@ -2035,7 +2036,7 @@ const Filter = struct {
2035 }2036 }
2036};2037};
20372038
2038pub fn depDigest(pkg_root: Cache.Path, cache_root: Cache.Directory, dep: Manifest.Dependency) ?Package.Hash {2039pub fn depDigest(pkg_root: Path, cache_root: Directory, dep: Manifest.Dependency) ?Package.Hash {
2039 if (dep.hash) |h| return .fromSlice(h);2040 if (dep.hash) |h| return .fromSlice(h);
20402041
2041 switch (dep.location) {2042 switch (dep.location) {