| ... | ... | @@ -149,13 +149,6 @@ entitlements: ?[]const u8 = null, |
| 149 | 149 | /// (Darwin) Size of the pagezero segment. |
| 150 | 150 | pagezero_size: ?u64 = null, |
| 151 | 151 | |
| 152 | | /// (Darwin) Search strategy for searching system libraries. Either `paths_first` or `dylibs_first`. |
| 153 | | /// The former lowers to `-search_paths_first` linker option, while the latter to `-search_dylibs_first` |
| 154 | | /// option. |
| 155 | | /// By default, if no option is specified, the linker assumes `paths_first` as the default |
| 156 | | /// search strategy. |
| 157 | | search_strategy: ?enum { paths_first, dylibs_first } = null, |
| 158 | | |
| 159 | 152 | /// (Darwin) Set size of the padding between the end of load commands |
| 160 | 153 | /// and start of `__TEXT,__text` section. |
| 161 | 154 | headerpad_size: ?u32 = null, |
| ... | ... | @@ -242,7 +235,11 @@ pub const SystemLib = struct { |
| 242 | 235 | name: []const u8, |
| 243 | 236 | needed: bool, |
| 244 | 237 | weak: bool, |
| 245 | | use_pkg_config: enum { |
| 238 | use_pkg_config: UsePkgConfig, |
| 239 | preferred_link_mode: std.builtin.LinkMode, |
| 240 | search_strategy: SystemLib.SearchStrategy, |
| 241 | |
| 242 | pub const UsePkgConfig = enum { |
| 246 | 243 | /// Don't use pkg-config, just pass -lfoo where foo is name. |
| 247 | 244 | no, |
| 248 | 245 | /// Try to get information on how to link the library from pkg-config. |
| ... | ... | @@ -251,7 +248,9 @@ pub const SystemLib = struct { |
| 251 | 248 | /// Try to get information on how to link the library from pkg-config. |
| 252 | 249 | /// If that fails, error out. |
| 253 | 250 | force, |
| 254 | | }, |
| 251 | }; |
| 252 | |
| 253 | pub const SearchStrategy = enum { paths_first, mode_first, no_fallback }; |
| 255 | 254 | }; |
| 256 | 255 | |
| 257 | 256 | const FrameworkLinkInfo = struct { |
| ... | ... | @@ -718,74 +717,29 @@ pub fn defineCMacroRaw(self: *Compile, name_and_value: []const u8) void { |
| 718 | 717 | self.c_macros.append(b.dupe(name_and_value)) catch @panic("OOM"); |
| 719 | 718 | } |
| 720 | 719 | |
| 721 | | /// This one has no integration with anything, it just puts -lname on the command line. |
| 722 | | /// Prefer to use `linkSystemLibrary` instead. |
| 720 | /// deprecated: use linkSystemLibrary2 |
| 723 | 721 | pub fn linkSystemLibraryName(self: *Compile, name: []const u8) void { |
| 724 | | const b = self.step.owner; |
| 725 | | self.link_objects.append(.{ |
| 726 | | .system_lib = .{ |
| 727 | | .name = b.dupe(name), |
| 728 | | .needed = false, |
| 729 | | .weak = false, |
| 730 | | .use_pkg_config = .no, |
| 731 | | }, |
| 732 | | }) catch @panic("OOM"); |
| 722 | return linkSystemLibrary2(self, name, .{ .use_pkg_config = .no }); |
| 733 | 723 | } |
| 734 | 724 | |
| 735 | | /// This one has no integration with anything, it just puts -needed-lname on the command line. |
| 736 | | /// Prefer to use `linkSystemLibraryNeeded` instead. |
| 725 | /// deprecated: use linkSystemLibrary2 |
| 737 | 726 | pub fn linkSystemLibraryNeededName(self: *Compile, name: []const u8) void { |
| 738 | | const b = self.step.owner; |
| 739 | | self.link_objects.append(.{ |
| 740 | | .system_lib = .{ |
| 741 | | .name = b.dupe(name), |
| 742 | | .needed = true, |
| 743 | | .weak = false, |
| 744 | | .use_pkg_config = .no, |
| 745 | | }, |
| 746 | | }) catch @panic("OOM"); |
| 727 | return linkSystemLibrary2(self, name, .{ .needed = true, .use_pkg_config = .no }); |
| 747 | 728 | } |
| 748 | 729 | |
| 749 | | /// Darwin-only. This one has no integration with anything, it just puts -weak-lname on the |
| 750 | | /// command line. Prefer to use `linkSystemLibraryWeak` instead. |
| 730 | /// deprecated: use linkSystemLibrary2 |
| 751 | 731 | pub fn linkSystemLibraryWeakName(self: *Compile, name: []const u8) void { |
| 752 | | const b = self.step.owner; |
| 753 | | self.link_objects.append(.{ |
| 754 | | .system_lib = .{ |
| 755 | | .name = b.dupe(name), |
| 756 | | .needed = false, |
| 757 | | .weak = true, |
| 758 | | .use_pkg_config = .no, |
| 759 | | }, |
| 760 | | }) catch @panic("OOM"); |
| 732 | return linkSystemLibrary2(self, name, .{ .weak = true, .use_pkg_config = .no }); |
| 761 | 733 | } |
| 762 | 734 | |
| 763 | | /// This links against a system library, exclusively using pkg-config to find the library. |
| 764 | | /// Prefer to use `linkSystemLibrary` instead. |
| 735 | /// deprecated: use linkSystemLibrary2 |
| 765 | 736 | pub fn linkSystemLibraryPkgConfigOnly(self: *Compile, lib_name: []const u8) void { |
| 766 | | const b = self.step.owner; |
| 767 | | self.link_objects.append(.{ |
| 768 | | .system_lib = .{ |
| 769 | | .name = b.dupe(lib_name), |
| 770 | | .needed = false, |
| 771 | | .weak = false, |
| 772 | | .use_pkg_config = .force, |
| 773 | | }, |
| 774 | | }) catch @panic("OOM"); |
| 737 | return linkSystemLibrary2(self, lib_name, .{ .use_pkg_config = .force }); |
| 775 | 738 | } |
| 776 | 739 | |
| 777 | | /// This links against a system library, exclusively using pkg-config to find the library. |
| 778 | | /// Prefer to use `linkSystemLibraryNeeded` instead. |
| 740 | /// deprecated: use linkSystemLibrary2 |
| 779 | 741 | pub fn linkSystemLibraryNeededPkgConfigOnly(self: *Compile, lib_name: []const u8) void { |
| 780 | | const b = self.step.owner; |
| 781 | | self.link_objects.append(.{ |
| 782 | | .system_lib = .{ |
| 783 | | .name = b.dupe(lib_name), |
| 784 | | .needed = true, |
| 785 | | .weak = false, |
| 786 | | .use_pkg_config = .force, |
| 787 | | }, |
| 788 | | }) catch @panic("OOM"); |
| 742 | return linkSystemLibrary2(self, lib_name, .{ .needed = true, .use_pkg_config = .force }); |
| 789 | 743 | } |
| 790 | 744 | |
| 791 | 745 | /// Run pkg-config for the given library name and parse the output, returning the arguments |
| ... | ... | @@ -885,21 +839,32 @@ fn runPkgConfig(self: *Compile, lib_name: []const u8) ![]const []const u8 { |
| 885 | 839 | } |
| 886 | 840 | |
| 887 | 841 | pub fn linkSystemLibrary(self: *Compile, name: []const u8) void { |
| 888 | | self.linkSystemLibraryInner(name, .{}); |
| 842 | self.linkSystemLibrary2(name, .{}); |
| 889 | 843 | } |
| 890 | 844 | |
| 845 | /// deprecated: use linkSystemLibrary2 |
| 891 | 846 | pub fn linkSystemLibraryNeeded(self: *Compile, name: []const u8) void { |
| 892 | | self.linkSystemLibraryInner(name, .{ .needed = true }); |
| 847 | return linkSystemLibrary2(self, name, .{ .needed = true }); |
| 893 | 848 | } |
| 894 | 849 | |
| 850 | /// deprecated: use linkSystemLibrary2 |
| 895 | 851 | pub fn linkSystemLibraryWeak(self: *Compile, name: []const u8) void { |
| 896 | | self.linkSystemLibraryInner(name, .{ .weak = true }); |
| 852 | return linkSystemLibrary2(self, name, .{ .weak = true }); |
| 897 | 853 | } |
| 898 | 854 | |
| 899 | | fn linkSystemLibraryInner(self: *Compile, name: []const u8, opts: struct { |
| 855 | pub const LinkSystemLibraryOptions = struct { |
| 900 | 856 | needed: bool = false, |
| 901 | 857 | weak: bool = false, |
| 902 | | }) void { |
| 858 | use_pkg_config: SystemLib.UsePkgConfig = .yes, |
| 859 | preferred_link_mode: std.builtin.LinkMode = .Dynamic, |
| 860 | search_strategy: SystemLib.SearchStrategy = .paths_first, |
| 861 | }; |
| 862 | |
| 863 | pub fn linkSystemLibrary2( |
| 864 | self: *Compile, |
| 865 | name: []const u8, |
| 866 | options: LinkSystemLibraryOptions, |
| 867 | ) void { |
| 903 | 868 | const b = self.step.owner; |
| 904 | 869 | if (isLibCLibrary(name)) { |
| 905 | 870 | self.linkLibC(); |
| ... | ... | @@ -913,9 +878,11 @@ fn linkSystemLibraryInner(self: *Compile, name: []const u8, opts: struct { |
| 913 | 878 | self.link_objects.append(.{ |
| 914 | 879 | .system_lib = .{ |
| 915 | 880 | .name = b.dupe(name), |
| 916 | | .needed = opts.needed, |
| 917 | | .weak = opts.weak, |
| 918 | | .use_pkg_config = .yes, |
| 881 | .needed = options.needed, |
| 882 | .weak = options.weak, |
| 883 | .use_pkg_config = options.use_pkg_config, |
| 884 | .preferred_link_mode = options.preferred_link_mode, |
| 885 | .search_strategy = options.search_strategy, |
| 919 | 886 | }, |
| 920 | 887 | }) catch @panic("OOM"); |
| 921 | 888 | } |
| ... | ... | @@ -1385,6 +1352,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1385 | 1352 | try transitive_deps.add(self.link_objects.items); |
| 1386 | 1353 | |
| 1387 | 1354 | var prev_has_cflags = false; |
| 1355 | var prev_search_strategy: SystemLib.SearchStrategy = .paths_first; |
| 1356 | var prev_preferred_link_mode: std.builtin.LinkMode = .Dynamic; |
| 1388 | 1357 | |
| 1389 | 1358 | for (transitive_deps.link_objects.items) |link_object| { |
| 1390 | 1359 | switch (link_object) { |
| ... | ... | @@ -1420,6 +1389,28 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1420 | 1389 | }, |
| 1421 | 1390 | |
| 1422 | 1391 | .system_lib => |system_lib| { |
| 1392 | if ((system_lib.search_strategy != prev_search_strategy or |
| 1393 | system_lib.preferred_link_mode != prev_preferred_link_mode) and |
| 1394 | self.linkage != .static) |
| 1395 | { |
| 1396 | switch (system_lib.search_strategy) { |
| 1397 | .no_fallback => switch (system_lib.preferred_link_mode) { |
| 1398 | .Dynamic => try zig_args.append("-search_dylibs_only"), |
| 1399 | .Static => try zig_args.append("-search_static_only"), |
| 1400 | }, |
| 1401 | .paths_first => switch (system_lib.preferred_link_mode) { |
| 1402 | .Dynamic => try zig_args.append("-search_paths_first"), |
| 1403 | .Static => try zig_args.append("-search_paths_first_static"), |
| 1404 | }, |
| 1405 | .mode_first => switch (system_lib.preferred_link_mode) { |
| 1406 | .Dynamic => try zig_args.append("-search_dylibs_first"), |
| 1407 | .Static => try zig_args.append("-search_static_first"), |
| 1408 | }, |
| 1409 | } |
| 1410 | prev_search_strategy = system_lib.search_strategy; |
| 1411 | prev_preferred_link_mode = system_lib.preferred_link_mode; |
| 1412 | } |
| 1413 | |
| 1423 | 1414 | const prefix: []const u8 = prefix: { |
| 1424 | 1415 | if (system_lib.needed) break :prefix "-needed-l"; |
| 1425 | 1416 | if (system_lib.weak) break :prefix "-weak-l"; |
| ... | ... | @@ -1662,10 +1653,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1662 | 1653 | const size = try std.fmt.allocPrint(b.allocator, "{x}", .{pagezero_size}); |
| 1663 | 1654 | try zig_args.appendSlice(&[_][]const u8{ "-pagezero_size", size }); |
| 1664 | 1655 | } |
| 1665 | | if (self.search_strategy) |strat| switch (strat) { |
| 1666 | | .paths_first => try zig_args.append("-search_paths_first"), |
| 1667 | | .dylibs_first => try zig_args.append("-search_dylibs_first"), |
| 1668 | | }; |
| 1669 | 1656 | if (self.headerpad_size) |headerpad_size| { |
| 1670 | 1657 | const size = try std.fmt.allocPrint(b.allocator, "{x}", .{headerpad_size}); |
| 1671 | 1658 | try zig_args.appendSlice(&[_][]const u8{ "-headerpad", size }); |