| ... | @@ -951,6 +951,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -951,6 +951,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 951 | options.target, | 951 | options.target, |
| 952 | options.is_native_abi, | 952 | options.is_native_abi, |
| 953 | link_libc, | 953 | link_libc, |
| | 954 | options.system_libs.len != 0, |
| 954 | options.libc_installation, | 955 | options.libc_installation, |
| 955 | ); | 956 | ); |
| 956 | | 957 | |
| ... | @@ -3129,6 +3130,7 @@ fn detectLibCIncludeDirs( | ... | @@ -3129,6 +3130,7 @@ fn detectLibCIncludeDirs( |
| 3129 | target: Target, | 3130 | target: Target, |
| 3130 | is_native_abi: bool, | 3131 | is_native_abi: bool, |
| 3131 | link_libc: bool, | 3132 | link_libc: bool, |
| | 3133 | link_system_libs: bool, |
| 3132 | libc_installation: ?*const LibCInstallation, | 3134 | libc_installation: ?*const LibCInstallation, |
| 3133 | ) !LibCDirs { | 3135 | ) !LibCDirs { |
| 3134 | if (!link_libc) { | 3136 | if (!link_libc) { |
| ... | @@ -3142,12 +3144,16 @@ fn detectLibCIncludeDirs( | ... | @@ -3142,12 +3144,16 @@ fn detectLibCIncludeDirs( |
| 3142 | return detectLibCFromLibCInstallation(arena, target, lci); | 3144 | return detectLibCFromLibCInstallation(arena, target, lci); |
| 3143 | } | 3145 | } |
| 3144 | | 3146 | |
| 3145 | if (is_native_abi) { | 3147 | // If linking system libraries and targeting the native abi, default to |
| | 3148 | // using the system libc installation. |
| | 3149 | if (link_system_libs and is_native_abi) { |
| 3146 | const libc = try arena.create(LibCInstallation); | 3150 | const libc = try arena.create(LibCInstallation); |
| 3147 | libc.* = try LibCInstallation.findNative(.{ .allocator = arena, .verbose = true }); | 3151 | libc.* = try LibCInstallation.findNative(.{ .allocator = arena, .verbose = true }); |
| 3148 | return detectLibCFromLibCInstallation(arena, target, libc); | 3152 | return detectLibCFromLibCInstallation(arena, target, libc); |
| 3149 | } | 3153 | } |
| 3150 | | 3154 | |
| | 3155 | // If not linking system libraries, build and provide our own libc by |
| | 3156 | // default if possible. |
| 3151 | if (target_util.canBuildLibC(target)) { | 3157 | if (target_util.canBuildLibC(target)) { |
| 3152 | const generic_name = target_util.libCGenericName(target); | 3158 | const generic_name = target_util.libCGenericName(target); |
| 3153 | // Some architectures are handled by the same set of headers. | 3159 | // Some architectures are handled by the same set of headers. |
| ... | @@ -3198,6 +3204,14 @@ fn detectLibCIncludeDirs( | ... | @@ -3198,6 +3204,14 @@ fn detectLibCIncludeDirs( |
| 3198 | }; | 3204 | }; |
| 3199 | } | 3205 | } |
| 3200 | | 3206 | |
| | 3207 | // If zig can't build the libc for the target and we are targeting the |
| | 3208 | // native abi, fall back to using the system libc installation. |
| | 3209 | if (is_native_abi) { |
| | 3210 | const libc = try arena.create(LibCInstallation); |
| | 3211 | libc.* = try LibCInstallation.findNative(.{ .allocator = arena, .verbose = true }); |
| | 3212 | return detectLibCFromLibCInstallation(arena, target, libc); |
| | 3213 | } |
| | 3214 | |
| 3201 | return LibCDirs{ | 3215 | return LibCDirs{ |
| 3202 | .libc_include_dir_list = &[0][]u8{}, | 3216 | .libc_include_dir_list = &[0][]u8{}, |
| 3203 | .libc_installation = null, | 3217 | .libc_installation = null, |