aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-08-19 21:49:29 -0700
committerGitHub <noreply@github.com>2024-08-19 21:49:29 -0700
commitdffc8c44f9a01aa05ea364ffdc71509d15bc2601 (patch)
treeb9b610ac10bb537b8b0dfba500f6599c5e4b2e15 /src/main.zig
parent7071d1b3c2ed908bb8f1170673b50568ed56da7b (diff)
parent80999391d9b0db0303f59942cb52542a6e4da331 (diff)
downloadzig-dffc8c44f9a01aa05ea364ffdc71509d15bc2601.tar.gz
zig-dffc8c44f9a01aa05ea364ffdc71509d15bc2601.zip
Merge pull request #21115 from Snektron/build-system-asm
compilation and build system fixes
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig86
1 files changed, 18 insertions, 68 deletions
diff --git a/src/main.zig b/src/main.zig
index 3429500bf8..1267baf9a9 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -3519,7 +3519,7 @@ fn buildOutputType(
if (test_exec_args.items.len == 0 and target.ofmt == .c) default_exec_args: {
// Default to using `zig run` to execute the produced .c code from `zig test`.
const c_code_loc = emit_bin_loc orelse break :default_exec_args;
- const c_code_directory = c_code_loc.directory orelse comp.bin_file.?.emit.directory;
+ const c_code_directory = c_code_loc.directory orelse comp.bin_file.?.emit.root_dir;
const c_code_path = try fs.path.join(arena, &[_][]const u8{
c_code_directory.path orelse ".", c_code_loc.basename,
});
@@ -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.
@@ -4308,7 +4256,7 @@ fn runOrTest(
// A naive `directory.join` here will indeed get the correct path to the binary,
// however, in the case of cwd, we actually want `./foo` so that the path can be executed.
const exe_path = try fs.path.join(arena, &[_][]const u8{
- lf.emit.directory.path orelse ".", lf.emit.sub_path,
+ lf.emit.root_dir.path orelse ".", lf.emit.sub_path,
});
var argv = std.ArrayList([]const u8).init(gpa);
@@ -4420,7 +4368,7 @@ fn runOrTestHotSwap(
// tmp zig-cache and use it to spawn the child process. This way we are free to update
// the binary with each requested hot update.
.windows => blk: {
- try lf.emit.directory.handle.copyFile(lf.emit.sub_path, comp.local_cache_directory.handle, lf.emit.sub_path, .{});
+ try lf.emit.root_dir.handle.copyFile(lf.emit.sub_path, comp.local_cache_directory.handle, lf.emit.sub_path, .{});
break :blk try fs.path.join(gpa, &[_][]const u8{
comp.local_cache_directory.path orelse ".", lf.emit.sub_path,
});
@@ -4429,7 +4377,7 @@ fn runOrTestHotSwap(
// A naive `directory.join` here will indeed get the correct path to the binary,
// however, in the case of cwd, we actually want `./foo` so that the path can be executed.
else => try fs.path.join(gpa, &[_][]const u8{
- lf.emit.directory.path orelse ".", lf.emit.sub_path,
+ lf.emit.root_dir.path orelse ".", lf.emit.sub_path,
}),
};
defer gpa.free(exe_path);
@@ -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) });