feature. See also
. The project being documented here (as the example) is the Zig library itself.
LibCDirs.detect
pub fn detect(
arena: Allocator,
io: Io,
zig_lib_dir: Path,
target: *const std.Target,
is_native_abi: bool,
link_libc: bool,
libc_installation: ?*const LibCInstallation,
environ_map: *const std.process.Environ.Map,
) LibCInstallation.FindError!LibCDirs
File
Code
pub fn detect(
arena: Allocator,
io: Io,
zig_lib_dir: Path,
target: *const std.Target,
is_native_abi: bool,
link_libc: bool,
libc_installation: ?*const LibCInstallation,
environ_map: *const std.process.Environ.Map,
) LibCInstallation.FindError!LibCDirs {
if (!link_libc) {
return .{
.libc_include_dir_list = &[0][]u8{},
.libc_installation = null,
.libc_framework_dir_list = &.{},
.sysroot = null,
.darwin_sdk_layout = null,
};
}
if (libc_installation) |lci| {
return detectFromInstallation(arena, target, lci);
}
// using the system libc installation.
if (is_native_abi and !target.isMinGW()) {
const libc = try arena.create(LibCInstallation);
libc.* = LibCInstallation.findNative(arena, io, .{
.target = target,
.environ_map = environ_map,
}) catch |err| switch (err) {
error.CCompilerExitCode,
error.CCompilerCrashed,
error.CCompilerCannotFindHeaders,
error.UnableToSpawnCCompiler,
error.DarwinSdkNotFound,
=> |e| {
// however, it is not installed. So we must rely on our bundled
// libc files.
if (std.zig.target.canBuildLibC(target)) {
return detectFromBuilding(arena, zig_lib_dir, target);
}
return e;
},
else => |e| return e,
};
return detectFromInstallation(arena, target, libc);
}
// default if possible.
if (std.zig.target.canBuildLibC(target)) {
return detectFromBuilding(arena, zig_lib_dir, target);
}
// native abi, fall back to using the system libc installation.
// On windows, instead of the native (mingw) abi, we want to check
// for the MSVC abi as a fallback.
const use_system_abi = if (builtin.os.tag == .windows)
target.abi == .msvc or target.abi == .itanium
else
is_native_abi;
if (use_system_abi) {
const libc = try arena.create(LibCInstallation);
libc.* = try LibCInstallation.findNative(arena, io, .{
.verbose = true,
.target = target,
.environ_map = environ_map,
});
return detectFromInstallation(arena, target, libc);
}
return .{
.libc_include_dir_list = &.{},
.libc_installation = null,
.libc_framework_dir_list = &.{},
.sysroot = null,
.darwin_sdk_layout = null,
};
}