authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-02-12 08:17:49-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-02-13 06:42:26-07:00
log3f8f63b132566683ffc1d3ec51e7f49346d88f2e
tree0165781535b45ef67714d583107b1e124c055b3c
parentd97042ad2e41b173334ec542eb4b07e81864d10e

std.Build: make cache_root and global_cache_root relative to cwd

This makes it so that when there is a tree of std.Build objects, only one zig-cache is used (the top-level application) instead of polluting package directories with zig-cache folders.

3 files changed, 5 insertions(+), 6 deletions(-)

lib/build_runner.zig+2-2
......@@ -49,12 +49,12 @@ pub fn main() !void {
4949 };
5050
5151 const local_cache_directory: std.Build.Cache.Directory = .{
52 .path = try std.fs.path.relative(allocator, build_root, cache_root),
52 .path = cache_root,
5353 .handle = try std.fs.cwd().makeOpenPath(cache_root, .{}),
5454 };
5555
5656 const global_cache_directory: std.Build.Cache.Directory = .{
57 .path = try std.fs.path.relative(allocator, build_root, global_cache_root),
57 .path = global_cache_root,
5858 .handle = try std.fs.cwd().makeOpenPath(global_cache_root, .{}),
5959 };
6060
lib/std/Build.zig-1
......@@ -1644,7 +1644,6 @@ pub const GeneratedFile = struct {
16441644};
16451645
16461646/// A file source is a reference to an existing or future file.
1647///
16481647pub const FileSource = union(enum) {
16491648 /// A plain file path, relative to build root or absolute.
16501649 path: []const u8,
lib/std/Build/CompileStep.zig+3-3
......@@ -1350,10 +1350,10 @@ fn make(step: *Step) !void {
13501350 }
13511351
13521352 try zig_args.append("--cache-dir");
1353 try zig_args.append(builder.pathFromRoot(builder.cache_root.path orelse "."));
1353 try zig_args.append(builder.cache_root.path orelse ".");
13541354
13551355 try zig_args.append("--global-cache-dir");
1356 try zig_args.append(builder.pathFromRoot(builder.global_cache_root.path orelse "."));
1356 try zig_args.append(builder.global_cache_root.path orelse ".");
13571357
13581358 try zig_args.append("--name");
13591359 try zig_args.append(self.name);
......@@ -1786,7 +1786,7 @@ fn make(step: *Step) !void {
17861786
17871787 const resolved_args_file = try mem.concat(builder.allocator, u8, &.{
17881788 "@",
1789 builder.pathFromRoot(try builder.cache_root.join(builder.allocator, &.{args_file})),
1789 try builder.cache_root.join(builder.allocator, &.{args_file}),
17901790 });
17911791
17921792 zig_args.shrinkRetainingCapacity(2);