From 96a703ee6deea1dfbfe300fc997c99c485fa3df8 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Fri, 4 Dec 2020 16:23:21 +0100 Subject: [PATCH] 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 --- src/Compilation.zig | 5 ++++- src/link/MachO.zig | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Compilation.zig b/src/Compilation.zig index 53133a7ab66f5a08f6a8d9114317a48753d9c2d7..7d294ddcda78aab879bf150773d9f25d8db83d0f 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -530,7 +530,10 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { const darwin_options: DarwinOptions = if (build_options.have_llvm and comptime std.Target.current.isDarwin()) outer: { const opts: DarwinOptions = if (use_lld and options.is_native_os and options.target.isDarwin()) inner: { - const syslibroot = try std.zig.system.getSDKPath(arena); + // TODO Revisit this targeting versions lower than macOS 11 when LLVM 12 is out. + // See https://github.com/ziglang/zig/issues/6996 + const at_least_big_sur = options.target.os.getVersionRange().semver.min.major >= 11; + const syslibroot = if (at_least_big_sur) try std.zig.system.getSDKPath(arena) else null; const system_linker_hack = std.os.getenv("ZIG_SYSTEM_LINKER_HACK") != null; break :inner .{ .syslibroot = syslibroot, diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 06730908d2d76a4f0f80492acae0f6c0fe40ced4..258e283135db38071333e155ea177f66eca43c28 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -476,6 +476,8 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { man.hash.addStringSet(self.base.options.system_libs); man.hash.add(allow_shlib_undefined); man.hash.add(self.base.options.bind_global_refs_locally); + man.hash.add(self.base.options.system_linker_hack); + man.hash.addOptionalBytes(self.base.options.syslibroot); // We don't actually care whether it's a cache hit or miss; we just need the digest and the lock. _ = try man.hit(); -- 2.54.0