aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2024-08-18 00:43:33 +0200
committerRobin Voetter <robin@voetter.nl>2024-08-19 19:09:11 +0200
commit43f73af3595c3174b8e67e9f2792c3774f2192e9 (patch)
tree5b178f2316304780f9e84abb60a4286a730ec194 /src/main.zig
parent54e48f7b7dec96c8cdd1a0a0491554b118767817 (diff)
downloadzig-43f73af3595c3174b8e67e9f2792c3774f2192e9.tar.gz
zig-43f73af3595c3174b8e67e9f2792c3774f2192e9.zip
fix various issues related to Path handling in the compiler and std
A compilation build step for which the binary is not required could not be compiled previously. There were 2 issues that caused this: - The compiler communicated only the results of the emitted binary and did not properly communicate the result if the binary was not emitted. This is fixed by communicating the final hash of the artifact path (the hash of the corresponding /o/<hash> directory) and communicating this instead of the entire path. This changes the zig build --listen protocol to communicate hashes instead of paths, and emit_bin_path is accordingly renamed to emit_digest. - There was an error related to the default llvm object path when CacheUse.Whole was selected. I'm not really sure why this didn't manifest when the binary is also emitted. This was fixed by improving the path handling related to flush() and emitLlvmObject(). In general, this commit also improves some of the path handling throughout the compiler and standard library.
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig78
1 files changed, 14 insertions, 64 deletions
diff --git a/src/main.zig b/src/main.zig
index 3429500bf8..1a080224ee 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -4142,7 +4142,7 @@ fn serve(
if (output.errors.errorMessageCount() != 0) {
try server.serveErrorBundle(output.errors);
} else {
- try server.serveEmitBinPath(output.out_zig_path, .{
+ try server.serveEmitDigest(&output.digest, .{
.flags = .{ .cache_hit = output.cache_hit },
});
}
@@ -4229,62 +4229,10 @@ fn serveUpdateResults(s: *Server, comp: *Compilation) !void {
return;
}
- // This logic is counter-intuitive because the protocol accounts for each
- // emitted artifact possibly being in a different location, which correctly
- // matches the behavior of the compiler, however, the build system
- // currently always passes flags that makes all build artifacts output to
- // the same local cache directory, and relies on them all being in the same
- // directory.
- //
- // So, until the build system and protocol are changed to reflect this,
- // this logic must ensure that emit_bin_path is emitted for at least one
- // thing, if there are any artifacts.
-
- switch (comp.cache_use) {
- .incremental => if (comp.bin_file) |lf| {
- const full_path = try lf.emit.directory.join(gpa, &.{lf.emit.sub_path});
- defer gpa.free(full_path);
- try s.serveEmitBinPath(full_path, .{
- .flags = .{ .cache_hit = comp.last_update_was_cache_hit },
- });
- return;
- },
- .whole => |whole| if (whole.bin_sub_path) |sub_path| {
- const full_path = try comp.local_cache_directory.join(gpa, &.{sub_path});
- defer gpa.free(full_path);
- try s.serveEmitBinPath(full_path, .{
- .flags = .{ .cache_hit = comp.last_update_was_cache_hit },
- });
- return;
- },
- }
-
- for ([_]?Compilation.Emit{
- comp.docs_emit,
- comp.implib_emit,
- }) |opt_emit| {
- const emit = opt_emit orelse continue;
- const full_path = try emit.directory.join(gpa, &.{emit.sub_path});
- defer gpa.free(full_path);
- try s.serveEmitBinPath(full_path, .{
+ if (comp.digest) |digest| {
+ try s.serveEmitDigest(&digest, .{
.flags = .{ .cache_hit = comp.last_update_was_cache_hit },
});
- return;
- }
-
- for ([_]?Compilation.EmitLoc{
- comp.emit_asm,
- comp.emit_llvm_ir,
- comp.emit_llvm_bc,
- }) |opt_emit_loc| {
- const emit_loc = opt_emit_loc orelse continue;
- const directory = emit_loc.directory orelse continue;
- const full_path = try directory.join(gpa, &.{emit_loc.basename});
- defer gpa.free(full_path);
- try s.serveEmitBinPath(full_path, .{
- .flags = .{ .cache_hit = comp.last_update_was_cache_hit },
- });
- return;
}
// Serve empty error bundle to indicate the update is done.
@@ -4539,9 +4487,11 @@ fn cmdTranslateC(
};
if (fancy_output) |p| p.cache_hit = true;
- const digest = if (try man.hit()) digest: {
+ const bin_digest, const hex_digest = if (try man.hit()) digest: {
if (file_system_inputs) |buf| try man.populateFileSystemInputs(buf);
- break :digest man.final();
+ const bin_digest = man.finalBin();
+ const hex_digest = Cache.binToHex(bin_digest);
+ break :digest .{ bin_digest, hex_digest };
} else digest: {
if (fancy_output) |p| p.cache_hit = false;
var argv = std.ArrayList([]const u8).init(arena);
@@ -4639,8 +4589,10 @@ fn cmdTranslateC(
};
}
- const digest = man.final();
- const o_sub_path = try fs.path.join(arena, &[_][]const u8{ "o", &digest });
+ const bin_digest = man.finalBin();
+ const hex_digest = Cache.binToHex(bin_digest);
+
+ const o_sub_path = try fs.path.join(arena, &[_][]const u8{ "o", &hex_digest });
var o_dir = try comp.local_cache_directory.handle.makeOpenPath(o_sub_path, .{});
defer o_dir.close();
@@ -4656,16 +4608,14 @@ fn cmdTranslateC(
if (file_system_inputs) |buf| try man.populateFileSystemInputs(buf);
- break :digest digest;
+ break :digest .{ bin_digest, hex_digest };
};
if (fancy_output) |p| {
- p.out_zig_path = try comp.local_cache_directory.join(comp.gpa, &[_][]const u8{
- "o", &digest, translated_zig_basename,
- });
+ p.digest = bin_digest;
p.errors = std.zig.ErrorBundle.empty;
} else {
- const out_zig_path = try fs.path.join(arena, &[_][]const u8{ "o", &digest, translated_zig_basename });
+ const out_zig_path = try fs.path.join(arena, &[_][]const u8{ "o", &hex_digest, translated_zig_basename });
const zig_file = comp.local_cache_directory.handle.openFile(out_zig_path, .{}) catch |err| {
const path = comp.local_cache_directory.path orelse ".";
fatal("unable to open cached translated zig file '{s}{s}{s}': {s}", .{ path, fs.path.sep_str, out_zig_path, @errorName(err) });