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.
This commit is contained in:
Andrew Kelley 2021-12-30 17:05:17 -07:00
parent e36718165c
commit d6c5602d46
2 changed files with 8 additions and 4 deletions

View File

@ -899,7 +899,10 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
break :blk build_options.is_stage1;
};
const cache_mode = if (use_stage1) CacheMode.whole else options.cache_mode;
const cache_mode = if (use_stage1 and !options.disable_lld_caching)
CacheMode.whole
else
options.cache_mode;
// Make a decision on whether to use LLVM or our own backend.
const use_llvm = build_options.have_llvm and blk: {
@ -1951,8 +1954,6 @@ pub fn update(comp: *Compilation) !void {
};
}
comp.emitOthers();
assert(comp.bin_file.lock == null);
comp.bin_file.lock = man.toOwnedLock();
return;

View File

@ -458,7 +458,10 @@ export fn stage2_fetch_file(
const comp = @intToPtr(*Compilation, stage1.userdata);
const file_path = path_ptr[0..path_len];
const max_file_size = std.math.maxInt(u32);
const contents = comp.whole_cache_manifest.?.addFilePostFetch(file_path, max_file_size) catch return null;
const contents = if (comp.whole_cache_manifest) |man|
man.addFilePostFetch(file_path, max_file_size) catch return null
else
std.fs.cwd().readFileAlloc(comp.gpa, file_path, max_file_size) catch return null;
result_len.* = contents.len;
// TODO https://github.com/ziglang/zig/issues/3328#issuecomment-716749475
if (contents.len == 0) return @intToPtr(?[*]const u8, 0x1);