aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-11-20 15:09:56 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-11-22 20:57:56 -0700
commit58d3ee2a08f5a1f1c66d5e3b4f215361073c6372 (patch)
tree6200d94b14457a36a592585ee7c1e15bc92aafc9
parentd24aaf8847336e12b6571e13d57f6d112452d97d (diff)
downloadzig-58d3ee2a08f5a1f1c66d5e3b4f215361073c6372.tar.gz
zig-58d3ee2a08f5a1f1c66d5e3b4f215361073c6372.zip
Compilation: avoid Cache hash dependency on zig lib path
* Update for the breaking changes to std.fs.path.resolve. This had a happy side effect of deleting some error handling code which is no longer needed. * Introduce cache_exempt_flags field to CSourceFile. This is used only for include directories when building libc++ and libc++abi which depend only on the zig lib path. * libc_include_dir_list is only added to the cache hash when it contains directories which have been obtained from system probing. It is exempt when the directories depend only on the zig lib path.
-rw-r--r--src/Compilation.zig22
-rw-r--r--src/libcxx.zig48
2 files changed, 43 insertions, 27 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 2c94785618..795eb493e2 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -201,7 +201,9 @@ pub const CRTFile = struct {
/// For passing to a C compiler.
pub const CSourceFile = struct {
src_path: []const u8,
- extra_flags: []const []const u8 = &[0][]const u8{},
+ extra_flags: []const []const u8 = &.{},
+ /// Same as extra_flags except they are not added to the Cache hash.
+ cache_exempt_flags: []const []const u8 = &.{},
};
const Job = union(enum) {
@@ -3251,13 +3253,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
const module = comp.bin_file.options.module.?;
module.semaPkg(pkg) catch |err| switch (err) {
- error.CurrentWorkingDirectoryUnlinked,
- error.Unexpected,
- => comp.lockAndSetMiscFailure(
- .analyze_pkg,
- "unexpected problem analyzing package '{s}'",
- .{pkg.root_src_path},
- ),
error.OutOfMemory => return error.OutOfMemory,
error.AnalysisFail => return,
};
@@ -3562,7 +3557,14 @@ pub fn obtainCObjectCacheManifest(comp: *const Compilation) Cache.Manifest {
man.hash.add(comp.sanitize_c);
man.hash.addListOfBytes(comp.clang_argv);
man.hash.add(comp.bin_file.options.link_libcpp);
- man.hash.addListOfBytes(comp.libc_include_dir_list);
+
+ // When libc_installation is null it means that Zig generated this dir list
+ // based on the zig library directory alone. The zig lib directory file
+ // path is purposefully either in the cache or not in the cache. The
+ // decision should not be overridden here.
+ if (comp.bin_file.options.libc_installation != null) {
+ man.hash.addListOfBytes(comp.libc_include_dir_list);
+ }
return man;
}
@@ -3949,6 +3951,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
{
try comp.addCCArgs(arena, &argv, ext, null);
try argv.appendSlice(c_object.src.extra_flags);
+ try argv.appendSlice(c_object.src.cache_exempt_flags);
const out_obj_path = if (comp.bin_file.options.emit) |emit|
try emit.directory.join(arena, &.{emit.sub_path})
@@ -3990,6 +3993,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
try std.fmt.allocPrint(arena, "{s}.d", .{out_obj_path});
try comp.addCCArgs(arena, &argv, ext, out_dep_path);
try argv.appendSlice(c_object.src.extra_flags);
+ try argv.appendSlice(c_object.src.cache_exempt_flags);
try argv.ensureUnusedCapacity(5);
switch (comp.clang_preprocessor_mode) {
diff --git a/src/libcxx.zig b/src/libcxx.zig
index 850da698c5..7ca405cf15 100644
--- a/src/libcxx.zig
+++ b/src/libcxx.zig
@@ -187,15 +187,6 @@ pub fn buildLibCXX(comp: *Compilation) !void {
try cflags.append("-faligned-allocation");
}
- try cflags.append("-I");
- try cflags.append(cxx_include_path);
-
- try cflags.append("-I");
- try cflags.append(cxxabi_include_path);
-
- try cflags.append("-I");
- try cflags.append(cxx_src_include_path);
-
if (target_util.supports_fpic(target)) {
try cflags.append("-fPIC");
}
@@ -203,9 +194,24 @@ pub fn buildLibCXX(comp: *Compilation) !void {
try cflags.append("-std=c++20");
try cflags.append("-Wno-user-defined-literals");
+ // These depend on only the zig lib directory file path, which is
+ // purposefully either in the cache or not in the cache. The decision
+ // should not be overridden here.
+ var cache_exempt_flags = std.ArrayList([]const u8).init(arena);
+
+ try cache_exempt_flags.append("-I");
+ try cache_exempt_flags.append(cxx_include_path);
+
+ try cache_exempt_flags.append("-I");
+ try cache_exempt_flags.append(cxxabi_include_path);
+
+ try cache_exempt_flags.append("-I");
+ try cache_exempt_flags.append(cxx_src_include_path);
+
c_source_files.appendAssumeCapacity(.{
.src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", cxx_src }),
.extra_flags = cflags.items,
+ .cache_exempt_flags = cache_exempt_flags.items,
});
}
@@ -340,15 +346,6 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
try cflags.append("-D_LIBCPP_HAS_MUSL_LIBC");
}
- try cflags.append("-I");
- try cflags.append(cxxabi_include_path);
-
- try cflags.append("-I");
- try cflags.append(cxx_include_path);
-
- try cflags.append("-I");
- try cflags.append(cxx_src_include_path);
-
if (target_util.supports_fpic(target)) {
try cflags.append("-fPIC");
}
@@ -357,9 +354,24 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
try cflags.append("-funwind-tables");
try cflags.append("-std=c++20");
+ // These depend on only the zig lib directory file path, which is
+ // purposefully either in the cache or not in the cache. The decision
+ // should not be overridden here.
+ var cache_exempt_flags = std.ArrayList([]const u8).init(arena);
+
+ try cache_exempt_flags.append("-I");
+ try cache_exempt_flags.append(cxxabi_include_path);
+
+ try cache_exempt_flags.append("-I");
+ try cache_exempt_flags.append(cxx_include_path);
+
+ try cache_exempt_flags.append("-I");
+ try cache_exempt_flags.append(cxx_src_include_path);
+
c_source_files.appendAssumeCapacity(.{
.src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", cxxabi_src }),
.extra_flags = cflags.items,
+ .cache_exempt_flags = cache_exempt_flags.items,
});
}