aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorIsaac Freund <ifreund@ifreund.xyz>2021-05-10 21:29:20 +0200
committerIsaac Freund <ifreund@ifreund.xyz>2021-05-11 21:30:07 +0200
commit5ac91794cce8bd53916a378815be01e4365d53d9 (patch)
treee8c8e858a3d72d8aa422722a99ea96c7eda06a51 /src/Compilation.zig
parentace5714551da16b541d8015e97a2fe32a7a1cf76 (diff)
downloadzig-5ac91794cce8bd53916a378815be01e4365d53d9.tar.gz
zig-5ac91794cce8bd53916a378815be01e4365d53d9.zip
stage2: use system libc when targeting the native OS/ABI
Currently zig will always try to build its own libc and compile against that. This of course makes sense for cross-compilation, but can cause problems when targeting the native OS/ABI. For example, if the system uses a newer glibc version than zig ships zig will fall back to using the newest version it does ship. However this causes linking system libraries to fail as they are built against a different glibc version than the zig code is built against. To remedy this, simply default to linking the system libc when targeting the native OS/ABI.
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 87d4c4c41e..71df776855 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -848,7 +848,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
arena,
options.zig_lib_directory.path.?,
options.target,
- options.is_native_os,
+ options.is_native_abi,
link_libc,
options.libc_installation,
);
@@ -2885,7 +2885,7 @@ fn detectLibCIncludeDirs(
arena: *Allocator,
zig_lib_dir: []const u8,
target: Target,
- is_native_os: bool,
+ is_native_abi: bool,
link_libc: bool,
libc_installation: ?*const LibCInstallation,
) !LibCDirs {
@@ -2900,6 +2900,12 @@ fn detectLibCIncludeDirs(
return detectLibCFromLibCInstallation(arena, target, lci);
}
+ if (is_native_abi) {
+ const libc = try arena.create(LibCInstallation);
+ libc.* = try LibCInstallation.findNative(.{ .allocator = arena });
+ return detectLibCFromLibCInstallation(arena, target, libc);
+ }
+
if (target_util.canBuildLibC(target)) {
const generic_name = target_util.libCGenericName(target);
// Some architectures are handled by the same set of headers.
@@ -2950,12 +2956,6 @@ fn detectLibCIncludeDirs(
};
}
- if (is_native_os) {
- const libc = try arena.create(LibCInstallation);
- libc.* = try LibCInstallation.findNative(.{ .allocator = arena });
- return detectLibCFromLibCInstallation(arena, target, libc);
- }
-
return LibCDirs{
.libc_include_dir_list = &[0][]u8{},
.libc_installation = null,