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.

getPkgs

PkgConfig.getPkgs
fn getPkgs(
    maker: *Maker,
    step: *Step,
    progress_node: std.Progress.Node,
    force: bool,
) RunError!std.zig.PkgConfig

File

lib/compiler/Maker/PkgConfig.zig:73

Code

fn getPkgs(
    maker: *Maker,
    step: *Step,
    progress_node: std.Progress.Node,
    force: bool,
) RunError!std.zig.PkgConfig {
    const graph = maker.graph;
    const io = graph.io;
    const pc = &maker.pkg_config;
    const arena = graph.arena;

    try pc.mutex.lock(io);
    defer pc.mutex.unlock(io);

    if (pc.pkgs) |pkgs| return pkgs;

    const pkg_config_exe = getExe(graph);
    const stdout = try captureChildProcess(maker, step, arena, .{
        .argv = &.{ pkg_config_exe, "--list-all" },
        .progress_node = progress_node,
        .allow_failure = !force,
    });

    var diagnostic: std.zig.PkgConfig.Diagnostic = undefined;
    const result = std.zig.PkgConfig.init(arena, stdout, &diagnostic) catch |err| switch (err) {
        error.InvalidPkgConfigOutput => {
            if (force) return step.fail(maker, "{s}: invalid line({d}): {s}", .{
                pkg_config_exe, diagnostic.invalid_line_index + 1, diagnostic.invalid_line,
            });
            return error.PkgConfigUnavailable;
        },
        else => |e| return e,
    };

    step.clearFailedCommand(maker.gpa);
    pc.pkgs = result;
    return result;
}