diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index 2883992c73a18d4d95f815bb8a855e03af18a119..4a5364176aab665e261db90085f4354994a0cea5 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -264,8 +264,20 @@ pub const HeaderInstallation = union(enum) { dest_rel_path: []const u8, pub fn dupe(self: File, b: *std.Build) File { + // 'path' lazy paths are relative to the build root of some step, inferred from the step + // in which they are used. This means that we can't dupe such paths, because they may + // come from dependencies with their own build roots and duping the paths as is might + // cause the build script to search for the file relative to the wrong root. + // As a temporary workaround, we convert build root-relative paths to absolute paths. + // If/when the build-root relative paths are updated to encode which build root they are + // relative to, this workaround should be removed. + const duped_source: LazyPath = switch (self.source) { + .path => |root_rel| .{ .cwd_relative = b.pathFromRoot(root_rel) }, + else => self.source.dupe(b), + }; + return .{ - .source = self.source.dupe(b), + .source = duped_source, .dest_rel_path = b.dupePath(self.dest_rel_path), }; } @@ -293,8 +305,20 @@ pub const HeaderInstallation = union(enum) { }; pub fn dupe(self: Directory, b: *std.Build) Directory { + // 'path' lazy paths are relative to the build root of some step, inferred from the step + // in which they are used. This means that we can't dupe such paths, because they may + // come from dependencies with their own build roots and duping the paths as is might + // cause the build script to search for the file relative to the wrong root. + // As a temporary workaround, we convert build root-relative paths to absolute paths. + // If/when the build-root relative paths are updated to encode which build root they are + // relative to, this workaround should be removed. + const duped_source: LazyPath = switch (self.source) { + .path => |root_rel| .{ .cwd_relative = b.pathFromRoot(root_rel) }, + else => self.source.dupe(b), + }; + return .{ - .source = self.source.dupe(b), + .source = duped_source, .dest_rel_path = b.dupePath(self.dest_rel_path), .options = self.options.dupe(b), }; @@ -492,9 +516,8 @@ pub fn installConfigHeader(cs: *Compile, config_header: *Step.ConfigHeader) void /// module's include search path. pub fn installLibraryHeaders(cs: *Compile, lib: *Compile) void { assert(lib.kind == .lib); - const b = cs.step.owner; for (lib.installed_headers.items) |installation| { - const installation_copy = installation.dupe(b); + const installation_copy = installation.dupe(lib.step.owner); cs.installed_headers.append(installation_copy) catch @panic("OOM"); cs.addHeaderInstallationToIncludeTree(installation_copy); installation_copy.getSource().addStepDependencies(&cs.step); diff --git a/test/standalone/install_headers/build.zig b/test/standalone/install_headers/build.zig index 965239aac512681cd178159395f8a1e7e82fa64e..4c9bbb501ae7fb82302d6f1b55e1b9d24bdeb53e 100644 --- a/test/standalone/install_headers/build.zig +++ b/test/standalone/install_headers/build.zig @@ -70,7 +70,7 @@ pub fn build(b: *std.Build) void { run_exe.expectStdOutEqual("ABD12X"); test_step.dependOn(&run_exe.step); - const install_exe = b.addInstallArtifact(libfoo, .{ + const install_libfoo = b.addInstallArtifact(libfoo, .{ .dest_dir = .{ .override = .{ .custom = "custom" } }, .h_dir = .{ .override = .{ .custom = "custom/include" } }, .implib_dir = .disabled, @@ -94,6 +94,6 @@ pub fn build(b: *std.Build) void { }); run_check_exists.setCwd(.{ .cwd_relative = b.getInstallPath(.prefix, "") }); run_check_exists.expectExitCode(0); - run_check_exists.step.dependOn(&install_exe.step); + run_check_exists.step.dependOn(&install_libfoo.step); test_step.dependOn(&run_check_exists.step); }