aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.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/Sema.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/Sema.zig')
-rw-r--r--src/Sema.zig11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index c8e2f2ae15..b511fead33 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -183,6 +183,7 @@ const InternPool = @import("InternPool.zig");
const Alignment = InternPool.Alignment;
const AnalUnit = InternPool.AnalUnit;
const ComptimeAllocIndex = InternPool.ComptimeAllocIndex;
+const Cache = std.Build.Cache;
pub const default_branch_quota = 1000;
pub const default_reference_trace_len = 2;
@@ -5871,16 +5872,18 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
return sema.failWithOwnedErrorMsg(&child_block, msg);
}
const parent_mod = parent_block.ownerModule();
+ const digest = Cache.binToHex(c_import_res.digest);
+ const c_import_zig_path = try comp.arena.dupe(u8, "o" ++ std.fs.path.sep_str ++ digest);
const c_import_mod = Package.Module.create(comp.arena, .{
.global_cache_directory = comp.global_cache_directory,
.paths = .{
.root = .{
- .root_dir = Compilation.Directory.cwd(),
- .sub_path = std.fs.path.dirname(c_import_res.out_zig_path) orelse "",
+ .root_dir = comp.local_cache_directory,
+ .sub_path = c_import_zig_path,
},
- .root_src_path = std.fs.path.basename(c_import_res.out_zig_path),
+ .root_src_path = "cimport.zig",
},
- .fully_qualified_name = c_import_res.out_zig_path,
+ .fully_qualified_name = c_import_zig_path,
.cc_argv = parent_mod.cc_argv,
.inherited = .{},
.global = comp.config,