Skip to content
Standard libraryZig 0.17.1Official documentation
Sourcestd/Build/Step/Fmt.zig

Source line 1

This step has two modes:

  • Modify mode: directly modify source files, formatting them in place.
  • Check mode: fail the step if a non-conforming file is found.

Fields

step: Step
paths: []const LazyPath

Intended to be read-only after the Fmt step is created.

exclude_paths: []const LazyPath

Intended to be read-only after the Fmt step is created.

check: bool

std.Build.Step.Fmt.base_tag

constant

Source line 18

Step.Tag

std.Build.Step.Fmt.Configuration

alias

Source line 9

Alias of std.Build.Configuration

std.Build.Step.Fmt.create

function

Source line 27

pub fn create(owner: *std.Build, options: Options) *Fmt

Parameters

owner: *std.Build
options: Options

std.Build.Step.Fmt.Fmt

alias

Source line 4

Alias of std.Build.Step.Fmt

std.Build.Step.Fmt.LazyPath

alias

Source line 8

Alias of std.Build.LazyPath

std.Build.Step.Fmt.Options

container

Source line 20

Fields

paths: []const LazyPath = &.{}
exclude_paths: []const LazyPath = &.{}
check: bool = false

If true, fails the build step when any non-conforming files are encountered.

std.Build.Step.Fmt.std

alias

Source line 6

Alias of std

std.Build.Step.Fmt.Step

alias

Source line 7

Alias of std.Build.Step

Source code

std/Build/Step/Fmt.zig

//! This step has two modes:
//! * Modify mode: directly modify source files, formatting them in place.
//! * Check mode: fail the step if a non-conforming file is found.
const Fmt = @This();

const std = @import("std");
const Step = std.Build.Step;
const LazyPath = std.Build.LazyPath;
const Configuration = std.Build.Configuration;

step: Step,
/// Intended to be read-only after the `Fmt` step is created.
paths: []const LazyPath,
/// Intended to be read-only after the `Fmt` step is created.
exclude_paths: []const LazyPath,
check: bool,

pub const base_tag: Step.Tag = .fmt;

pub const Options = struct {
    paths: []const LazyPath = &.{},
    exclude_paths: []const LazyPath = &.{},
    /// If true, fails the build step when any non-conforming files are encountered.
    check: bool = false,
};

pub fn create(owner: *std.Build, options: Options) *Fmt {
    const graph = owner.graph;
    const fmt = graph.create(Fmt);

    fmt.* = .{
        .step = .init(.{
            .tag = base_tag,
            .name = if (options.check) "zig fmt --check" else "zig fmt",
            .owner = owner,
        }),
        .paths = LazyPath.dupeList(options.paths, graph),
        .exclude_paths = LazyPath.dupeList(options.exclude_paths, graph),
        .check = options.check,
    };

    for (options.paths) |lp| lp.addStepDependencies(&fmt.step);
    for (options.exclude_paths) |lp| lp.addStepDependencies(&fmt.step);

    return fmt;
}