Function findNative [src]

Finds the default, native libc.

Prototype

pub fn findNative(args: FindNativeOptions) FindError!LibCInstallation

Parameters

args: FindNativeOptions

Possible Errors

CCompilerCannotFindHeaders
CCompilerCrashed
CCompilerExitCode
DarwinSdkNotFound
FileSystem
LibCKernel32LibNotFound
LibCRuntimeNotFound
LibCStdLibHeaderNotFound
OutOfMemory
UnableToSpawnCCompiler
UnsupportedArchitecture
WindowsSdkNotFound
ZigIsTheCCompiler

Source

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