Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function

findNative

Public Function
std.zig.LibCInstallation.findNative
pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!LibCInstallation

Finds the default, native libc.

Params

Errors

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

File

zig/LibCInstallation.zig:181
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
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);
                try self.findNativeGccDirPosix(gpa, io, args);
            },
            else => {},
        }
    } else {
        return error.LibCRuntimeNotFound;
    }
    return self;
}