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 {
201201/// For passing to a C compiler.
202202pub const CSourceFile = struct {
203203 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 = &.{},
205207};
206208
207209const Job = union(enum) {
......@@ -3251,13 +3253,6 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
32513253
32523254 const module = comp.bin_file.options.module.?;
32533255 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 ),
32613256 error.OutOfMemory => return error.OutOfMemory,
32623257 error.AnalysisFail => return,
32633258 };
......@@ -3562,7 +3557,14 @@ pub fn obtainCObjectCacheManifest(comp: *const Compilation) Cache.Manifest {
35623557 man.hash.add(comp.sanitize_c);
35633558 man.hash.addListOfBytes(comp.clang_argv);
35643559 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
35673569 return man;
35683570}
......@@ -3949,6 +3951,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
39493951 {
39503952 try comp.addCCArgs(arena, &argv, ext, null);
39513953 try argv.appendSlice(c_object.src.extra_flags);
3954 try argv.appendSlice(c_object.src.cache_exempt_flags);
39523955
39533956 const out_obj_path = if (comp.bin_file.options.emit) |emit|
39543957 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
39903993 try std.fmt.allocPrint(arena, "{s}.d", .{out_obj_path});
39913994 try comp.addCCArgs(arena, &argv, ext, out_dep_path);
39923995 try argv.appendSlice(c_object.src.extra_flags);
3996 try argv.appendSlice(c_object.src.cache_exempt_flags);
39933997
39943998 try argv.ensureUnusedCapacity(5);
39953999 switch (comp.clang_preprocessor_mode) {
src/libcxx.zig+30-18
......@@ -187,15 +187,6 @@ pub fn buildLibCXX(comp: *Compilation) !void {
187187 try cflags.append("-faligned-allocation");
188188 }
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
199190 if (target_util.supports_fpic(target)) {
200191 try cflags.append("-fPIC");
201192 }
......@@ -203,9 +194,24 @@ pub fn buildLibCXX(comp: *Compilation) !void {
203194 try cflags.append("-std=c++20");
204195 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
206211 c_source_files.appendAssumeCapacity(.{
207212 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", cxx_src }),
208213 .extra_flags = cflags.items,
214 .cache_exempt_flags = cache_exempt_flags.items,
209215 });
210216 }
211217
......@@ -340,15 +346,6 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
340346 try cflags.append("-D_LIBCPP_HAS_MUSL_LIBC");
341347 }
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
352349 if (target_util.supports_fpic(target)) {
353350 try cflags.append("-fPIC");
354351 }
......@@ -357,9 +354,24 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
357354 try cflags.append("-funwind-tables");
358355 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
360371 c_source_files.appendAssumeCapacity(.{
361372 .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", cxxabi_src }),
362373 .extra_flags = cflags.items,
374 .cache_exempt_flags = cache_exempt_flags.items,
363375 });
364376 }
365377