authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-11-20 15:09:56-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-11-22 20:57:56-07:00
log58d3ee2a08f5a1f1c66d5e3b4f215361073c6372
tree6200d94b14457a36a592585ee7c1e15bc92aafc9
parentd24aaf8847336e12b6571e13d57f6d112452d97d

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.

2 files changed, 43 insertions(+), 27 deletions(-)

src/Compilation.zig+13-9
...@@ -201,7 +201,9 @@ pub const CRTFile = struct {...@@ -201,7 +201,9 @@ pub const CRTFile = struct {
201/// For passing to a C compiler.201/// For passing to a C compiler.
202pub const CSourceFile = struct {202pub const CSourceFile = struct {
203 src_path: []const u8,203 src_path: []const u8,
204 extra_flags: []const []const u8 = &[0][]const u8{},204 extra_flags: []const []const u8 = &.{},
205 /// Same as extra_flags except they are not added to the Cache hash.
206 cache_exempt_flags: []const []const u8 = &.{},
205};207};
206208
207const Job = union(enum) {209const Job = union(enum) {
...@@ -3251,13 +3253,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {...@@ -3251,13 +3253,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
32513253
3252 const module = comp.bin_file.options.module.?;3254 const module = comp.bin_file.options.module.?;
3253 module.semaPkg(pkg) catch |err| switch (err) {3255 module.semaPkg(pkg) catch |err| switch (err) {
3254 error.CurrentWorkingDirectoryUnlinked,
3255 error.Unexpected,
3256 => comp.lockAndSetMiscFailure(
3257 .analyze_pkg,
3258 "unexpected problem analyzing package '{s}'",
3259 .{pkg.root_src_path},
3260 ),
3261 error.OutOfMemory => return error.OutOfMemory,3256 error.OutOfMemory => return error.OutOfMemory,
3262 error.AnalysisFail => return,3257 error.AnalysisFail => return,
3263 };3258 };
...@@ -3562,7 +3557,14 @@ pub fn obtainCObjectCacheManifest(comp: *const Compilation) Cache.Manifest {...@@ -3562,7 +3557,14 @@ pub fn obtainCObjectCacheManifest(comp: *const Compilation) Cache.Manifest {
3562 man.hash.add(comp.sanitize_c);3557 man.hash.add(comp.sanitize_c);
3563 man.hash.addListOfBytes(comp.clang_argv);3558 man.hash.addListOfBytes(comp.clang_argv);
3564 man.hash.add(comp.bin_file.options.link_libcpp);3559 man.hash.add(comp.bin_file.options.link_libcpp);
3565 man.hash.addListOfBytes(comp.libc_include_dir_list);3560
3561 // When libc_installation is null it means that Zig generated this dir list
3562 // based on the zig library directory alone. The zig lib directory file
3563 // path is purposefully either in the cache or not in the cache. The
3564 // decision should not be overridden here.
3565 if (comp.bin_file.options.libc_installation != null) {
3566 man.hash.addListOfBytes(comp.libc_include_dir_list);
3567 }
35663568
3567 return man;3569 return man;
3568}3570}
...@@ -3949,6 +3951,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P...@@ -3949,6 +3951,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
3949 {3951 {
3950 try comp.addCCArgs(arena, &argv, ext, null);3952 try comp.addCCArgs(arena, &argv, ext, null);
3951 try argv.appendSlice(c_object.src.extra_flags);3953 try argv.appendSlice(c_object.src.extra_flags);
3954 try argv.appendSlice(c_object.src.cache_exempt_flags);
39523955
3953 const out_obj_path = if (comp.bin_file.options.emit) |emit|3956 const out_obj_path = if (comp.bin_file.options.emit) |emit|
3954 try emit.directory.join(arena, &.{emit.sub_path})3957 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...@@ -3990,6 +3993,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
3990 try std.fmt.allocPrint(arena, "{s}.d", .{out_obj_path});3993 try std.fmt.allocPrint(arena, "{s}.d", .{out_obj_path});
3991 try comp.addCCArgs(arena, &argv, ext, out_dep_path);3994 try comp.addCCArgs(arena, &argv, ext, out_dep_path);
3992 try argv.appendSlice(c_object.src.extra_flags);3995 try argv.appendSlice(c_object.src.extra_flags);
3996 try argv.appendSlice(c_object.src.cache_exempt_flags);
39933997
3994 try argv.ensureUnusedCapacity(5);3998 try argv.ensureUnusedCapacity(5);
3995 switch (comp.clang_preprocessor_mode) {3999 switch (comp.clang_preprocessor_mode) {
src/libcxx.zig+30-18
...@@ -187,15 +187,6 @@ pub fn buildLibCXX(comp: *Compilation) !void {...@@ -187,15 +187,6 @@ pub fn buildLibCXX(comp: *Compilation) !void {
187 try cflags.append("-faligned-allocation");187 try cflags.append("-faligned-allocation");
188 }188 }
189189
190 try cflags.append("-I");
191 try cflags.append(cxx_include_path);
192
193 try cflags.append("-I");
194 try cflags.append(cxxabi_include_path);
195
196 try cflags.append("-I");
197 try cflags.append(cxx_src_include_path);
198
199 if (target_util.supports_fpic(target)) {190 if (target_util.supports_fpic(target)) {
200 try cflags.append("-fPIC");191 try cflags.append("-fPIC");
201 }192 }
...@@ -203,9 +194,24 @@ pub fn buildLibCXX(comp: *Compilation) !void {...@@ -203,9 +194,24 @@ pub fn buildLibCXX(comp: *Compilation) !void {
203 try cflags.append("-std=c++20");194 try cflags.append("-std=c++20");
204 try cflags.append("-Wno-user-defined-literals");195 try cflags.append("-Wno-user-defined-literals");
205196
197 // These depend on only the zig lib directory file path, which is
198 // purposefully either in the cache or not in the cache. The decision
199 // should not be overridden here.
200 var cache_exempt_flags = std.ArrayList([]const u8).init(arena);
201
202 try cache_exempt_flags.append("-I");
203 try cache_exempt_flags.append(cxx_include_path);
204
205 try cache_exempt_flags.append("-I");
206 try cache_exempt_flags.append(cxxabi_include_path);
207
208 try cache_exempt_flags.append("-I");
209 try cache_exempt_flags.append(cxx_src_include_path);
210
206 c_source_files.appendAssumeCapacity(.{211 c_source_files.appendAssumeCapacity(.{
207 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", cxx_src }),212 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", cxx_src }),
208 .extra_flags = cflags.items,213 .extra_flags = cflags.items,
214 .cache_exempt_flags = cache_exempt_flags.items,
209 });215 });
210 }216 }
211217
...@@ -340,15 +346,6 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {...@@ -340,15 +346,6 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
340 try cflags.append("-D_LIBCPP_HAS_MUSL_LIBC");346 try cflags.append("-D_LIBCPP_HAS_MUSL_LIBC");
341 }347 }
342348
343 try cflags.append("-I");
344 try cflags.append(cxxabi_include_path);
345
346 try cflags.append("-I");
347 try cflags.append(cxx_include_path);
348
349 try cflags.append("-I");
350 try cflags.append(cxx_src_include_path);
351
352 if (target_util.supports_fpic(target)) {349 if (target_util.supports_fpic(target)) {
353 try cflags.append("-fPIC");350 try cflags.append("-fPIC");
354 }351 }
...@@ -357,9 +354,24 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {...@@ -357,9 +354,24 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
357 try cflags.append("-funwind-tables");354 try cflags.append("-funwind-tables");
358 try cflags.append("-std=c++20");355 try cflags.append("-std=c++20");
359356
357 // These depend on only the zig lib directory file path, which is
358 // purposefully either in the cache or not in the cache. The decision
359 // should not be overridden here.
360 var cache_exempt_flags = std.ArrayList([]const u8).init(arena);
361
362 try cache_exempt_flags.append("-I");
363 try cache_exempt_flags.append(cxxabi_include_path);
364
365 try cache_exempt_flags.append("-I");
366 try cache_exempt_flags.append(cxx_include_path);
367
368 try cache_exempt_flags.append("-I");
369 try cache_exempt_flags.append(cxx_src_include_path);
370
360 c_source_files.appendAssumeCapacity(.{371 c_source_files.appendAssumeCapacity(.{
361 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", cxxabi_src }),372 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", cxxabi_src }),
362 .extra_flags = cflags.items,373 .extra_flags = cflags.items,
374 .cache_exempt_flags = cache_exempt_flags.items,
363 });375 });
364 }376 }
365377