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.

addOutputFileArg2

Provides a file path as a command line argument to the command being run.

For example, a prefix of "-o" and sub_path of "output.txt" will result in the child process seeing something like this: "-ozig-cache/.../output.txt"

The child process will see a single argument, regardless of whether the prefix or sub_path have spaces.

The returned std.Build.LazyPath can be used as inputs to other APIs throughout the build system.

Related:

Run.addOutputFileArg2
pub fn addOutputFileArg2(
    run: *Run,
    /// The name of the generated output file which may have zero or more path
    /// components.
    ///
    /// Asserted to be non-empty.
    sub_path: []const u8,
    options: PathArgOptions,
) std.Build.LazyPath

File

Code

pub fn addOutputFileArg2(
    run: *Run,
    /// The name of the generated output file which may have zero or more path
    /// components.
    ///
    /// Asserted to be non-empty.
    sub_path: []const u8,
    options: PathArgOptions,
) std.Build.LazyPath {
    const b = run.step.owner;
    const graph = b.graph;
    const arena = graph.arena;
    assert(sub_path.len != 0);

    const output = graph.create(Output);
    output.* = .{
        .prefix = graph.dupeString(options.prefix),
        .basename = graph.dupeString(sub_path),
        .suffix = graph.dupeString(options.suffix),
        .generated_file = graph.addGeneratedFile(&run.step),
        .make_absolute = options.make_absolute,
    };
    run.argv.append(arena, .{ .output_file = output }) catch @panic("OOM");

    if (run.rename_step_with_output_arg) {
        run.setName(b.fmt("{s} ({s})", .{ run.step.name, sub_path }));
    }

    return .{ .generated = .{ .index = output.generated_file } };
}