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.

rebuildTestsWorkerRunFallible

Fuzz.rebuildTestsWorkerRunFallible
fn rebuildTestsWorkerRunFallible(
    maker: *Maker,
    run_index: Configuration.Step.Index,
    parent_progress_node: std.Progress.Node,
) !void

File

Code

fn rebuildTestsWorkerRunFallible(
    maker: *Maker,
    run_index: Configuration.Step.Index,
    parent_progress_node: std.Progress.Node,
) !void {
    const graph = maker.graph;
    const io = graph.io;
    const gpa = maker.gpa;
    const conf = &maker.scanned_config.configuration;
    const run = &maker.stepByIndex(run_index).extended.run;
    const conf_run = run_index.ptr(conf).extended.cast(conf, Configuration.Step.Run).?;
    const comp_index = conf_run.producer.value.?;
    const comp_step = maker.stepByIndex(comp_index);
    const comp = &comp_step.extended.compile;
    const conf_comp_step = comp_index.ptr(conf);
    const conf_comp = conf_comp_step.extended.cast(conf, Configuration.Step.Compile).?;
    const root_module = conf_comp.root_module.get(conf);
    const target = root_module.resolved_target.get(conf).?.result.get(conf);

    const prog_node = parent_progress_node.start(conf_comp_step.name.slice(conf), 0);
    defer prog_node.end();

    const result = comp.rebuildInFuzzMode(maker, comp_index, prog_node);

    const show_compile_errors = comp_step.result_error_bundle.errorMessageCount() > 0;
    const show_error_msgs = comp_step.result_error_msgs.items.len > 0;
    const show_stderr = comp_step.result_stderr.len > 0;

    if (show_error_msgs or show_compile_errors or show_stderr) {
        var buf: [256]u8 = undefined;
        const stderr = try io.lockStderr(&buf, graph.stderr_mode);
        defer io.unlockStderr();
        maker.printErrorMessages(comp_index, .{}, stderr.terminal(), .verbose, .indent) catch {};
    }

    const rebuilt_bin_path = result catch |err| switch (err) {
        error.MakeFailed => return,
        else => |other| return other,
    };
    const compile_filename = try std.zig.binNameAlloc(gpa, .{
        .root_name = conf_comp.root_name.slice(conf),
        .cpu_arch = target.flags.cpu_arch.unwrap().?,
        .os_tag = target.flags.os_tag.unwrap().?,
        .ofmt = target.flags.object_format.unwrap().?,
        .abi = target.flags.abi.unwrap().?,
        .output_mode = switch (conf_comp.flags3.kind) {
            .lib => .Lib,
            .obj, .test_obj => .Obj,
            .exe, .@"test" => .Exe,
        },
        .link_mode = conf_comp.flags2.linkage.unwrap(),
        .version = if (conf_comp.version.value) |v|
            std.SemanticVersion.parse(v.slice(conf)) catch unreachable
        else
            null,
    });
    defer gpa.free(compile_filename);

    run.rebuilt_executable = try rebuilt_bin_path.join(gpa, compile_filename);
}