-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
93 lines (80 loc) · 3.44 KB
/
Copy pathbuild.zig
File metadata and controls
93 lines (80 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const std = @import("std");
pub fn build(b: *std.Build) void {
// These helpers expose the standard `-Dtarget` and `-Doptimize` flags so
// `zig build`, `zig build run`, and release builds all share the same setup.
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
if (target.result.os.tag != .windows) {
@panic("asteroids is configured for Windows-only builds");
}
// Pull in raylib-zig as a dependency and build it for the same target and
// optimization mode as the game. We request GLES2 because the app boots the
// ANGLE runtime in `src/angle_runtime.zig`, which translates GLES calls to
// Direct3D on Windows.
const raylib_dep = b.dependency("raylib_zig", .{
.target = target,
.optimize = optimize,
.opengl_version = .gles_2,
});
const raylib = raylib_dep.module("raylib");
const raylib_artifact = raylib_dep.artifact("raylib");
// `core` is a reusable module for the game's shared code. Tests can target
// this module directly without going through the executable entry point.
const core = b.addModule("asteroids", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "raylib", .module = raylib },
},
});
// Build the actual executable from `src/main.zig`, importing both the core
// game module above and the third-party raylib module.
const exe = b.addExecutable(.{
.name = "asteroids",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "asteroids", .module = core },
.{ .name = "raylib", .module = raylib },
},
}),
});
// raylib is provided as a compiled library artifact, so the executable and
// test binaries must link against it explicitly. libc is also required by
// raylib and parts of the runtime code.
exe.root_module.linkLibrary(raylib_artifact);
exe.root_module.link_libc = true;
// `zig build` installs the executable into `zig-out/bin`.
b.installArtifact(exe);
// `zig build run` first performs the install step, then launches the built
// executable. Any extra CLI args after `--` are forwarded to the program.
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the game");
run_step.dependOn(&run_cmd.step);
// There are two test entry points:
// - core tests cover the reusable game module
// - exe tests cover the main executable module graph
const core_tests = b.addTest(.{
.root_module = core,
});
core_tests.root_module.linkLibrary(raylib_artifact);
core_tests.root_module.link_libc = true;
const run_core_tests = b.addRunArtifact(core_tests);
const exe_tests = b.addTest(.{
.root_module = exe.root_module,
});
exe_tests.root_module.linkLibrary(raylib_artifact);
exe_tests.root_module.link_libc = true;
const run_exe_tests = b.addRunArtifact(exe_tests);
// `zig build test` runs both test binaries.
const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_core_tests.step);
test_step.dependOn(&run_exe_tests.step);
}