-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
93 lines (82 loc) · 3.45 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
const std = @import("std");
const builtin = @import("builtin");
const nov_version: std.SemanticVersion = .{ .major = 0, .minor = 0, .patch = 0 };
pub fn build(b: *std.Build) void {
comptime {
const current_zig = builtin.zig_version;
const min_zig = std.SemanticVersion.parse("0.14.0-dev.1860+2e2927735") catch unreachable;
if (current_zig.order(min_zig) == .lt) {
@compileError(std.fmt.comptimePrint(
\\Your zig version ({}) does not meet the minimum required version ({})
, .{ current_zig, min_zig }));
}
}
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe_options = b.addOptions();
exe_options.addOption(std.SemanticVersion, "version", nov_version);
const exe = makeExe(b, target, optimize, exe_options);
b.installArtifact(exe);
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 app");
run_step.dependOn(&run_cmd.step);
const release = b.step("release", "Make an upstream binary release");
const release_targets = [_]std.Target.Query{
.{ .cpu_arch = .aarch64, .os_tag = .macos },
.{ .cpu_arch = .aarch64, .os_tag = .linux },
.{ .cpu_arch = .x86_64, .os_tag = .linux },
.{ .cpu_arch = .x86_64, .os_tag = .windows },
};
for (release_targets) |target_query| {
const rel_target = b.resolveTargetQuery(target_query);
const rel_exe = makeExe(b, rel_target, .ReleaseSafe, exe_options);
rel_exe.root_module.strip = true;
const install = b.addInstallArtifact(rel_exe, .{});
install.dest_sub_path = b.fmt("{s}-{s}", .{
target_query.zigTriple(b.allocator) catch unreachable,
rel_exe.name,
});
release.dependOn(&install.step);
}
const tests = b.addTest(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const run_tests = b.addRunArtifact(tests);
const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_tests.step);
const fmt_step = b.step("fmt", "Format all source files");
fmt_step.dependOn(&b.addFmt(.{ .paths = &.{ "build.zig", "src" } }).step);
const clean_step = b.step("clean", "Remove build artifacts");
clean_step.dependOn(&b.addRemoveDirTree(b.path("zig-out")).step);
clean_step.dependOn(&b.addRemoveDirTree(b.path(".zig-cache")).step);
}
fn makeExe(
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
options: *std.Build.Step.Options,
) *std.Build.Step.Compile {
const isocline = b.dependency("isocline-zig", .{}).module("isocline");
const clap = b.dependency("clap", .{}).module("clap");
const known_folders = b.dependency("known-folders", .{}).module("known-folders");
const axe = b.dependency("axe", .{}).module("axe");
const exe = b.addExecutable(.{
.name = "nov",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addOptions("build_options", options);
exe.root_module.addImport("isocline", isocline);
exe.root_module.addImport("clap", clap);
exe.root_module.addImport("axe", axe);
exe.root_module.addImport("known-folders", known_folders);
exe.linkLibC();
return exe;
}