diff --git a/build.zig b/build.zig index 4f6e477616..6e4e966cbe 100644 --- a/build.zig +++ b/build.zig @@ -315,6 +315,7 @@ const MiniCiStep = struct { // mini CI pipeline. try runSubBuild(step, "fmt", "zig build fmt"); try runSubBuild(step, null, "zig build"); + try checkBuiltinRocFormatting(step); try runSubBuild(step, "snapshot", "zig build snapshot"); try checkSnapshotChanges(step); try runSubBuild(step, "test", "zig build test"); @@ -323,6 +324,41 @@ const MiniCiStep = struct { try runSubBuild(step, "test-cli", "zig build test-cli"); } + fn checkBuiltinRocFormatting(step: *Step) !void { + const b = step.owner; + std.debug.print("---- minici: checking Builtin.roc formatting ----\n", .{}); + + var child_argv = std.ArrayList([]const u8).empty; + defer child_argv.deinit(b.allocator); + + try child_argv.append(b.allocator, "./zig-out/bin/roc"); + try child_argv.append(b.allocator, "fmt"); + try child_argv.append(b.allocator, "--check"); + try child_argv.append(b.allocator, "src/build/roc/Builtin.roc"); + + var child = std.process.Child.init(child_argv.items, b.allocator); + child.stdin_behavior = .Inherit; + child.stdout_behavior = .Inherit; + child.stderr_behavior = .Inherit; + + const term = try child.spawnAndWait(); + + switch (term) { + .Exited => |code| { + if (code != 0) { + return step.fail( + "src/build/roc/Builtin.roc is not formatted. " ++ + "Run 'zig build run -- fmt src/build/roc/Builtin.roc' to format it.", + .{}, + ); + } + }, + else => { + return step.fail("roc fmt --check terminated abnormally", .{}); + }, + } + } + fn checkSnapshotChanges(step: *Step) !void { const b = step.owner; std.debug.print("---- minici: checking for snapshot changes ----\n", .{});