aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2020-11-02 09:04:18 +0100
committerJakub Konka <kubkon@jakubkonka.com>2020-11-02 17:06:09 +0100
commit317c555a5cdc52612e998d8b4bcbaf730be1a6f1 (patch)
tree0c414e11cfb2de91e0c7ee6485d784f61dc4330a /src/Compilation.zig
parent909aae8153e7ac71197bc9f864e4ceb2793317f2 (diff)
downloadzig-317c555a5cdc52612e998d8b4bcbaf730be1a6f1.tar.gz
zig-317c555a5cdc52612e998d8b4bcbaf730be1a6f1.zip
Fix linking issues on BigSur
This commit fixes linking issue on macOS 11 BigSur by appending a prefix path to all lib and framework search paths known as `-syslibroot`. The reason this is needed is that in macOS 11, the system libraries and frameworks are no longer readily available in the filesystem. Instead, the new macOS ships with a built-in dynamic linker cache of all system-provided libraries, and hence, when linking with either `lld.ld64` or `ld64`, it is required to pass in `-syslibroot [dir]`. The latter can usually be obtained by invoking `xcrun --show-sdk-path`. With this commit, Zig will do this automatically when compiling natively on macOS. However, it also provides a flag `-syslibroot` which can be used to overwrite the automtically populated value. To summarise, with this change, the user of Zig is not required to generate and append their own syslibroot path. Standard invocations such as `zig build-exe hello.zig` or `zig build` for projects will work out of the box. The only missing bit is `zig cc` and `zig c++` since the addition of the `-syslibroot` option would be a mismatch between the values provided by `clang` itself and Zig's wrapper.
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 472f367b91..872eb1a78b 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -333,6 +333,7 @@ pub const InitOptions = struct {
keep_source_files_loaded: bool = false,
clang_argv: []const []const u8 = &[0][]const u8{},
lld_argv: []const []const u8 = &[0][]const u8{},
+ syslibroot: ?[]const u8 = null,
lib_dirs: []const []const u8 = &[0][]const u8{},
rpath_list: []const []const u8 = &[0][]const u8{},
c_source_files: []const CSourceFile = &[0]CSourceFile{},
@@ -773,6 +774,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
.frameworks = options.frameworks,
.framework_dirs = options.framework_dirs,
.system_libs = system_libs,
+ .syslibroot = options.syslibroot,
.lib_dirs = options.lib_dirs,
.rpath_list = options.rpath_list,
.strip = strip,