authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-12-04 16:23:21+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-04 11:37:55-08:00
logc4853ba7ea007f46f8680749c028767287d39f68
tree69485827953cc62d05ed50ff11f4078d8a58d00d
parentb6b7a6401c064582b610b8ca6935a388c3bb3c03

Version-gate appending -syslibroot flag to lld

This commit version-gates appending `-syslibroot` flag to lld. This is predicated upon the fact that for versions of macOS lower than 11, lld would fail to find and link against frameworks with this flag specified. Co-authored-by: Andrew Kelley <andrew@ziglang.org>

2 files changed, 6 insertions(+), 1 deletions(-)

src/Compilation.zig+4-1
...@@ -534,7 +534,10 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -534,7 +534,10 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
534534
535 const darwin_options: DarwinOptions = if (build_options.have_llvm and comptime std.Target.current.isDarwin()) outer: {535 const darwin_options: DarwinOptions = if (build_options.have_llvm and comptime std.Target.current.isDarwin()) outer: {
536 const opts: DarwinOptions = if (use_lld and options.is_native_os and options.target.isDarwin()) inner: {536 const opts: DarwinOptions = if (use_lld and options.is_native_os and options.target.isDarwin()) inner: {
537 const syslibroot = try std.zig.system.getSDKPath(arena);537 // TODO Revisit this targeting versions lower than macOS 11 when LLVM 12 is out.
538 // See https://github.com/ziglang/zig/issues/6996
539 const at_least_big_sur = options.target.os.getVersionRange().semver.min.major >= 11;
540 const syslibroot = if (at_least_big_sur) try std.zig.system.getSDKPath(arena) else null;
538 const system_linker_hack = std.os.getenv("ZIG_SYSTEM_LINKER_HACK") != null;541 const system_linker_hack = std.os.getenv("ZIG_SYSTEM_LINKER_HACK") != null;
539 break :inner .{542 break :inner .{
540 .syslibroot = syslibroot,543 .syslibroot = syslibroot,
src/link/MachO.zig+2
...@@ -421,6 +421,8 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {...@@ -421,6 +421,8 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
421 man.hash.addStringSet(self.base.options.system_libs);421 man.hash.addStringSet(self.base.options.system_libs);
422 man.hash.add(allow_shlib_undefined);422 man.hash.add(allow_shlib_undefined);
423 man.hash.add(self.base.options.bind_global_refs_locally);423 man.hash.add(self.base.options.bind_global_refs_locally);
424 man.hash.add(self.base.options.system_linker_hack);
425 man.hash.addOptionalBytes(self.base.options.syslibroot);
424426
425 // We don't actually care whether it's a cache hit or miss; we just need the digest and the lock.427 // We don't actually care whether it's a cache hit or miss; we just need the digest and the lock.
426 _ = try man.hit();428 _ = try man.hit();