Zig2048/build.zig
2026-08-24 22:10:02 +01:00

49 lines
1.5 KiB
Zig

const std = @import("std");
pub fn build(b: *std.Build) void {
// Both of these read flags from the command line, e.g.:
// zig build -Dtarget=x86_64-windows -Doptimize=ReleaseSafe
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "_2048zig",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{},
}),
});
// Plain `zig build` runs this: copies the binary into zig-out/bin.
b.installArtifact(exe);
// `zig build run`: execute the freshly built program.
const run_step = b.step("run", "Run the app");
const run_cmd = b.addRunArtifact(exe);
run_step.dependOn(&run_cmd.step);
// Chaining run onto install guarantees the exe is rebuilt first.
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
// `zig build test`: builds a special binary whose "main" collects every
// `test` block reachable from the root source file (main.zig) — which is
// exactly why the `_ = Board;` bridge block lives there and not in board.zig.
const exe_tests = b.addTest(.{
.root_module = exe.root_module,
});
const run_exe_tests = b.addRunArtifact(exe_tests);
const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_exe_tests.step);
}