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) {...@@ -264,8 +264,20 @@ pub const HeaderInstallation = union(enum) {
264 dest_rel_path: []const u8,264 dest_rel_path: []const u8,
265265
266 pub fn dupe(self: File, b: *std.Build) File {266 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
267 return .{279 return .{
268 .source = self.source.dupe(b),280 .source = duped_source,
269 .dest_rel_path = b.dupePath(self.dest_rel_path),281 .dest_rel_path = b.dupePath(self.dest_rel_path),
270 };282 };
271 }283 }
...@@ -293,8 +305,20 @@ pub const HeaderInstallation = union(enum) {...@@ -293,8 +305,20 @@ pub const HeaderInstallation = union(enum) {
293 };305 };
294306
295 pub fn dupe(self: Directory, b: *std.Build) Directory {307 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
296 return .{320 return .{
297 .source = self.source.dupe(b),321 .source = duped_source,
298 .dest_rel_path = b.dupePath(self.dest_rel_path),322 .dest_rel_path = b.dupePath(self.dest_rel_path),
299 .options = self.options.dupe(b),323 .options = self.options.dupe(b),
300 };324 };
...@@ -492,9 +516,8 @@ pub fn installConfigHeader(cs: *Compile, config_header: *Step.ConfigHeader) void...@@ -492,9 +516,8 @@ pub fn installConfigHeader(cs: *Compile, config_header: *Step.ConfigHeader) void
492/// module's include search path.516/// module's include search path.
493pub fn installLibraryHeaders(cs: *Compile, lib: *Compile) void {517pub fn installLibraryHeaders(cs: *Compile, lib: *Compile) void {
494 assert(lib.kind == .lib);518 assert(lib.kind == .lib);
495 const b = cs.step.owner;
496 for (lib.installed_headers.items) |installation| {519 for (lib.installed_headers.items) |installation| {
497 const installation_copy = installation.dupe(b);520 const installation_copy = installation.dupe(lib.step.owner);
498 cs.installed_headers.append(installation_copy) catch @panic("OOM");521 cs.installed_headers.append(installation_copy) catch @panic("OOM");
499 cs.addHeaderInstallationToIncludeTree(installation_copy);522 cs.addHeaderInstallationToIncludeTree(installation_copy);
500 installation_copy.getSource().addStepDependencies(&cs.step);523 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 {...@@ -70,7 +70,7 @@ pub fn build(b: *std.Build) void {
70 run_exe.expectStdOutEqual("ABD12X");70 run_exe.expectStdOutEqual("ABD12X");
71 test_step.dependOn(&run_exe.step);71 test_step.dependOn(&run_exe.step);
7272
73 const install_exe = b.addInstallArtifact(libfoo, .{73 const install_libfoo = b.addInstallArtifact(libfoo, .{
74 .dest_dir = .{ .override = .{ .custom = "custom" } },74 .dest_dir = .{ .override = .{ .custom = "custom" } },
75 .h_dir = .{ .override = .{ .custom = "custom/include" } },75 .h_dir = .{ .override = .{ .custom = "custom/include" } },
76 .implib_dir = .disabled,76 .implib_dir = .disabled,
...@@ -94,6 +94,6 @@ pub fn build(b: *std.Build) void {...@@ -94,6 +94,6 @@ pub fn build(b: *std.Build) void {
94 });94 });
95 run_check_exists.setCwd(.{ .cwd_relative = b.getInstallPath(.prefix, "") });95 run_check_exists.setCwd(.{ .cwd_relative = b.getInstallPath(.prefix, "") });
96 run_check_exists.expectExitCode(0);96 run_check_exists.expectExitCode(0);
97 run_check_exists.step.dependOn(&install_exe.step);97 run_check_exists.step.dependOn(&install_libfoo.step);
98 test_step.dependOn(&run_check_exists.step);98 test_step.dependOn(&run_check_exists.step);
99}99}