forked from zig-gamedev/zig-gamedev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
97 lines (80 loc) · 2.5 KB
/
build.zig
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
const std = @import("std");
pub const Options = struct {
enable_cross_platform_determinism: bool = true,
};
pub const Package = struct {
options: Options,
zmath: *std.Build.Module,
zmath_options: *std.Build.Module,
pub fn link(pkg: Package, exe: *std.Build.CompileStep) void {
exe.addModule("zmath", pkg.zmath);
exe.addModule("zmath_options", pkg.zmath_options);
}
};
pub fn package(
b: *std.Build,
_: std.zig.CrossTarget,
_: std.builtin.Mode,
args: struct {
options: Options = .{},
},
) Package {
const step = b.addOptions();
step.addOption(
bool,
"enable_cross_platform_determinism",
args.options.enable_cross_platform_determinism,
);
const zmath_options = step.createModule();
const zmath = b.createModule(.{
.source_file = .{ .path = thisDir() ++ "/src/main.zig" },
.dependencies = &.{
.{ .name = "zmath_options", .module = zmath_options },
},
});
return .{
.options = args.options,
.zmath = zmath,
.zmath_options = zmath_options,
};
}
pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});
const test_step = b.step("test", "Run zmath tests");
test_step.dependOn(runTests(b, optimize, target));
const benchmark_step = b.step("benchmark", "Run zmath benchmarks");
benchmark_step.dependOn(runBenchmarks(b, target));
}
pub fn runTests(
b: *std.Build,
optimize: std.builtin.Mode,
target: std.zig.CrossTarget,
) *std.Build.Step {
const tests = b.addTest(.{
.name = "zmath-tests",
.root_source_file = .{ .path = thisDir() ++ "/src/main.zig" },
.target = target,
.optimize = optimize,
});
const zmath_pkg = package(b, target, optimize, .{});
tests.addModule("zmath_options", zmath_pkg.zmath_options);
return &b.addRunArtifact(tests).step;
}
pub fn runBenchmarks(
b: *std.Build,
target: std.zig.CrossTarget,
) *std.Build.Step {
const exe = b.addExecutable(.{
.name = "zmath-benchmarks",
.root_source_file = .{ .path = thisDir() ++ "/src/benchmark.zig" },
.target = target,
.optimize = .ReleaseFast,
});
const zmath_pkg = package(b, target, .ReleaseFast, .{});
exe.addModule("zmath", zmath_pkg.zmath);
return &b.addRunArtifact(exe).step;
}
inline fn thisDir() []const u8 {
return comptime std.fs.path.dirname(@src().file) orelse ".";
}