-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
82 lines (67 loc) · 2.26 KB
/
build.zig
File metadata and controls
82 lines (67 loc) · 2.26 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
const std = @import("std");
const Dependency = struct {
name: []const u8,
module: ?[]const u8 = null,
link: ?[]const u8 = null,
};
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const name = "dotr";
const deps = &[_]Dependency{
.{ .name = "age" },
.{ .name = "parg" },
.{ .name = "zutils" },
};
const exe = b.addExecutable(.{
.name = name,
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const opts = getBuildOptions(b);
opts.addOption([]const u8, "name", name);
exe.root_module.addOptions("build_options", opts);
appendDependencies(b, exe, target, optimize, deps);
b.installArtifact(exe);
const test_deps = &[_]Dependency{
.{ .name = "protest" },
};
const unit_test = b.addTest(.{
.root_source_file = b.path("src/test.zig"),
.target = target,
.optimize = optimize,
});
appendDependencies(b, unit_test, target, optimize, deps ++ test_deps);
const run_unit_tests = b.addRunArtifact(unit_test);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_unit_tests.step);
}
fn appendDependencies(b: *std.Build, comp: *std.Build.Step.Compile, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, deps: []const Dependency) void {
for (deps) |d| {
const module = d.module orelse d.name;
const dep = b.dependency(d.name, .{ .target = target, .optimize = optimize });
const mod = dep.module(module);
comp.root_module.addImport(d.name, mod);
if (d.link) |l| {
comp.linkLibrary(dep.artifact(l));
}
}
}
fn getBuildOptions(b: *std.Build) *std.Build.Step.Options {
const options = b.addOptions();
const version = b.run(&[_][]const u8{
"git",
"describe",
"--tags",
"--abbrev=0",
});
options.addOption([]const u8, "version", std.mem.trim(u8, version, " \n"));
const commit = b.run(&[_][]const u8{
"git",
"rev-parse",
"HEAD",
})[0..8];
options.addOption([]const u8, "commit", std.mem.trim(u8, commit, " \n"));
return options;
}