From 26399b5249cbc8774e50856fed6d2336e396cb69 Mon Sep 17 00:00:00 2001 From: antlilja Date: Tue, 1 Dec 2020 16:47:47 +0100 Subject: Added global-cache argument to build system + removed extra args. * Field global_cache_root was added to Builder struct along with mandatory argument for build_runner.zig. Logic for using the custom global cache was also added. * The arguments --cache-dir and --global-cache-dir are no longer passed directly through to build_runner.zig and are instead only passed through the mandatory cache_root and global_cache_root arguments. --- lib/std/build.zig | 17 ++++++++++++++++- lib/std/special/build_runner.zig | 12 +++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/std/build.zig b/lib/std/build.zig index a76e2b6327..dacfaf5f75 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -61,6 +61,7 @@ pub const Builder = struct { installed_files: ArrayList(InstalledFile), build_root: []const u8, cache_root: []const u8, + global_cache_root: []const u8, release_mode: ?builtin.Mode, is_release: bool, override_lib_dir: ?[]const u8, @@ -126,6 +127,7 @@ pub const Builder = struct { zig_exe: []const u8, build_root: []const u8, cache_root: []const u8, + global_cache_root: []const u8, ) !*Builder { const env_map = try allocator.create(BufMap); env_map.* = try process.getEnvMap(allocator); @@ -135,6 +137,7 @@ pub const Builder = struct { .zig_exe = zig_exe, .build_root = build_root, .cache_root = try fs.path.relative(allocator, build_root, cache_root), + .global_cache_root = global_cache_root, .verbose = false, .verbose_tokenize = false, .verbose_ast = false, @@ -1128,7 +1131,13 @@ test "builder.findProgram compiles" { var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); defer arena.deinit(); - const builder = try Builder.create(&arena.allocator, "zig", "zig-cache", "zig-cache"); + const builder = try Builder.create( + &arena.allocator, + "zig", + "zig-cache", + "zig-cache", + "zig-cache", + ); defer builder.destroy(); _ = builder.findProgram(&[_][]const u8{}, &[_][]const u8{}) catch null; } @@ -2196,6 +2205,9 @@ pub const LibExeObjStep = struct { try zig_args.append("--cache-dir"); try zig_args.append(builder.pathFromRoot(builder.cache_root)); + try zig_args.append("--global-cache-dir"); + try zig_args.append(builder.pathFromRoot(builder.global_cache_root)); + zig_args.append("--name") catch unreachable; zig_args.append(self.name) catch unreachable; @@ -2826,6 +2838,7 @@ test "Builder.dupePkg()" { "test", "test", "test", + "test", ); defer builder.destroy(); @@ -2869,6 +2882,7 @@ test "LibExeObjStep.addBuildOption" { "test", "test", "test", + "test", ); defer builder.destroy(); @@ -2906,6 +2920,7 @@ test "LibExeObjStep.addPackage" { "test", "test", "test", + "test", ); defer builder.destroy(); diff --git a/lib/std/special/build_runner.zig b/lib/std/special/build_runner.zig index b6e8f27b12..7d9ac17499 100644 --- a/lib/std/special/build_runner.zig +++ b/lib/std/special/build_runner.zig @@ -41,8 +41,18 @@ pub fn main() !void { warn("Expected third argument to be cache root directory path\n", .{}); return error.InvalidArgs; }; + const global_cache_root = nextArg(args, &arg_idx) orelse { + warn("Expected third argument to be global cache root directory path\n", .{}); + return error.InvalidArgs; + }; - const builder = try Builder.create(allocator, zig_exe, build_root, cache_root); + const builder = try Builder.create( + allocator, + zig_exe, + build_root, + cache_root, + global_cache_root, + ); defer builder.destroy(); var targets = ArrayList([]const u8).init(allocator); -- cgit v1.2.3