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