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

init

Public Function
std.zig.Directories.init
pub fn init(arena: Allocator, io: Io, options: InitOptions) Directories

Uses std.process.fatal on error conditions.

Params

File

zig.zig:1413
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
    pub fn init(arena: Allocator, io: Io, options: InitOptions) Directories {
        const wasi = builtin.target.os.tag == .wasi;
        const cwd = options.cwd;

        const zig_lib: Cache.Directory = d: {
            if (options.override_zig_lib) |path| break :d openUnresolved(arena, io, cwd, path, .@"zig lib");
            if (wasi) break :d getPreopen(options.preopens, "/lib");
            break :d findZigLibDirFromSelfExe(arena, io, cwd, options.self_exe_path) catch |err| {
                fatal("unable to find zig installation directory from executable path {q}: {t}", .{
                    options.self_exe_path, err,
                });
            };
        };
        const build_root: Cache.Directory = if (options.build_root) |s|
            openUnresolved(arena, io, cwd, s, .@"build root")
        else
            .cwd();

        const global_cache: Cache.Directory = d: {
            if (options.override_global_cache) |path| break :d openUnresolved(arena, io, cwd, path, .@"global cache");
            if (wasi) break :d getPreopen(options.preopens, "/cache");
            const path = resolveGlobalCacheDir(arena, options.environ_map) catch |err| {
                fatal("unable to resolve zig cache directory: {t}", .{err});
            };
            break :d openUnresolved(arena, io, cwd, path, .@"global cache");
        };

        const local_cache = getLocalCacheDirectory(arena, io, cwd, global_cache, options.local_cache_strat);

        if (mem.eql(u8, zig_lib.path orelse "", global_cache.path orelse "")) {
            fatal("zig lib directory '{f}' cannot be equal to global cache directory '{f}'", .{ zig_lib, global_cache });
        }
        if (mem.eql(u8, zig_lib.path orelse "", local_cache.path orelse "")) {
            fatal("zig lib directory '{f}' cannot be equal to local cache directory '{f}'", .{ zig_lib, local_cache });
        }

        return .{
            .cwd = cwd,
            .zig_lib = zig_lib,
            .global_cache = global_cache,
            .local_cache = local_cache,
            .build_root = build_root,
        };
    }