authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-10 08:33:18-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-11 08:41:24-07:00
logc96cb98ad13d0ebb4593cd0a29159b64b6c7621b
treef1ab644d45eb7d2c411082017ec33a830d2fac0b
parent1728d92f60d4e9aa10d878e3235fc63764d3909b

CLI: remove --enable-cache option

This use case is now handled instead by the --listen option. closes #15025 closes #15072

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

lib/std/Build/CompileStep.zig-1
......@@ -1864,7 +1864,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
18641864 });
18651865 }
18661866
1867 try zig_args.append("--enable-cache");
18681867 try zig_args.append("--listen=-");
18691868
18701869 // Windows has an argument length limit of 32,766 characters, macOS 262,144 and Linux
lib/std/Build/TranslateCStep.zig-1
......@@ -100,7 +100,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
100100 try argv_list.append("translate-c");
101101 try argv_list.append("-lc");
102102
103 try argv_list.append("--enable-cache");
104103 try argv_list.append("--listen=-");
105104
106105 if (!self.target.isNative()) {
src/main.zig+6-71
......@@ -386,7 +386,6 @@ const usage_build_generic =
386386 \\ --cache-dir [path] Override the local cache directory
387387 \\ --global-cache-dir [path] Override the global cache directory
388388 \\ --zig-lib-dir [path] Override path to Zig installation lib directory
389 \\ --enable-cache Output to cache directory; print path to stdout
390389 \\
391390 \\Compile Options:
392391 \\ -target [name] <arch><sub>-<os>-<abi> see the targets command
......@@ -756,7 +755,6 @@ fn buildOutputType(
756755 var link_libcpp = false;
757756 var link_libunwind = false;
758757 var want_native_include_dirs = false;
759 var enable_cache: ?bool = null;
760758 var want_pic: ?bool = null;
761759 var want_pie: ?bool = null;
762760 var want_lto: ?bool = null;
......@@ -1203,8 +1201,6 @@ fn buildOutputType(
12031201 build_id = true;
12041202 } else if (mem.eql(u8, arg, "-fno-build-id")) {
12051203 build_id = false;
1206 } else if (mem.eql(u8, arg, "--enable-cache")) {
1207 enable_cache = true;
12081204 } else if (mem.eql(u8, arg, "--test-cmd-bin")) {
12091205 try test_exec_args.append(null);
12101206 } else if (mem.eql(u8, arg, "--test-evented-io")) {
......@@ -2641,7 +2637,7 @@ fn buildOutputType(
26412637 var cleanup_emit_bin_dir: ?fs.Dir = null;
26422638 defer if (cleanup_emit_bin_dir) |*dir| dir.close();
26432639
2644 const have_enable_cache = enable_cache orelse false;
2640 const output_to_cache = listen != .none;
26452641 const optional_version = if (have_version) version else null;
26462642
26472643 const resolved_soname: ?[]const u8 = switch (soname) {
......@@ -2668,7 +2664,7 @@ fn buildOutputType(
26682664 switch (arg_mode) {
26692665 .run, .zig_test => break :blk null,
26702666 else => {
2671 if (have_enable_cache) {
2667 if (output_to_cache) {
26722668 break :blk null;
26732669 } else {
26742670 break :blk .{ .path = null, .handle = fs.cwd() };
......@@ -2686,12 +2682,6 @@ fn buildOutputType(
26862682 },
26872683 .yes => |full_path| b: {
26882684 const basename = fs.path.basename(full_path);
2689 if (have_enable_cache) {
2690 break :b Compilation.EmitLoc{
2691 .basename = basename,
2692 .directory = null,
2693 };
2694 }
26952685 if (fs.path.dirname(full_path)) |dirname| {
26962686 const handle = fs.cwd().openDir(dirname, .{}) catch |err| {
26972687 fatal("unable to open output directory '{s}': {s}", .{ dirname, @errorName(err) });
......@@ -3145,7 +3135,7 @@ fn buildOutputType(
31453135 .test_filter = test_filter,
31463136 .test_name_prefix = test_name_prefix,
31473137 .test_runner_path = test_runner_path,
3148 .disable_lld_caching = !have_enable_cache,
3138 .disable_lld_caching = !output_to_cache,
31493139 .subsystem = subsystem,
31503140 .wasi_exec_model = wasi_exec_model,
31513141 .debug_compile_errors = debug_compile_errors,
......@@ -3240,19 +3230,7 @@ fn buildOutputType(
32403230 return cmdTranslateC(comp, arena, null);
32413231 }
32423232
3243 const hook: AfterUpdateHook = blk: {
3244 if (!have_enable_cache)
3245 break :blk .none;
3246
3247 switch (emit_bin) {
3248 .no => break :blk .none,
3249 .yes_default_path => break :blk .print_emit_bin_dir_path,
3250 .yes => |full_path| break :blk .{ .update = full_path },
3251 .yes_a_out => break :blk .{ .update = a_out_basename },
3252 }
3253 };
3254
3255 updateModule(gpa, comp, hook) catch |err| switch (err) {
3233 updateModule(comp) catch |err| switch (err) {
32563234 error.SemanticAnalyzeFail => if (listen == .none) process.exit(1),
32573235 else => |e| return e,
32583236 };
......@@ -3800,13 +3778,7 @@ fn runOrTestHotSwap(
38003778 }
38013779}
38023780
3803const AfterUpdateHook = union(enum) {
3804 none,
3805 print_emit_bin_dir_path,
3806 update: []const u8,
3807};
3808
3809fn updateModule(gpa: Allocator, comp: *Compilation, hook: AfterUpdateHook) !void {
3781fn updateModule(comp: *Compilation) !void {
38103782 {
38113783 // If the terminal is dumb, we dont want to show the user all the output.
38123784 var progress: std.Progress = .{ .dont_print_on_dumb = true };
......@@ -3832,43 +3804,6 @@ fn updateModule(gpa: Allocator, comp: *Compilation, hook: AfterUpdateHook) !void
38323804 if (errors.errorMessageCount() > 0) {
38333805 errors.renderToStdErr(renderOptions(comp.color));
38343806 return error.SemanticAnalyzeFail;
3835 } else switch (hook) {
3836 .none => {},
3837 .print_emit_bin_dir_path => {
3838 const emit = comp.bin_file.options.emit.?;
3839 const full_path = try emit.directory.join(gpa, &.{emit.sub_path});
3840 defer gpa.free(full_path);
3841 const dir_path = fs.path.dirname(full_path).?;
3842 try io.getStdOut().writer().print("{s}\n", .{dir_path});
3843 },
3844 .update => |full_path| {
3845 const bin_sub_path = comp.bin_file.options.emit.?.sub_path;
3846 const cwd = fs.cwd();
3847 const cache_dir = comp.bin_file.options.emit.?.directory.handle;
3848 _ = try cache_dir.updateFile(bin_sub_path, cwd, full_path, .{});
3849
3850 // If a .pdb file is part of the expected output, we must also copy
3851 // it into place here.
3852 const is_coff = comp.bin_file.options.target.ofmt == .coff;
3853 const have_pdb = is_coff and !comp.bin_file.options.strip;
3854 if (have_pdb) {
3855 // Replace `.out` or `.exe` with `.pdb` on both the source and destination
3856 const src_bin_ext = fs.path.extension(bin_sub_path);
3857 const dst_bin_ext = fs.path.extension(full_path);
3858
3859 const src_pdb_path = try std.fmt.allocPrint(gpa, "{s}.pdb", .{
3860 bin_sub_path[0 .. bin_sub_path.len - src_bin_ext.len],
3861 });
3862 defer gpa.free(src_pdb_path);
3863
3864 const dst_pdb_path = try std.fmt.allocPrint(gpa, "{s}.pdb", .{
3865 full_path[0 .. full_path.len - dst_bin_ext.len],
3866 });
3867 defer gpa.free(dst_pdb_path);
3868
3869 _ = try cache_dir.updateFile(src_pdb_path, cwd, dst_pdb_path, .{});
3870 }
3871 },
38723807 }
38733808}
38743809
......@@ -4499,7 +4434,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
44994434 };
45004435 defer comp.destroy();
45014436
4502 updateModule(gpa, comp, .none) catch |err| switch (err) {
4437 updateModule(comp) catch |err| switch (err) {
45034438 error.SemanticAnalyzeFail => process.exit(2),
45044439 else => |e| return e,
45054440 };