Skip to content

Commit 4ecd243

Browse files
committed
hhhh
1 parent e358e60 commit 4ecd243

File tree

2 files changed

+33
-39
lines changed

2 files changed

+33
-39
lines changed

src/Compilation.zig

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,7 +2398,10 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
23982398
}
23992399
}
24002400

2401-
try flush(comp, arena, .main, main_progress_node);
2401+
try flush(comp, arena, .{
2402+
.root_dir = comp.local_cache_directory,
2403+
.sub_path = o_sub_path,
2404+
}, .main, main_progress_node);
24022405
if (comp.totalErrorCount() != 0) return;
24032406

24042407
// Failure here only means an unnecessary cache miss.
@@ -2414,8 +2417,10 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
24142417
assert(whole.lock == null);
24152418
whole.lock = man.toOwnedLock();
24162419
},
2417-
.incremental => {
2418-
try flush(comp, arena, .main, main_progress_node);
2420+
.incremental => |incremental| {
2421+
try flush(comp, arena, .{
2422+
.root_dir = incremental.artifact_directory,
2423+
}, .main, main_progress_node);
24192424
if (comp.totalErrorCount() != 0) return;
24202425
},
24212426
}
@@ -2445,7 +2450,13 @@ pub fn appendFileSystemInput(
24452450
std.debug.panic("missing prefix directory: {}, {s}", .{ root, sub_file_path });
24462451
}
24472452

2448-
fn flush(comp: *Compilation, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Progress.Node) !void {
2453+
fn flush(
2454+
comp: *Compilation,
2455+
arena: Allocator,
2456+
default_artifact_directory: Path,
2457+
tid: Zcu.PerThread.Id,
2458+
prog_node: std.Progress.Node,
2459+
) !void {
24492460
if (comp.bin_file) |lf| {
24502461
// This is needed before reading the error flags.
24512462
lf.flush(arena, tid, prog_node) catch |err| switch (err) {
@@ -2459,17 +2470,7 @@ fn flush(comp: *Compilation, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
24592470
try link.File.C.flushEmitH(zcu);
24602471

24612472
if (zcu.llvm_object) |llvm_object| {
2462-
const default_emit = switch (comp.cache_use) {
2463-
.whole => |whole| .{
2464-
.directory = whole.tmp_artifact_directory.?,
2465-
.sub_path = "dummy",
2466-
},
2467-
.incremental => |incremental| .{
2468-
.directory = incremental.artifact_directory,
2469-
.sub_path = "dummy",
2470-
},
2471-
};
2472-
try emitLlvmObject(comp, arena, default_emit, null, llvm_object, prog_node);
2473+
try emitLlvmObject(comp, arena, default_artifact_directory, null, llvm_object, prog_node);
24732474
}
24742475
}
24752476
}
@@ -2750,7 +2751,7 @@ fn emitOthers(comp: *Compilation) void {
27502751
pub fn emitLlvmObject(
27512752
comp: *Compilation,
27522753
arena: Allocator,
2753-
default_emit: Emit,
2754+
default_artifact_directory: Path,
27542755
bin_emit_loc: ?EmitLoc,
27552756
llvm_object: LlvmObject.Ptr,
27562757
prog_node: std.Progress.Node,
@@ -2761,10 +2762,10 @@ pub fn emitLlvmObject(
27612762
try llvm_object.emit(.{
27622763
.pre_ir_path = comp.verbose_llvm_ir,
27632764
.pre_bc_path = comp.verbose_llvm_bc,
2764-
.bin_path = try resolveEmitLoc(arena, default_emit, bin_emit_loc),
2765-
.asm_path = try resolveEmitLoc(arena, default_emit, comp.emit_asm),
2766-
.post_ir_path = try resolveEmitLoc(arena, default_emit, comp.emit_llvm_ir),
2767-
.post_bc_path = try resolveEmitLoc(arena, default_emit, comp.emit_llvm_bc),
2765+
.bin_path = try resolveEmitLoc(arena, default_artifact_directory, bin_emit_loc),
2766+
.asm_path = try resolveEmitLoc(arena, default_artifact_directory, comp.emit_asm),
2767+
.post_ir_path = try resolveEmitLoc(arena, default_artifact_directory, comp.emit_llvm_ir),
2768+
.post_bc_path = try resolveEmitLoc(arena, default_artifact_directory, comp.emit_llvm_bc),
27682769

27692770
.is_debug = comp.root_mod.optimize_mode == .Debug,
27702771
.is_small = comp.root_mod.optimize_mode == .ReleaseSmall,
@@ -2777,14 +2778,14 @@ pub fn emitLlvmObject(
27772778

27782779
fn resolveEmitLoc(
27792780
arena: Allocator,
2780-
default_emit: Emit,
2781+
default_artifact_directory: Path,
27812782
opt_loc: ?EmitLoc,
27822783
) Allocator.Error!?[*:0]const u8 {
27832784
const loc = opt_loc orelse return null;
27842785
const slice = if (loc.directory) |directory|
27852786
try directory.joinZ(arena, &.{loc.basename})
27862787
else
2787-
try default_emit.basenamePath(arena, loc.basename);
2788+
try default_artifact_directory.joinStringZ(arena, loc.basename);
27882789
return slice.ptr;
27892790
}
27902791

@@ -4455,8 +4456,6 @@ pub const CImportResult = struct {
44554456
};
44564457

44574458
/// Caller owns returned memory.
4458-
/// This API is currently coupled pretty tightly to stage1's needs; it will need to be reworked
4459-
/// a bit when we want to start using it from self-hosted.
44604459
pub fn cImport(comp: *Compilation, c_src: []const u8, owner_mod: *Package.Module) !CImportResult {
44614460
dev.check(.translate_c_command);
44624461

@@ -4570,8 +4569,9 @@ pub fn cImport(comp: *Compilation, c_src: []const u8, owner_mod: *Package.Module
45704569
.incremental => {},
45714570
}
45724571

4573-
const digest = man.final();
4574-
const o_sub_path = try std.fs.path.join(arena, &[_][]const u8{ "o", &digest });
4572+
const bin_digest = man.finalBin();
4573+
const hex_digest = Cache.binToHex(digest);
4574+
const o_sub_path = try std.fs.path.join(arena, &[_][]const u8{ "o", &hex_digest });
45754575
var o_dir = try comp.local_cache_directory.handle.makeOpenPath(o_sub_path, .{});
45764576
defer o_dir.close();
45774577

@@ -4583,8 +4583,8 @@ pub fn cImport(comp: *Compilation, c_src: []const u8, owner_mod: *Package.Module
45834583

45844584
try out_zig_file.writeAll(formatted);
45854585

4586-
break :digest digest;
4587-
} else man.final();
4586+
break :digest bin_digest;
4587+
} else man.finalBin();
45884588

45894589
if (man.have_exclusive_lock) {
45904590
// Write the updated manifest. This is a no-op if the manifest is not dirty. Note that it is
@@ -4596,17 +4596,8 @@ pub fn cImport(comp: *Compilation, c_src: []const u8, owner_mod: *Package.Module
45964596
};
45974597
}
45984598

4599-
// const out_zig_path = try comp.local_cache_directory.join(comp.arena, &.{
4600-
// "o", &digest, cimport_zig_basename,
4601-
// });
4602-
// if (comp.verbose_cimport) {
4603-
// log.info("C import output: {s}", .{out_zig_path});
4604-
// }
4605-
var bin_digest: [Cache.bin_digest_len]u8 = undefined;
4606-
_ = std.fmt.hexToBytes(&bin_digest, &digest) catch unreachable;
4607-
46084599
return CImportResult{
4609-
.digest = bin_digest,
4600+
.digest = digest,
46104601
.cache_hit = actual_hit,
46114602
.errors = std.zig.ErrorBundle.empty,
46124603
};

src/link.zig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,10 @@ pub const File = struct {
10291029
llvm_object: LlvmObject.Ptr,
10301030
prog_node: std.Progress.Node,
10311031
) !void {
1032-
return base.comp.emitLlvmObject(arena, base.emit, .{
1032+
return base.comp.emitLlvmObject(arena, .{
1033+
.root_dir = base.emit.directory,
1034+
.sub_path = std.fs.path.dirname(base.emit.sub_path) orelse "",
1035+
}, .{
10331036
.directory = null,
10341037
.basename = base.zcu_object_sub_path.?,
10351038
}, llvm_object, prog_node);

0 commit comments

Comments
 (0)