| author | |
| committer | |
| log | 00ceb592ef8d396ec354152c1684321a6c5847e4 |
| tree | c12a7a6cb5421aaa19753d2b2223ef4d057db60f |
| parent | be26c3bf4e4c6a7654ea68e6606c1167ef969a09 |
| parent | 6ecefd590360be0484d766d18a23e19c6c7325e6 |
| signature |
macOS: fix linking issues on BigSur5 files changed, 42 insertions(+), 0 deletions(-)
lib/std/zig/system.zig+2| ... | @@ -17,6 +17,8 @@ const macos = @import("system/macos.zig"); | ... | @@ -17,6 +17,8 @@ const macos = @import("system/macos.zig"); |
| 17 | 17 | ||
| 18 | const is_windows = Target.current.os.tag == .windows; | 18 | const is_windows = Target.current.os.tag == .windows; |
| 19 | 19 | ||
| 20 | pub const getSDKPath = macos.getSDKPath; | ||
| 21 | |||
| 20 | pub const NativePaths = struct { | 22 | pub const NativePaths = struct { |
| 21 | include_dirs: ArrayList([:0]u8), | 23 | include_dirs: ArrayList([:0]u8), |
| 22 | lib_dirs: ArrayList([:0]u8), | 24 | lib_dirs: ArrayList([:0]u8), |
lib/std/zig/system/macos.zig+24| ... | @@ -4,6 +4,8 @@ | ... | @@ -4,6 +4,8 @@ |
| 4 | // The MIT license requires this copyright notice to be included in all copies | 4 | // The MIT license requires this copyright notice to be included in all copies |
| 5 | // and substantial portions of the software. | 5 | // and substantial portions of the software. |
| 6 | const std = @import("std"); | 6 | const std = @import("std"); |
| 7 | const assert = std.debug.assert; | ||
| 8 | const mem = std.mem; | ||
| 7 | 9 | ||
| 8 | pub fn version_from_build(build: []const u8) !std.builtin.Version { | 10 | pub fn version_from_build(build: []const u8) !std.builtin.Version { |
| 9 | // build format: | 11 | // build format: |
| ... | @@ -452,3 +454,25 @@ test "version_from_build" { | ... | @@ -452,3 +454,25 @@ test "version_from_build" { |
| 452 | std.testing.expect(std.mem.eql(u8, sver, pair[1])); | 454 | std.testing.expect(std.mem.eql(u8, sver, pair[1])); |
| 453 | } | 455 | } |
| 454 | } | 456 | } |
| 457 | |||
| 458 | /// Detect SDK path on Darwin. | ||
| 459 | /// Calls `xcrun --show-sdk-path` which result can be used to specify | ||
| 460 | /// `-syslibroot` param of the linker. | ||
| 461 | /// The caller needs to free the resulting path slice. | ||
| 462 | pub fn getSDKPath(allocator: *mem.Allocator) ![]u8 { | ||
| 463 | assert(std.Target.current.isDarwin()); | ||
| 464 | const argv = &[_][]const u8{ "xcrun", "--show-sdk-path" }; | ||
| 465 | const result = try std.ChildProcess.exec(.{ .allocator = allocator, .argv = argv }); | ||
| 466 | defer { | ||
| 467 | allocator.free(result.stderr); | ||
| 468 | allocator.free(result.stdout); | ||
| 469 | } | ||
| 470 | if (result.stderr.len != 0) { | ||
| 471 | std.log.err("unexpected 'xcrun --show-sdk-path' stderr: {}", .{result.stderr}); | ||
| 472 | } | ||
| 473 | if (result.term.Exited != 0) { | ||
| 474 | return error.ProcessTerminated; | ||
| 475 | } | ||
| 476 | const syslibroot = mem.trimRight(u8, result.stdout, "\r\n"); | ||
| 477 | return mem.dupe(allocator, u8, syslibroot); | ||
| 478 | } |
src/Compilation.zig+9| ... | @@ -472,6 +472,14 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -472,6 +472,14 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 472 | break :blk false; | 472 | break :blk false; |
| 473 | }; | 473 | }; |
| 474 | 474 | ||
| 475 | const syslibroot = if (build_options.have_llvm and comptime std.Target.current.isDarwin()) outer: { | ||
| 476 | const path = if (use_lld and options.is_native_os and options.target.isDarwin()) inner: { | ||
| 477 | const syslibroot_path = try std.zig.system.getSDKPath(arena); | ||
| 478 | break :inner syslibroot_path; | ||
| 479 | } else null; | ||
| 480 | break :outer path; | ||
| 481 | } else null; | ||
| 482 | |||
| 475 | const link_libc = options.link_libc or target_util.osRequiresLibC(options.target); | 483 | const link_libc = options.link_libc or target_util.osRequiresLibC(options.target); |
| 476 | 484 | ||
| 477 | const must_dynamic_link = dl: { | 485 | const must_dynamic_link = dl: { |
| ... | @@ -773,6 +781,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -773,6 +781,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 773 | .frameworks = options.frameworks, | 781 | .frameworks = options.frameworks, |
| 774 | .framework_dirs = options.framework_dirs, | 782 | .framework_dirs = options.framework_dirs, |
| 775 | .system_libs = system_libs, | 783 | .system_libs = system_libs, |
| 784 | .syslibroot = syslibroot, | ||
| 776 | .lib_dirs = options.lib_dirs, | 785 | .lib_dirs = options.lib_dirs, |
| 777 | .rpath_list = options.rpath_list, | 786 | .rpath_list = options.rpath_list, |
| 778 | .strip = strip, | 787 | .strip = strip, |
src/link.zig+2| ... | @@ -88,6 +88,8 @@ pub const Options = struct { | ... | @@ -88,6 +88,8 @@ pub const Options = struct { |
| 88 | llvm_cpu_features: ?[*:0]const u8, | 88 | llvm_cpu_features: ?[*:0]const u8, |
| 89 | /// Extra args passed directly to LLD. Ignored when not linking with LLD. | 89 | /// Extra args passed directly to LLD. Ignored when not linking with LLD. |
| 90 | extra_lld_args: []const []const u8, | 90 | extra_lld_args: []const []const u8, |
| 91 | /// Darwin-only. Set the root path to the system libraries and frameworks. | ||
| 92 | syslibroot: ?[]const u8, | ||
| 91 | 93 | ||
| 92 | objects: []const []const u8, | 94 | objects: []const []const u8, |
| 93 | framework_dirs: []const []const u8, | 95 | framework_dirs: []const []const u8, |
src/link/MachO.zig+5| ... | @@ -628,6 +628,11 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { | ... | @@ -628,6 +628,11 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { |
| 628 | } | 628 | } |
| 629 | } | 629 | } |
| 630 | 630 | ||
| 631 | if (self.base.options.syslibroot) |dir| { | ||
| 632 | try argv.append("-syslibroot"); | ||
| 633 | try argv.append(dir); | ||
| 634 | } | ||
| 635 | |||
| 631 | for (self.base.options.lib_dirs) |lib_dir| { | 636 | for (self.base.options.lib_dirs) |lib_dir| { |
| 632 | try argv.append("-L"); | 637 | try argv.append("-L"); |
| 633 | try argv.append(lib_dir); | 638 | try argv.append(lib_dir); |