| ... | ... | @@ -1,7 +1,6 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("../std.zig"); |
| 3 | 3 | const mem = std.mem; |
| 4 | | const log = std.log; |
| 5 | 4 | const fs = std.fs; |
| 6 | 5 | const assert = std.debug.assert; |
| 7 | 6 | const panic = std.debug.panic; |
| ... | ... | @@ -697,7 +696,7 @@ pub fn linkSystemLibraryNeededPkgConfigOnly(self: *CompileStep, lib_name: []cons |
| 697 | 696 | |
| 698 | 697 | /// Run pkg-config for the given library name and parse the output, returning the arguments |
| 699 | 698 | /// that should be passed to zig to link the given library. |
| 700 | | pub fn runPkgConfig(self: *CompileStep, lib_name: []const u8) ![]const []const u8 { |
| 699 | fn runPkgConfig(self: *CompileStep, lib_name: []const u8) ![]const []const u8 { |
| 701 | 700 | const b = self.step.owner; |
| 702 | 701 | const pkg_name = match: { |
| 703 | 702 | // First we have to map the library name to pkg config name. Unfortunately, |
| ... | ... | @@ -783,8 +782,8 @@ pub fn runPkgConfig(self: *CompileStep, lib_name: []const u8) ![]const []const u |
| 783 | 782 | try zig_args.appendSlice(&[_][]const u8{ "-D", macro }); |
| 784 | 783 | } else if (mem.startsWith(u8, tok, "-D")) { |
| 785 | 784 | try zig_args.append(tok); |
| 786 | | } else if (b.verbose) { |
| 787 | | log.warn("Ignoring pkg-config flag '{s}'", .{tok}); |
| 785 | } else if (b.debug_pkg_config) { |
| 786 | return self.step.fail("unknown pkg-config flag '{s}'", .{tok}); |
| 788 | 787 | } |
| 789 | 788 | } |
| 790 | 789 | |
| ... | ... | @@ -1190,8 +1189,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1190 | 1189 | const self = @fieldParentPtr(CompileStep, "step", step); |
| 1191 | 1190 | |
| 1192 | 1191 | if (self.root_src == null and self.link_objects.items.len == 0) { |
| 1193 | | log.err("{s}: linker needs 1 or more objects to link", .{self.step.name}); |
| 1194 | | return error.NeedAnObject; |
| 1192 | return step.fail("the linker needs one or more objects to link", .{}); |
| 1195 | 1193 | } |
| 1196 | 1194 | |
| 1197 | 1195 | var zig_args = ArrayList([]const u8).init(b.allocator); |
| ... | ... | @@ -1280,10 +1278,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1280 | 1278 | .system_lib => |system_lib| { |
| 1281 | 1279 | const prefix: []const u8 = prefix: { |
| 1282 | 1280 | if (system_lib.needed) break :prefix "-needed-l"; |
| 1283 | | if (system_lib.weak) { |
| 1284 | | if (self.target.isDarwin()) break :prefix "-weak-l"; |
| 1285 | | log.warn("Weak library import used for a non-darwin target, this will be converted to normally library import `-lname`", .{}); |
| 1286 | | } |
| 1281 | if (system_lib.weak) break :prefix "-weak-l"; |
| 1287 | 1282 | break :prefix "-l"; |
| 1288 | 1283 | }; |
| 1289 | 1284 | switch (system_lib.use_pkg_config) { |
| ... | ... | @@ -1774,18 +1769,18 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1774 | 1769 | try zig_args.append(c_macro); |
| 1775 | 1770 | } |
| 1776 | 1771 | |
| 1777 | | if (self.target.isDarwin()) { |
| 1778 | | for (self.framework_dirs.items) |dir| { |
| 1779 | | if (b.sysroot != null) { |
| 1780 | | try zig_args.append("-iframeworkwithsysroot"); |
| 1781 | | } else { |
| 1782 | | try zig_args.append("-iframework"); |
| 1783 | | } |
| 1784 | | try zig_args.append(dir); |
| 1785 | | try zig_args.append("-F"); |
| 1786 | | try zig_args.append(dir); |
| 1772 | for (self.framework_dirs.items) |dir| { |
| 1773 | if (b.sysroot != null) { |
| 1774 | try zig_args.append("-iframeworkwithsysroot"); |
| 1775 | } else { |
| 1776 | try zig_args.append("-iframework"); |
| 1787 | 1777 | } |
| 1778 | try zig_args.append(dir); |
| 1779 | try zig_args.append("-F"); |
| 1780 | try zig_args.append(dir); |
| 1781 | } |
| 1788 | 1782 | |
| 1783 | { |
| 1789 | 1784 | var it = self.frameworks.iterator(); |
| 1790 | 1785 | while (it.next()) |entry| { |
| 1791 | 1786 | const name = entry.key_ptr.*; |
| ... | ... | @@ -1799,14 +1794,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1799 | 1794 | } |
| 1800 | 1795 | try zig_args.append(name); |
| 1801 | 1796 | } |
| 1802 | | } else { |
| 1803 | | if (self.framework_dirs.items.len > 0) { |
| 1804 | | log.info("Framework directories have been added for a non-darwin target, this will have no affect on the build", .{}); |
| 1805 | | } |
| 1806 | | |
| 1807 | | if (self.frameworks.count() > 0) { |
| 1808 | | log.info("Frameworks have been added for a non-darwin target, this will have no affect on the build", .{}); |
| 1809 | | } |
| 1810 | 1797 | } |
| 1811 | 1798 | |
| 1812 | 1799 | if (b.sysroot) |sysroot| { |
| ... | ... | @@ -1970,8 +1957,15 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1970 | 1957 | } |
| 1971 | 1958 | } |
| 1972 | 1959 | |
| 1973 | | if (self.kind == .lib and self.linkage != null and self.linkage.? == .dynamic and self.version != null and self.target.wantSharedLibSymLinks()) { |
| 1974 | | try doAtomicSymLinks(b.allocator, self.getOutputSource().getPath(b), self.major_only_filename.?, self.name_only_filename.?); |
| 1960 | if (self.kind == .lib and self.linkage != null and self.linkage.? == .dynamic and |
| 1961 | self.version != null and self.target.wantSharedLibSymLinks()) |
| 1962 | { |
| 1963 | try doAtomicSymLinks( |
| 1964 | step, |
| 1965 | self.getOutputSource().getPath(b), |
| 1966 | self.major_only_filename.?, |
| 1967 | self.name_only_filename.?, |
| 1968 | ); |
| 1975 | 1969 | } |
| 1976 | 1970 | } |
| 1977 | 1971 | |
| ... | ... | @@ -2013,30 +2007,27 @@ fn findVcpkgRoot(allocator: Allocator) !?[]const u8 { |
| 2013 | 2007 | } |
| 2014 | 2008 | |
| 2015 | 2009 | pub fn doAtomicSymLinks( |
| 2016 | | allocator: Allocator, |
| 2010 | step: *Step, |
| 2017 | 2011 | output_path: []const u8, |
| 2018 | 2012 | filename_major_only: []const u8, |
| 2019 | 2013 | filename_name_only: []const u8, |
| 2020 | 2014 | ) !void { |
| 2015 | const arena = step.owner.allocator; |
| 2021 | 2016 | const out_dir = fs.path.dirname(output_path) orelse "."; |
| 2022 | 2017 | const out_basename = fs.path.basename(output_path); |
| 2023 | 2018 | // sym link for libfoo.so.1 to libfoo.so.1.2.3 |
| 2024 | | const major_only_path = try fs.path.join( |
| 2025 | | allocator, |
| 2026 | | &[_][]const u8{ out_dir, filename_major_only }, |
| 2027 | | ); |
| 2028 | | fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| { |
| 2029 | | log.err("Unable to symlink {s} -> {s}", .{ major_only_path, out_basename }); |
| 2030 | | return err; |
| 2019 | const major_only_path = try fs.path.join(arena, &.{ out_dir, filename_major_only }); |
| 2020 | fs.atomicSymLink(arena, out_basename, major_only_path) catch |err| { |
| 2021 | return step.fail("unable to symlink {s} -> {s}: {s}", .{ |
| 2022 | major_only_path, out_basename, @errorName(err), |
| 2023 | }); |
| 2031 | 2024 | }; |
| 2032 | 2025 | // sym link for libfoo.so to libfoo.so.1 |
| 2033 | | const name_only_path = try fs.path.join( |
| 2034 | | allocator, |
| 2035 | | &[_][]const u8{ out_dir, filename_name_only }, |
| 2036 | | ); |
| 2037 | | fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| { |
| 2038 | | log.err("Unable to symlink {s} -> {s}", .{ name_only_path, filename_major_only }); |
| 2039 | | return err; |
| 2026 | const name_only_path = try fs.path.join(arena, &.{ out_dir, filename_name_only }); |
| 2027 | fs.atomicSymLink(arena, filename_major_only, name_only_path) catch |err| { |
| 2028 | return step.fail("Unable to symlink {s} -> {s}: {s}", .{ |
| 2029 | name_only_path, filename_major_only, @errorName(err), |
| 2030 | }); |
| 2040 | 2031 | }; |
| 2041 | 2032 | } |
| 2042 | 2033 | |