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 {...@@ -49,12 +49,12 @@ pub fn main() !void {
49 };49 };
5050
51 const local_cache_directory: std.Build.Cache.Directory = .{51 const local_cache_directory: std.Build.Cache.Directory = .{
52 .path = try std.fs.path.relative(allocator, build_root, cache_root),52 .path = cache_root,
53 .handle = try std.fs.cwd().makeOpenPath(cache_root, .{}),53 .handle = try std.fs.cwd().makeOpenPath(cache_root, .{}),
54 };54 };
5555
56 const global_cache_directory: std.Build.Cache.Directory = .{56 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,
58 .handle = try std.fs.cwd().makeOpenPath(global_cache_root, .{}),58 .handle = try std.fs.cwd().makeOpenPath(global_cache_root, .{}),
59 };59 };
6060
lib/std/Build.zig-1
...@@ -1644,7 +1644,6 @@ pub const GeneratedFile = struct {...@@ -1644,7 +1644,6 @@ pub const GeneratedFile = struct {
1644};1644};
16451645
1646/// A file source is a reference to an existing or future file.1646/// A file source is a reference to an existing or future file.
1647///
1648pub const FileSource = union(enum) {1647pub const FileSource = union(enum) {
1649 /// A plain file path, relative to build root or absolute.1648 /// A plain file path, relative to build root or absolute.
1650 path: []const u8,1649 path: []const u8,
lib/std/Build/CompileStep.zig+3-3
...@@ -1350,10 +1350,10 @@ fn make(step: *Step) !void {...@@ -1350,10 +1350,10 @@ fn make(step: *Step) !void {
1350 }1350 }
13511351
1352 try zig_args.append("--cache-dir");1352 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
1355 try zig_args.append("--global-cache-dir");1355 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
1358 try zig_args.append("--name");1358 try zig_args.append("--name");
1359 try zig_args.append(self.name);1359 try zig_args.append(self.name);
...@@ -1786,7 +1786,7 @@ fn make(step: *Step) !void {...@@ -1786,7 +1786,7 @@ fn make(step: *Step) !void {
17861786
1787 const resolved_args_file = try mem.concat(builder.allocator, u8, &.{1787 const resolved_args_file = try mem.concat(builder.allocator, u8, &.{
1788 "@",1788 "@",
1789 builder.pathFromRoot(try builder.cache_root.join(builder.allocator, &.{args_file})),1789 try builder.cache_root.join(builder.allocator, &.{args_file}),
1790 });1790 });
17911791
1792 zig_args.shrinkRetainingCapacity(2);1792 zig_args.shrinkRetainingCapacity(2);