aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Build/Step/Compile.zig
diff options
context:
space:
mode:
authorCarl Åstholm <carl@astholm.se>2024-03-15 19:59:02 +0100
committerCarl Åstholm <carl@astholm.se>2024-04-07 15:34:47 +0200
commiteee5400b7dc37845ea5f42e0841320953e7852b2 (patch)
tree62dc62418a6e784ab03de7a14f7055c9ed913d9f /lib/std/Build/Step/Compile.zig
parentd99e44a157dee9204c38e66bf7eba00c051690ba (diff)
downloadzig-eee5400b7dc37845ea5f42e0841320953e7852b2.tar.gz
zig-eee5400b7dc37845ea5f42e0841320953e7852b2.zip
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.
Diffstat (limited to 'lib/std/Build/Step/Compile.zig')
-rw-r--r--lib/std/Build/Step/Compile.zig31
1 files changed, 27 insertions, 4 deletions
diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig
index 2883992c73..4a5364176a 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);