| ... | @@ -386,7 +386,6 @@ const usage_build_generic = | ... | @@ -386,7 +386,6 @@ const usage_build_generic = |
| 386 | \\ --cache-dir [path] Override the local cache directory | 386 | \\ --cache-dir [path] Override the local cache directory |
| 387 | \\ --global-cache-dir [path] Override the global cache directory | 387 | \\ --global-cache-dir [path] Override the global cache directory |
| 388 | \\ --zig-lib-dir [path] Override path to Zig installation lib directory | 388 | \\ --zig-lib-dir [path] Override path to Zig installation lib directory |
| 389 | \\ --enable-cache Output to cache directory; print path to stdout | | |
| 390 | \\ | 389 | \\ |
| 391 | \\Compile Options: | 390 | \\Compile Options: |
| 392 | \\ -target [name] <arch><sub>-<os>-<abi> see the targets command | 391 | \\ -target [name] <arch><sub>-<os>-<abi> see the targets command |
| ... | @@ -756,7 +755,6 @@ fn buildOutputType( | ... | @@ -756,7 +755,6 @@ fn buildOutputType( |
| 756 | var link_libcpp = false; | 755 | var link_libcpp = false; |
| 757 | var link_libunwind = false; | 756 | var link_libunwind = false; |
| 758 | var want_native_include_dirs = false; | 757 | var want_native_include_dirs = false; |
| 759 | var enable_cache: ?bool = null; | | |
| 760 | var want_pic: ?bool = null; | 758 | var want_pic: ?bool = null; |
| 761 | var want_pie: ?bool = null; | 759 | var want_pie: ?bool = null; |
| 762 | var want_lto: ?bool = null; | 760 | var want_lto: ?bool = null; |
| ... | @@ -1203,8 +1201,6 @@ fn buildOutputType( | ... | @@ -1203,8 +1201,6 @@ fn buildOutputType( |
| 1203 | build_id = true; | 1201 | build_id = true; |
| 1204 | } else if (mem.eql(u8, arg, "-fno-build-id")) { | 1202 | } else if (mem.eql(u8, arg, "-fno-build-id")) { |
| 1205 | build_id = false; | 1203 | build_id = false; |
| 1206 | } else if (mem.eql(u8, arg, "--enable-cache")) { | | |
| 1207 | enable_cache = true; | | |
| 1208 | } else if (mem.eql(u8, arg, "--test-cmd-bin")) { | 1204 | } else if (mem.eql(u8, arg, "--test-cmd-bin")) { |
| 1209 | try test_exec_args.append(null); | 1205 | try test_exec_args.append(null); |
| 1210 | } else if (mem.eql(u8, arg, "--test-evented-io")) { | 1206 | } else if (mem.eql(u8, arg, "--test-evented-io")) { |
| ... | @@ -2641,7 +2637,7 @@ fn buildOutputType( | ... | @@ -2641,7 +2637,7 @@ fn buildOutputType( |
| 2641 | var cleanup_emit_bin_dir: ?fs.Dir = null; | 2637 | var cleanup_emit_bin_dir: ?fs.Dir = null; |
| 2642 | defer if (cleanup_emit_bin_dir) |*dir| dir.close(); | 2638 | defer if (cleanup_emit_bin_dir) |*dir| dir.close(); |
| 2643 | | 2639 | |
| 2644 | const have_enable_cache = enable_cache orelse false; | 2640 | const output_to_cache = listen != .none; |
| 2645 | const optional_version = if (have_version) version else null; | 2641 | const optional_version = if (have_version) version else null; |
| 2646 | | 2642 | |
| 2647 | const resolved_soname: ?[]const u8 = switch (soname) { | 2643 | const resolved_soname: ?[]const u8 = switch (soname) { |
| ... | @@ -2668,7 +2664,7 @@ fn buildOutputType( | ... | @@ -2668,7 +2664,7 @@ fn buildOutputType( |
| 2668 | switch (arg_mode) { | 2664 | switch (arg_mode) { |
| 2669 | .run, .zig_test => break :blk null, | 2665 | .run, .zig_test => break :blk null, |
| 2670 | else => { | 2666 | else => { |
| 2671 | if (have_enable_cache) { | 2667 | if (output_to_cache) { |
| 2672 | break :blk null; | 2668 | break :blk null; |
| 2673 | } else { | 2669 | } else { |
| 2674 | break :blk .{ .path = null, .handle = fs.cwd() }; | 2670 | break :blk .{ .path = null, .handle = fs.cwd() }; |
| ... | @@ -2686,12 +2682,6 @@ fn buildOutputType( | ... | @@ -2686,12 +2682,6 @@ fn buildOutputType( |
| 2686 | }, | 2682 | }, |
| 2687 | .yes => |full_path| b: { | 2683 | .yes => |full_path| b: { |
| 2688 | const basename = fs.path.basename(full_path); | 2684 | 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 | } | | |
| 2695 | if (fs.path.dirname(full_path)) |dirname| { | 2685 | if (fs.path.dirname(full_path)) |dirname| { |
| 2696 | const handle = fs.cwd().openDir(dirname, .{}) catch |err| { | 2686 | const handle = fs.cwd().openDir(dirname, .{}) catch |err| { |
| 2697 | fatal("unable to open output directory '{s}': {s}", .{ dirname, @errorName(err) }); | 2687 | fatal("unable to open output directory '{s}': {s}", .{ dirname, @errorName(err) }); |
| ... | @@ -3145,7 +3135,7 @@ fn buildOutputType( | ... | @@ -3145,7 +3135,7 @@ fn buildOutputType( |
| 3145 | .test_filter = test_filter, | 3135 | .test_filter = test_filter, |
| 3146 | .test_name_prefix = test_name_prefix, | 3136 | .test_name_prefix = test_name_prefix, |
| 3147 | .test_runner_path = test_runner_path, | 3137 | .test_runner_path = test_runner_path, |
| 3148 | .disable_lld_caching = !have_enable_cache, | 3138 | .disable_lld_caching = !output_to_cache, |
| 3149 | .subsystem = subsystem, | 3139 | .subsystem = subsystem, |
| 3150 | .wasi_exec_model = wasi_exec_model, | 3140 | .wasi_exec_model = wasi_exec_model, |
| 3151 | .debug_compile_errors = debug_compile_errors, | 3141 | .debug_compile_errors = debug_compile_errors, |
| ... | @@ -3240,19 +3230,7 @@ fn buildOutputType( | ... | @@ -3240,19 +3230,7 @@ fn buildOutputType( |
| 3240 | return cmdTranslateC(comp, arena, null); | 3230 | return cmdTranslateC(comp, arena, null); |
| 3241 | } | 3231 | } |
| 3242 | | 3232 | |
| 3243 | const hook: AfterUpdateHook = blk: { | 3233 | updateModule(comp) catch |err| switch (err) { |
| 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) { | | |
| 3256 | error.SemanticAnalyzeFail => if (listen == .none) process.exit(1), | 3234 | error.SemanticAnalyzeFail => if (listen == .none) process.exit(1), |
| 3257 | else => |e| return e, | 3235 | else => |e| return e, |
| 3258 | }; | 3236 | }; |
| ... | @@ -3800,13 +3778,7 @@ fn runOrTestHotSwap( | ... | @@ -3800,13 +3778,7 @@ fn runOrTestHotSwap( |
| 3800 | } | 3778 | } |
| 3801 | } | 3779 | } |
| 3802 | | 3780 | |
| 3803 | const AfterUpdateHook = union(enum) { | 3781 | fn updateModule(comp: *Compilation) !void { |
| 3804 | none, | | |
| 3805 | print_emit_bin_dir_path, | | |
| 3806 | update: []const u8, | | |
| 3807 | }; | | |
| 3808 | | | |
| 3809 | fn updateModule(gpa: Allocator, comp: *Compilation, hook: AfterUpdateHook) !void { | | |
| 3810 | { | 3782 | { |
| 3811 | // If the terminal is dumb, we dont want to show the user all the output. | 3783 | // If the terminal is dumb, we dont want to show the user all the output. |
| 3812 | var progress: std.Progress = .{ .dont_print_on_dumb = true }; | 3784 | var progress: std.Progress = .{ .dont_print_on_dumb = true }; |
| ... | @@ -3832,43 +3804,6 @@ fn updateModule(gpa: Allocator, comp: *Compilation, hook: AfterUpdateHook) !void | ... | @@ -3832,43 +3804,6 @@ fn updateModule(gpa: Allocator, comp: *Compilation, hook: AfterUpdateHook) !void |
| 3832 | if (errors.errorMessageCount() > 0) { | 3804 | if (errors.errorMessageCount() > 0) { |
| 3833 | errors.renderToStdErr(renderOptions(comp.color)); | 3805 | errors.renderToStdErr(renderOptions(comp.color)); |
| 3834 | return error.SemanticAnalyzeFail; | 3806 | 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 | }, | | |
| 3872 | } | 3807 | } |
| 3873 | } | 3808 | } |
| 3874 | | 3809 | |
| ... | @@ -4499,7 +4434,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi | ... | @@ -4499,7 +4434,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi |
| 4499 | }; | 4434 | }; |
| 4500 | defer comp.destroy(); | 4435 | defer comp.destroy(); |
| 4501 | | 4436 | |
| 4502 | updateModule(gpa, comp, .none) catch |err| switch (err) { | 4437 | updateModule(comp) catch |err| switch (err) { |
| 4503 | error.SemanticAnalyzeFail => process.exit(2), | 4438 | error.SemanticAnalyzeFail => process.exit(2), |
| 4504 | else => |e| return e, | 4439 | else => |e| return e, |
| 4505 | }; | 4440 | }; |