-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.zig
77 lines (64 loc) · 2.17 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
const std = @import("std");
// near default build.zig from 0.11.0-dev.1908+06b263825a
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const src = b.path("src/main.zig");
const opts = b.addOptions();
opts.addOption(
std.SemanticVersion,
"version",
std.SemanticVersion.parse(version(b)) catch unreachable,
);
const log = b.createModule(.{
.root_source_file = b.path("src/log.zig"),
});
const exe = b.addExecutable(.{
.name = "hsh",
.root_source_file = src,
.target = target,
.optimize = optimize,
});
exe.root_module.addOptions("hsh_build", opts);
exe.root_module.addImport("log", log);
b.installArtifact(exe);
// hsh doesn't like to be run from within zig build
//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);
// TODO enable sysinstall with keyword
//const install_step = b.step("sysinstall", "install to system");
//install_step.dependOn(&b.addInstallArtifact(exe).step);
// TESTS
const unit_tests = b.addTest(.{
.root_source_file = src,
.target = target,
.optimize = optimize,
});
unit_tests.root_module.addOptions("hsh_build", opts);
unit_tests.root_module.addImport("log", log);
const run_tests = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_tests.step);
}
fn version(b: *std.Build) []const u8 {
if (!std.process.can_spawn) {
std.debug.print("Can't get a version number\n", .{});
std.process.exit(1);
}
var code: u8 = undefined;
const git_wide = b.runAllowFail(&[_][]const u8{
"git",
"describe",
"--dirty",
"--always",
}, &code, .Ignore) catch {
std.process.exit(2);
};
var git = std.mem.trim(u8, git_wide, " \r\n");
return if (std.mem.startsWith(u8, git, "v")) git[1..] else git;
}