Zig 0.17.0-dev (Split by item)

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 library itself.

find

Find path and version of Windows 10 SDK and Windows 8.1 SDK, and find path to MSVC's lib/ directory. Caller owns the result's fields. Returns memory allocated by gpa

WindowsSdk.find
pub fn find(
    gpa: Allocator,
    io: Io,
    arch: std.Target.Cpu.Arch,
    environ_map: *const Environ.Map,
) error

File

lib/std/zig/WindowsSdk.zig:29

Code

pub fn find(
    gpa: Allocator,
    io: Io,
    arch: std.Target.Cpu.Arch,
    environ_map: *const Environ.Map,
) error{ OutOfMemory, NotFound, PathTooLong }!WindowsSdk {
    if (builtin.os.tag != .windows) return error.NotFound;

    var registry: Registry = .{};
    defer registry.deinit();

    // If this key doesn't exist, neither the Win 8 SDK nor the Win 10 SDK is installed
    const roots_key = registry.openSoftwareKey(.{ .root = .local_machine, .wow64 = .wow64_32 }, L(windows_kits_reg_key)) catch |err| switch (err) {
        error.KeyNotFound => return error.NotFound,
    };
    defer roots_key.close();

    const windows10sdk = Installation.find(gpa, io, &registry, roots_key, L("KitsRoot10"), "", L("v10.0")) catch |err| switch (err) {
        error.InstallationNotFound => null,
        error.PathTooLong => null,
        error.VersionTooLong => null,
        error.OutOfMemory => |e| return e,
    };
    errdefer if (windows10sdk) |*w| w.free(gpa);

    const windows81sdk = Installation.find(gpa, io, &registry, roots_key, L("KitsRoot81"), "winver", L("v8.1")) catch |err| switch (err) {
        error.InstallationNotFound => null,
        error.PathTooLong => null,
        error.VersionTooLong => null,
        error.OutOfMemory => |e| return e,
    };
    errdefer if (windows81sdk) |*w| w.free(gpa);

    const msvc_lib_dir: ?[]const u8 = MsvcLibDir.find(gpa, io, &registry, arch, environ_map) catch |err| switch (err) {
        error.MsvcLibDirNotFound => null,
        error.OutOfMemory => |e| return e,
    };
    errdefer gpa.free(msvc_lib_dir);

    return .{
        .windows10sdk = windows10sdk,
        .windows81sdk = windows81sdk,
        .msvc_lib_dir = msvc_lib_dir,
    };
}