authorgravatar for readcuttingt@gmail.comTom Read Cutting <readcuttingt@gmail.com> 2021-06-28 21:48:59+01:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-08-20 13:11:19+03:00
log0cecdca6a24d5009d543962f62c907aa45ec82ff
tree6dcff5ab470504ca31af9814d2a183fba244026b
parentddaca728647c85d77706aead2f7e5d83714cb7fc

Resolve order-of-call dependencies in build.zig


1 files changed, 33 insertions(+), 23 deletions(-)

lib/std/build.zig+33-23
...@@ -1735,7 +1735,6 @@ pub const LibExeObjStep = struct {...@@ -1735,7 +1735,6 @@ pub const LibExeObjStep = struct {
1735 }1735 }
17361736
1737 pub fn linkFramework(self: *LibExeObjStep, framework_name: []const u8) void {1737 pub fn linkFramework(self: *LibExeObjStep, framework_name: []const u8) void {
1738 assert(self.target.isDarwin());
1739 // Note: No need to dupe because frameworks dupes internally.1738 // Note: No need to dupe because frameworks dupes internally.
1740 self.frameworks.insert(framework_name) catch unreachable;1739 self.frameworks.insert(framework_name) catch unreachable;
1741 }1740 }
...@@ -2247,28 +2246,6 @@ pub const LibExeObjStep = struct {...@@ -2247,28 +2246,6 @@ pub const LibExeObjStep = struct {
2247 self.step.dependOn(&other.step);2246 self.step.dependOn(&other.step);
2248 self.link_objects.append(.{ .other_step = other }) catch unreachable;2247 self.link_objects.append(.{ .other_step = other }) catch unreachable;
2249 self.include_dirs.append(.{ .other_step = other }) catch unreachable;2248 self.include_dirs.append(.{ .other_step = other }) catch unreachable;
2250
2251 // BUG: The following code introduces a order-of-call dependency:
2252 // var lib = addSharedLibrary(...);
2253 // var exe = addExecutable(...);
2254 // exe.linkLibrary(lib);
2255 // lib.linkSystemLibrary("foobar"); // this will be ignored for exe!
2256
2257 // Inherit dependency on system libraries
2258 for (other.link_objects.items) |link_object| {
2259 switch (link_object) {
2260 .system_lib => |name| self.linkSystemLibrary(name),
2261 else => continue,
2262 }
2263 }
2264
2265 // Inherit dependencies on darwin frameworks
2266 if (self.target.isDarwin() and !other.isDynamicLibrary()) {
2267 var it = other.frameworks.iterator();
2268 while (it.next()) |framework| {
2269 self.frameworks.insert(framework.*) catch unreachable;
2270 }
2271 }
2272 }2249 }
22732250
2274 fn makePackageCmd(self: *LibExeObjStep, pkg: Pkg, zig_args: *ArrayList([]const u8)) error{OutOfMemory}!void {2251 fn makePackageCmd(self: *LibExeObjStep, pkg: Pkg, zig_args: *ArrayList([]const u8)) error{OutOfMemory}!void {
...@@ -2322,6 +2299,31 @@ pub const LibExeObjStep = struct {...@@ -2322,6 +2299,31 @@ pub const LibExeObjStep = struct {
2322 if (self.root_src) |root_src| try zig_args.append(root_src.getPath(builder));2299 if (self.root_src) |root_src| try zig_args.append(root_src.getPath(builder));
23232300
2324 var prev_has_extra_flags = false;2301 var prev_has_extra_flags = false;
2302
2303 // Resolve transitive dependencies
2304 for (self.link_objects.items) |link_object| {
2305 switch (link_object) {
2306 .other_step => |other| {
2307 // Inherit dependency on system libraries
2308 for (other.link_objects.items) |other_link_object| {
2309 switch (other_link_object) {
2310 .system_lib => |name| self.linkSystemLibrary(name),
2311 else => continue,
2312 }
2313 }
2314
2315 // Inherit dependencies on darwin frameworks
2316 if (!other.isDynamicLibrary()) {
2317 var it = other.frameworks.iterator();
2318 while (it.next()) |framework| {
2319 self.frameworks.insert(framework.*) catch unreachable;
2320 }
2321 }
2322 },
2323 else => continue,
2324 }
2325 }
2326
2325 for (self.link_objects.items) |link_object| {2327 for (self.link_objects.items) |link_object| {
2326 switch (link_object) {2328 switch (link_object) {
2327 .static_path => |static_path| try zig_args.append(static_path.getPath(builder)),2329 .static_path => |static_path| try zig_args.append(static_path.getPath(builder)),
...@@ -2719,6 +2721,14 @@ pub const LibExeObjStep = struct {...@@ -2719,6 +2721,14 @@ pub const LibExeObjStep = struct {
2719 zig_args.append("-framework") catch unreachable;2721 zig_args.append("-framework") catch unreachable;
2720 zig_args.append(framework.*) catch unreachable;2722 zig_args.append(framework.*) catch unreachable;
2721 }2723 }
2724 } else {
2725 if (self.framework_dirs.items.len > 0) {
2726 warn("Framework directories have been added for a non-darwin target, this will have no affect on the build\n", .{});
2727 }
2728
2729 if (self.frameworks.count() > 0) {
2730 warn("Frameworks have been added for a non-darwin target, this will have no affect on the build\n", .{});
2731 }
2722 }2732 }
27232733
2724 if (builder.sysroot) |sysroot| {2734 if (builder.sysroot) |sysroot| {