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 {...@@ -848,7 +848,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
848 arena,848 arena,
849 options.zig_lib_directory.path.?,849 options.zig_lib_directory.path.?,
850 options.target,850 options.target,
851 options.is_native_os,851 options.is_native_abi,
852 link_libc,852 link_libc,
853 options.libc_installation,853 options.libc_installation,
854 );854 );
...@@ -2885,7 +2885,7 @@ fn detectLibCIncludeDirs(...@@ -2885,7 +2885,7 @@ fn detectLibCIncludeDirs(
2885 arena: *Allocator,2885 arena: *Allocator,
2886 zig_lib_dir: []const u8,2886 zig_lib_dir: []const u8,
2887 target: Target,2887 target: Target,
2888 is_native_os: bool,2888 is_native_abi: bool,
2889 link_libc: bool,2889 link_libc: bool,
2890 libc_installation: ?*const LibCInstallation,2890 libc_installation: ?*const LibCInstallation,
2891) !LibCDirs {2891) !LibCDirs {
...@@ -2900,6 +2900,12 @@ fn detectLibCIncludeDirs(...@@ -2900,6 +2900,12 @@ fn detectLibCIncludeDirs(
2900 return detectLibCFromLibCInstallation(arena, target, lci);2900 return detectLibCFromLibCInstallation(arena, target, lci);
2901 }2901 }
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
2903 if (target_util.canBuildLibC(target)) {2909 if (target_util.canBuildLibC(target)) {
2904 const generic_name = target_util.libCGenericName(target);2910 const generic_name = target_util.libCGenericName(target);
2905 // Some architectures are handled by the same set of headers.2911 // Some architectures are handled by the same set of headers.
...@@ -2950,12 +2956,6 @@ fn detectLibCIncludeDirs(...@@ -2950,12 +2956,6 @@ fn detectLibCIncludeDirs(
2950 };2956 };
2951 }2957 }
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
2959 return LibCDirs{2959 return LibCDirs{
2960 .libc_include_dir_list = &[0][]u8{},2960 .libc_include_dir_list = &[0][]u8{},
2961 .libc_installation = null,2961 .libc_installation = null,