-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
100 lines (87 loc) · 2.69 KB
/
build.zig
File metadata and controls
100 lines (87 loc) · 2.69 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
94
95
96
97
98
99
100
const std = @import("std");
pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});
const libzig8only = b.option(
bool,
"libZig8Only",
"Only install the zig8 library.",
) orelse false;
const zig8 = b.addModule("zig8", .{
.root_source_file = b.path("./src/lib/root.zig"),
.target = target,
.optimize = optimize,
});
const libzig8 = b.addLibrary(.{
.name = "zig8",
.root_module = zig8,
});
b.installArtifact(libzig8);
const term = b.addModule("term", .{
.root_source_file = b.path("./src/term/root.zig"),
.target = target,
.optimize = optimize,
});
const exe = b.addExecutable(.{
.name = "zig-8",
.root_module = b.createModule(.{
.root_source_file = b.path("./src/main.zig"),
.target = b.graph.host,
.imports = &.{
.{
.name = "zig8",
.module = zig8,
},
.{
.name = "term",
.module = term,
},
},
}),
});
const rl = b.dependency("raylib", .{
.target = target,
.optimize = optimize,
});
const raylib_artifact = rl.artifact("raylib");
exe.root_module.linkLibrary(raylib_artifact);
if (!libzig8only) {
b.installArtifact(raylib_artifact);
b.installArtifact(exe);
}
// RUNNING
const run_exe = b.addRunArtifact(exe);
const run_step = b.step("run", "Run the chip8 emulator");
{
// I like this but the next option is cleaner
// Ex: zig build run -DROM_Path=./ROMs...
// const rom_path = b.option(
// []const u8,
// "ROM_Path",
// "Relative path to your rom",
// );
// if (rom_path) |path| {
// run_exe.addArg(path);
// run_step.dependOn(&run_exe.step);
// } else {
// run_step.dependOn(
// &b.addFail("The -DROM_Path=... option is required for the run step").step,
// );
// }
// Ex: zig build -- ./ROMs/...
if (b.args) |args| {
run_exe.addArgs(args);
}
run_step.dependOn(&run_exe.step);
}
// TESTING
const test_step = b.step("test", "Run unit tests");
const unit_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("./src/main.zig"),
.target = target,
}),
});
const run_unit_tests = b.addRunArtifact(unit_tests);
test_step.dependOn(&run_unit_tests.step);
}