Zig2048/build.zig

50 lines
1.5 KiB
Zig
Raw Permalink Normal View History

2026-08-21 03:47:26 +01:00
const std = @import("std");
pub fn build(b: *std.Build) void {
2026-08-24 22:10:02 +01:00
// Both of these read flags from the command line, e.g.:
// zig build -Dtarget=x86_64-windows -Doptimize=ReleaseSafe
2026-08-21 03:47:26 +01:00
const target = b.standardTargetOptions(.{});
2026-08-21 14:08:23 +01:00
const optimize = b.standardOptimizeOption(.{});
2026-08-21 03:47:26 +01:00
const exe = b.addExecutable(.{
.name = "_2048zig",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
2026-08-21 14:08:23 +01:00
2026-08-21 03:47:26 +01:00
.target = target,
.optimize = optimize,
2026-08-21 14:08:23 +01:00
.imports = &.{},
2026-08-21 03:47:26 +01:00
}),
});
2026-08-24 22:10:02 +01:00
// Plain `zig build` runs this: copies the binary into zig-out/bin.
2026-08-21 03:47:26 +01:00
b.installArtifact(exe);
2026-08-24 22:10:02 +01:00
// `zig build run`: execute the freshly built program.
2026-08-21 03:47:26 +01:00
const run_step = b.step("run", "Run the app");
const run_cmd = b.addRunArtifact(exe);
run_step.dependOn(&run_cmd.step);
2026-08-24 22:10:02 +01:00
// Chaining run onto install guarantees the exe is rebuilt first.
2026-08-21 03:47:26 +01:00
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
2026-08-24 22:10:02 +01:00
// `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.
2026-08-21 03:47:26 +01:00
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);
}