authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-30 17:05:17-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-02 13:16:17-07:00
logd6c5602d4665ba4e9e7c0b7f42bd00b2489d420c
treec234262f9c98e834ed470fd5fddf18c04cad94d2
parente36718165cdc29b777392a3a343d92ccd1c6acf3

stage2: fix CLI not populating output binary files

This fixes a regression in this branch that can be reproduced with the following steps: 1. `zig build-exe hello.zig` 2. delete the "hello" binary 3. `zig build-exe hello.zig` 4. observe that the "hello" binary is missing This happened because it was a cache hit, but nothing got copied to the output directory. This commit sets CacheMode to incremental - even for stage1 - when the CLI requests `disable_lld_caching` (this option should be renamed), resulting in the main Compilation to be repeated (uncached) for stage1, populating the binary into the cwd as expected. For stage2 the result is even better: the incremental compilation system will look for build artifacts to incrementally compile, and start fresh if not found.

2 files changed, 8 insertions(+), 4 deletions(-)

src/Compilation.zig+4-3
......@@ -899,7 +899,10 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
899899 break :blk build_options.is_stage1;
900900 };
901901
902 const cache_mode = if (use_stage1) CacheMode.whole else options.cache_mode;
902 const cache_mode = if (use_stage1 and !options.disable_lld_caching)
903 CacheMode.whole
904 else
905 options.cache_mode;
903906
904907 // Make a decision on whether to use LLVM or our own backend.
905908 const use_llvm = build_options.have_llvm and blk: {
......@@ -1951,8 +1954,6 @@ pub fn update(comp: *Compilation) !void {
19511954 };
19521955 }
19531956
1954 comp.emitOthers();
1955
19561957 assert(comp.bin_file.lock == null);
19571958 comp.bin_file.lock = man.toOwnedLock();
19581959 return;
src/stage1.zig+4-1
......@@ -458,7 +458,10 @@ export fn stage2_fetch_file(
458458 const comp = @intToPtr(*Compilation, stage1.userdata);
459459 const file_path = path_ptr[0..path_len];
460460 const max_file_size = std.math.maxInt(u32);
461 const contents = comp.whole_cache_manifest.?.addFilePostFetch(file_path, max_file_size) catch return null;
461 const contents = if (comp.whole_cache_manifest) |man|
462 man.addFilePostFetch(file_path, max_file_size) catch return null
463 else
464 std.fs.cwd().readFileAlloc(comp.gpa, file_path, max_file_size) catch return null;
462465 result_len.* = contents.len;
463466 // TODO https://github.com/ziglang/zig/issues/3328#issuecomment-716749475
464467 if (contents.len == 0) return @intToPtr(?[*]const u8, 0x1);