authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-05-10 21:29:20+02:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-05-11 21:30:07+02:00
log5ac91794cce8bd53916a378815be01e4365d53d9
treee8c8e858a3d72d8aa422722a99ea96c7eda06a51
parentace5714551da16b541d8015e97a2fe32a7a1cf76
signaturelock-open Commit is signed but in an unrecognized format.

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.

1 files changed, 8 insertions(+), 8 deletions(-)

src/Compilation.zig+8-8
......@@ -848,7 +848,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
848848 arena,
849849 options.zig_lib_directory.path.?,
850850 options.target,
851 options.is_native_os,
851 options.is_native_abi,
852852 link_libc,
853853 options.libc_installation,
854854 );
......@@ -2885,7 +2885,7 @@ fn detectLibCIncludeDirs(
28852885 arena: *Allocator,
28862886 zig_lib_dir: []const u8,
28872887 target: Target,
2888 is_native_os: bool,
2888 is_native_abi: bool,
28892889 link_libc: bool,
28902890 libc_installation: ?*const LibCInstallation,
28912891) !LibCDirs {
......@@ -2900,6 +2900,12 @@ fn detectLibCIncludeDirs(
29002900 return detectLibCFromLibCInstallation(arena, target, lci);
29012901 }
29022902
2903 if (is_native_abi) {
2904 const libc = try arena.create(LibCInstallation);
2905 libc.* = try LibCInstallation.findNative(.{ .allocator = arena });
2906 return detectLibCFromLibCInstallation(arena, target, libc);
2907 }
2908
29032909 if (target_util.canBuildLibC(target)) {
29042910 const generic_name = target_util.libCGenericName(target);
29052911 // Some architectures are handled by the same set of headers.
......@@ -2950,12 +2956,6 @@ fn detectLibCIncludeDirs(
29502956 };
29512957 }
29522958
2953 if (is_native_os) {
2954 const libc = try arena.create(LibCInstallation);
2955 libc.* = try LibCInstallation.findNative(.{ .allocator = arena });
2956 return detectLibCFromLibCInstallation(arena, target, libc);
2957 }
2958
29592959 return LibCDirs{
29602960 .libc_include_dir_list = &[0][]u8{},
29612961 .libc_installation = null,