@@ -2398,7 +2398,10 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
2398
2398
}
2399
2399
}
2400
2400
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 );
2402
2405
if (comp .totalErrorCount () != 0 ) return ;
2403
2406
2404
2407
// Failure here only means an unnecessary cache miss.
@@ -2414,8 +2417,10 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
2414
2417
assert (whole .lock == null );
2415
2418
whole .lock = man .toOwnedLock ();
2416
2419
},
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 );
2419
2424
if (comp .totalErrorCount () != 0 ) return ;
2420
2425
},
2421
2426
}
@@ -2445,7 +2450,13 @@ pub fn appendFileSystemInput(
2445
2450
std .debug .panic ("missing prefix directory: {}, {s}" , .{ root , sub_file_path });
2446
2451
}
2447
2452
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 {
2449
2460
if (comp .bin_file ) | lf | {
2450
2461
// This is needed before reading the error flags.
2451
2462
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:
2459
2470
try link .File .C .flushEmitH (zcu );
2460
2471
2461
2472
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 );
2473
2474
}
2474
2475
}
2475
2476
}
@@ -2750,7 +2751,7 @@ fn emitOthers(comp: *Compilation) void {
2750
2751
pub fn emitLlvmObject (
2751
2752
comp : * Compilation ,
2752
2753
arena : Allocator ,
2753
- default_emit : Emit ,
2754
+ default_artifact_directory : Path ,
2754
2755
bin_emit_loc : ? EmitLoc ,
2755
2756
llvm_object : LlvmObject.Ptr ,
2756
2757
prog_node : std.Progress.Node ,
@@ -2761,10 +2762,10 @@ pub fn emitLlvmObject(
2761
2762
try llvm_object .emit (.{
2762
2763
.pre_ir_path = comp .verbose_llvm_ir ,
2763
2764
.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 ),
2768
2769
2769
2770
.is_debug = comp .root_mod .optimize_mode == .Debug ,
2770
2771
.is_small = comp .root_mod .optimize_mode == .ReleaseSmall ,
@@ -2777,14 +2778,14 @@ pub fn emitLlvmObject(
2777
2778
2778
2779
fn resolveEmitLoc (
2779
2780
arena : Allocator ,
2780
- default_emit : Emit ,
2781
+ default_artifact_directory : Path ,
2781
2782
opt_loc : ? EmitLoc ,
2782
2783
) Allocator.Error ! ? [* :0 ]const u8 {
2783
2784
const loc = opt_loc orelse return null ;
2784
2785
const slice = if (loc .directory ) | directory |
2785
2786
try directory .joinZ (arena , &.{loc .basename })
2786
2787
else
2787
- try default_emit . basenamePath (arena , loc .basename );
2788
+ try default_artifact_directory . joinStringZ (arena , loc .basename );
2788
2789
return slice .ptr ;
2789
2790
}
2790
2791
@@ -4455,8 +4456,6 @@ pub const CImportResult = struct {
4455
4456
};
4456
4457
4457
4458
/// 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.
4460
4459
pub fn cImport (comp : * Compilation , c_src : []const u8 , owner_mod : * Package.Module ) ! CImportResult {
4461
4460
dev .check (.translate_c_command );
4462
4461
@@ -4570,8 +4569,9 @@ pub fn cImport(comp: *Compilation, c_src: []const u8, owner_mod: *Package.Module
4570
4569
.incremental = > {},
4571
4570
}
4572
4571
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 });
4575
4575
var o_dir = try comp .local_cache_directory .handle .makeOpenPath (o_sub_path , .{});
4576
4576
defer o_dir .close ();
4577
4577
@@ -4583,8 +4583,8 @@ pub fn cImport(comp: *Compilation, c_src: []const u8, owner_mod: *Package.Module
4583
4583
4584
4584
try out_zig_file .writeAll (formatted );
4585
4585
4586
- break :digest digest ;
4587
- } else man .final ();
4586
+ break :digest bin_digest ;
4587
+ } else man .finalBin ();
4588
4588
4589
4589
if (man .have_exclusive_lock ) {
4590
4590
// 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
4596
4596
};
4597
4597
}
4598
4598
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
-
4608
4599
return CImportResult {
4609
- .digest = bin_digest ,
4600
+ .digest = digest ,
4610
4601
.cache_hit = actual_hit ,
4611
4602
.errors = std .zig .ErrorBundle .empty ,
4612
4603
};
0 commit comments