commit 3f8f63b132566683ffc1d3ec51e7f49346d88f2e (tree)
parent d97042ad2e41b173334ec542eb4b07e81864d10e
Author: Andrew Kelley <andrew@ziglang.org>
Date: Sun, 12 Feb 2023 08:17:49 -0700
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.
Diffstat:
3 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/lib/build_runner.zig b/lib/build_runner.zig
@@ -49,12 +49,12 @@ pub fn main() !void {
};
const local_cache_directory: std.Build.Cache.Directory = .{
- .path = try std.fs.path.relative(allocator, build_root, cache_root),
+ .path = cache_root,
.handle = try std.fs.cwd().makeOpenPath(cache_root, .{}),
};
const global_cache_directory: std.Build.Cache.Directory = .{
- .path = try std.fs.path.relative(allocator, build_root, global_cache_root),
+ .path = global_cache_root,
.handle = try std.fs.cwd().makeOpenPath(global_cache_root, .{}),
};
diff --git a/lib/std/Build.zig b/lib/std/Build.zig
@@ -1644,7 +1644,6 @@ pub const GeneratedFile = struct {
};
/// A file source is a reference to an existing or future file.
-///
pub const FileSource = union(enum) {
/// A plain file path, relative to build root or absolute.
path: []const u8,
diff --git a/lib/std/Build/CompileStep.zig b/lib/std/Build/CompileStep.zig
@@ -1350,10 +1350,10 @@ fn make(step: *Step) !void {
}
try zig_args.append("--cache-dir");
- try zig_args.append(builder.pathFromRoot(builder.cache_root.path orelse "."));
+ try zig_args.append(builder.cache_root.path orelse ".");
try zig_args.append("--global-cache-dir");
- try zig_args.append(builder.pathFromRoot(builder.global_cache_root.path orelse "."));
+ try zig_args.append(builder.global_cache_root.path orelse ".");
try zig_args.append("--name");
try zig_args.append(self.name);
@@ -1786,7 +1786,7 @@ fn make(step: *Step) !void {
const resolved_args_file = try mem.concat(builder.allocator, u8, &.{
"@",
- builder.pathFromRoot(try builder.cache_root.join(builder.allocator, &.{args_file})),
+ try builder.cache_root.join(builder.allocator, &.{args_file}),
});
zig_args.shrinkRetainingCapacity(2);