Finds the default, native libc.
pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!LibCInstallation
pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!LibCInstallation {
var self: LibCInstallation = .{};
if (is_darwin and args.target.os.tag.isDarwin()) {
if (!std.zig.system.darwin.isSdkInstalled(gpa, io))
return error.DarwinSdkNotFound;
const sdk = std.zig.system.darwin.getSdk(gpa, io, args.target) orelse
return error.DarwinSdkNotFound;
defer gpa.free(sdk);
self.include_dir = try fs.path.join(gpa, &.{
sdk, "usr/include",
});
self.sys_include_dir = try fs.path.join(gpa, &.{
sdk, "usr/include",
});
return self;
} else if (is_windows) {
const sdk = std.zig.WindowsSdk.find(gpa, io, args.target.cpu.arch, args.environ_map) catch |err| switch (err) {
error.NotFound => return error.WindowsSdkNotFound,
error.PathTooLong => return error.WindowsSdkNotFound,
error.OutOfMemory => |e| return e,
};
defer sdk.free(gpa);
try self.findNativeMsvcIncludeDir(gpa, io, sdk);
try self.findNativeMsvcLibDir(gpa, sdk);
try self.findNativeKernel32LibDir(gpa, io, args, sdk);
try self.findNativeIncludeDirWindows(gpa, io, sdk);
try self.findNativeCrtDirWindows(gpa, io, args.target, sdk);
} else if (is_haiku) {
try self.findNativeIncludeDirPosix(gpa, io, args);
try self.findNativeGccDirPosix(gpa, io, args);
self.crt_dir = try gpa.dupe(u8, "/system/develop/lib");
} else if (is_serenity) {
try self.findNativeIncludeDirPosix(gpa, io, args);
try self.findNativeGccDirPosix(gpa, io, args);
self.crt_dir = try gpa.dupe(u8, "/usr/lib");
} else if (builtin.target.os.tag == .illumos) {
// There is only one libc, and its headers/libraries are always in the same spot.
self.include_dir = try gpa.dupe(u8, "/usr/include");
self.sys_include_dir = try gpa.dupe(u8, "/usr/include");
self.crt_dir = try gpa.dupe(u8, "/usr/lib/64");
} else if (std.process.can_spawn) {
try self.findNativeIncludeDirPosix(gpa, io, args);
switch (builtin.target.os.tag) {
.freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try gpa.dupe(u8, "/usr/lib"),
.linux => try self.findNativeCrtDirPosix(gpa, io, args),
else => {},
}
} else {
return error.LibCRuntimeNotFound;
}
return self;
}