-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
100 lines (88 loc) · 3.71 KB
/
build.zig
File metadata and controls
100 lines (88 loc) · 3.71 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");
const Compile = std.Build.Step.Compile;
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const strip = if (optimize == std.builtin.OptimizeMode.ReleaseSafe) true else null;
const default_os = target.result.os.tag;
const common = b.createModule(.{ .root_source_file = b.path("src/common/root.zig") });
if (default_os.isBSD() or default_os.isDarwin() or default_os == std.Target.Os.Tag.linux) {
common.link_libc = true;
}
const zip = b.dependency("zip", .{ .target = target, .optimize = optimize });
const zigverm = b.addExecutable(
.{ .name = "zigverm", .root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.strip = strip,
}) },
);
zigverm.subsystem = .Console;
zigverm.root_module.addImport("common", common);
zigverm.root_module.addImport("zip", zip.module("zip"));
zigverm.root_module.addAnonymousImport("build_zig_zon", .{
.root_source_file = b.path("build.zig.zon"),
});
const zig = b.addExecutable(.{ .name = "zig", .root_module = b.createModule(.{
.root_source_file = b.path("src/zig/main.zig"),
.target = target,
.optimize = optimize,
.strip = strip,
}) });
zig.subsystem = .Console;
zig.root_module.addImport("common", common);
const zigverm_setup = b.addExecutable(.{ .name = "zigverm-setup", .root_module = b.createModule(.{
.root_source_file = b.path("src/zigverm-setup/main.zig"),
.target = target,
.optimize = optimize,
.strip = strip,
}) });
zigverm_setup.subsystem = .Console;
zigverm_setup.root_module.addImport("common", common);
zigverm_setup.root_module.addImport("zip", zip.module("zip"));
b.installArtifact(zigverm);
b.installArtifact(zig);
b.installArtifact(zigverm_setup);
addExeRunner(b, zigverm, "run-zigverm");
addExeRunner(b, zig, "run-zig");
addExeRunner(b, zigverm_setup, "run-zigverm-setup");
addTestRunner(b, target, optimize);
}
fn addExeRunner(b: *std.Build, bin: *Compile, name: []const u8) void {
const run_bin = b.addRunArtifact(bin);
run_bin.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_bin.addArgs(args);
}
const run_zigverm_step = b.step(name, "Run the app");
run_zigverm_step.dependOn(&run_bin.step);
}
fn addTestRunner(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) void {
const zigverm_tests = b.addTest(.{ .root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}) });
const run_zigverm_tests = b.addRunArtifact(zigverm_tests);
const zig_tests = b.addTest(.{ .root_module = b.createModule(.{
.root_source_file = b.path("src/zig/main.zig"),
.target = target,
.optimize = optimize,
}) });
const run_zig_tests = b.addRunArtifact(zig_tests);
const common_tests = b.addTest(.{ .root_module = b.createModule(.{
.root_source_file = b.path("src/zig/main.zig"),
.target = target,
.optimize = optimize,
}) });
const default_os = target.result.os.tag;
if (default_os.isBSD() or default_os.isDarwin() or default_os == std.Target.Os.Tag.linux) {
common_tests.is_linking_libc = true;
}
const run_common_tests = b.addRunArtifact(common_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_zigverm_tests.step);
test_step.dependOn(&run_zig_tests.step);
test_step.dependOn(&run_common_tests.step);
}