authorgravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2024-03-15 19:59:02+01:00
committergravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2024-04-07 15:34:47+02:00
logeee5400b7dc37845ea5f42e0841320953e7852b2
tree62dc62418a6e784ab03de7a14f7055c9ed913d9f
parentd99e44a157dee9204c38e66bf7eba00c051690ba

Account for dependency boundaries when duping headers

This is a temporary workaround that can be revered if/when 'path' lazy paths are updated to encode which build root they are relative to.

2 files changed, 29 insertions(+), 6 deletions(-)

lib/std/Build/Step/Compile.zig+27-4
......@@ -264,8 +264,20 @@ pub const HeaderInstallation = union(enum) {
264264 dest_rel_path: []const u8,
265265
266266 pub fn dupe(self: File, b: *std.Build) File {
267 // 'path' lazy paths are relative to the build root of some step, inferred from the step
268 // in which they are used. This means that we can't dupe such paths, because they may
269 // come from dependencies with their own build roots and duping the paths as is might
270 // cause the build script to search for the file relative to the wrong root.
271 // As a temporary workaround, we convert build root-relative paths to absolute paths.
272 // If/when the build-root relative paths are updated to encode which build root they are
273 // relative to, this workaround should be removed.
274 const duped_source: LazyPath = switch (self.source) {
275 .path => |root_rel| .{ .cwd_relative = b.pathFromRoot(root_rel) },
276 else => self.source.dupe(b),
277 };
278
267279 return .{
268 .source = self.source.dupe(b),
280 .source = duped_source,
269281 .dest_rel_path = b.dupePath(self.dest_rel_path),
270282 };
271283 }
......@@ -293,8 +305,20 @@ pub const HeaderInstallation = union(enum) {
293305 };
294306
295307 pub fn dupe(self: Directory, b: *std.Build) Directory {
308 // 'path' lazy paths are relative to the build root of some step, inferred from the step
309 // in which they are used. This means that we can't dupe such paths, because they may
310 // come from dependencies with their own build roots and duping the paths as is might
311 // cause the build script to search for the file relative to the wrong root.
312 // As a temporary workaround, we convert build root-relative paths to absolute paths.
313 // If/when the build-root relative paths are updated to encode which build root they are
314 // relative to, this workaround should be removed.
315 const duped_source: LazyPath = switch (self.source) {
316 .path => |root_rel| .{ .cwd_relative = b.pathFromRoot(root_rel) },
317 else => self.source.dupe(b),
318 };
319
296320 return .{
297 .source = self.source.dupe(b),
321 .source = duped_source,
298322 .dest_rel_path = b.dupePath(self.dest_rel_path),
299323 .options = self.options.dupe(b),
300324 };
......@@ -492,9 +516,8 @@ pub fn installConfigHeader(cs: *Compile, config_header: *Step.ConfigHeader) void
492516/// module's include search path.
493517pub fn installLibraryHeaders(cs: *Compile, lib: *Compile) void {
494518 assert(lib.kind == .lib);
495 const b = cs.step.owner;
496519 for (lib.installed_headers.items) |installation| {
497 const installation_copy = installation.dupe(b);
520 const installation_copy = installation.dupe(lib.step.owner);
498521 cs.installed_headers.append(installation_copy) catch @panic("OOM");
499522 cs.addHeaderInstallationToIncludeTree(installation_copy);
500523 installation_copy.getSource().addStepDependencies(&cs.step);
test/standalone/install_headers/build.zig+2-2
......@@ -70,7 +70,7 @@ pub fn build(b: *std.Build) void {
7070 run_exe.expectStdOutEqual("ABD12X");
7171 test_step.dependOn(&run_exe.step);
7272
73 const install_exe = b.addInstallArtifact(libfoo, .{
73 const install_libfoo = b.addInstallArtifact(libfoo, .{
7474 .dest_dir = .{ .override = .{ .custom = "custom" } },
7575 .h_dir = .{ .override = .{ .custom = "custom/include" } },
7676 .implib_dir = .disabled,
......@@ -94,6 +94,6 @@ pub fn build(b: *std.Build) void {
9494 });
9595 run_check_exists.setCwd(.{ .cwd_relative = b.getInstallPath(.prefix, "") });
9696 run_check_exists.expectExitCode(0);
97 run_check_exists.step.dependOn(&install_exe.step);
97 run_check_exists.step.dependOn(&install_libfoo.step);
9898 test_step.dependOn(&run_check_exists.step);
9999}