A pretty printer for zig
zig
1const std = @import("std");
2
3pub fn build(b: *std.Build) void {
4 const target = b.standardTargetOptions(.{});
5 const optimize = b.standardOptimizeOption(.{});
6
7 const pretty = b.addModule("pretty", .{
8 .root_source_file = b.path("pretty.zig"),
9 .target = target,
10 .optimize = optimize,
11 });
12
13 const options = b.addOptions();
14
15 const indent_width = b.option(u32, "indent-width", "Set indent width") orelse 2;
16 options.addOption(u32, "indent_width", indent_width);
17
18 const skip_root_type_name = b.option(bool, "skip-root-type-name", "Don't show the type name of the first element") orelse false;
19 options.addOption(bool, "skip_root_type_name", skip_root_type_name);
20
21 const example = b.addExecutable(.{
22 .root_module = b.createModule(.{
23 .root_source_file = b.path("example/main.zig"),
24 .target = target,
25 .optimize = optimize,
26 .imports = &.{
27 .{ .name = "pretty", .module = pretty },
28 .{ .name = "build-options", .module = options.createModule() },
29 },
30 }),
31 .name = "pretty-example",
32 });
33 b.installArtifact(example);
34
35 const run_example = b.addRunArtifact(example);
36 run_example.step.dependOn(b.getInstallStep());
37
38 if (b.args) |args| run_example.addArgs(args);
39
40 const run_step = b.step("example", "Run the example");
41 run_step.dependOn(&run_example.step);
42}