diff --git a/lib/std/build.zig b/lib/std/build.zig index b06ef55db4..0a59c1da6d 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -1735,7 +1735,6 @@ pub const LibExeObjStep = struct { } pub fn linkFramework(self: *LibExeObjStep, framework_name: []const u8) void { - assert(self.target.isDarwin()); // Note: No need to dupe because frameworks dupes internally. self.frameworks.insert(framework_name) catch unreachable; } @@ -2247,28 +2246,6 @@ pub const LibExeObjStep = struct { self.step.dependOn(&other.step); self.link_objects.append(.{ .other_step = other }) catch unreachable; self.include_dirs.append(.{ .other_step = other }) catch unreachable; - - // BUG: The following code introduces a order-of-call dependency: - // var lib = addSharedLibrary(...); - // var exe = addExecutable(...); - // exe.linkLibrary(lib); - // lib.linkSystemLibrary("foobar"); // this will be ignored for exe! - - // Inherit dependency on system libraries - for (other.link_objects.items) |link_object| { - switch (link_object) { - .system_lib => |name| self.linkSystemLibrary(name), - else => continue, - } - } - - // Inherit dependencies on darwin frameworks - if (self.target.isDarwin() and !other.isDynamicLibrary()) { - var it = other.frameworks.iterator(); - while (it.next()) |framework| { - self.frameworks.insert(framework.*) catch unreachable; - } - } } fn makePackageCmd(self: *LibExeObjStep, pkg: Pkg, zig_args: *ArrayList([]const u8)) error{OutOfMemory}!void { @@ -2322,6 +2299,31 @@ pub const LibExeObjStep = struct { if (self.root_src) |root_src| try zig_args.append(root_src.getPath(builder)); var prev_has_extra_flags = false; + + // Resolve transitive dependencies + for (self.link_objects.items) |link_object| { + switch (link_object) { + .other_step => |other| { + // Inherit dependency on system libraries + for (other.link_objects.items) |other_link_object| { + switch (other_link_object) { + .system_lib => |name| self.linkSystemLibrary(name), + else => continue, + } + } + + // Inherit dependencies on darwin frameworks + if (!other.isDynamicLibrary()) { + var it = other.frameworks.iterator(); + while (it.next()) |framework| { + self.frameworks.insert(framework.*) catch unreachable; + } + } + }, + else => continue, + } + } + for (self.link_objects.items) |link_object| { switch (link_object) { .static_path => |static_path| try zig_args.append(static_path.getPath(builder)), @@ -2719,6 +2721,14 @@ pub const LibExeObjStep = struct { zig_args.append("-framework") catch unreachable; zig_args.append(framework.*) catch unreachable; } + } else { + if (self.framework_dirs.items.len > 0) { + warn("Framework directories have been added for a non-darwin target, this will have no affect on the build\n", .{}); + } + + if (self.frameworks.count() > 0) { + warn("Frameworks have been added for a non-darwin target, this will have no affect on the build\n", .{}); + } } if (builder.sysroot) |sysroot| {