-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
137 lines (112 loc) · 4.1 KB
/
build.zig
File metadata and controls
137 lines (112 loc) · 4.1 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
const std = @import("std");
const build_zig_zon = @import("./build.zig.zon");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const tlsDep = b.dependency("tls", .{
.target = target,
.optimize = optimize,
});
const build_options = b.addOptions();
build_options.addOption(
std.SemanticVersion,
"version",
std.SemanticVersion.parse(build_zig_zon.version) catch unreachable,
);
const build_options_module = build_options.createModule();
const toziMod = b.addModule("tozi", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "tls", .module = tlsDep.module("tls") },
.{ .name = "build_options", .module = build_options_module },
},
});
const exeOpts = std.Build.ExecutableOptions{
.name = "tozi",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "tozi", .module = toziMod },
.{ .name = "build_options", .module = build_options_module },
},
}),
};
const exe = b.addExecutable(exeOpts);
b.installArtifact(exe);
const checkExe = b.addExecutable(exeOpts);
const checkMod = b.addLibrary(.{
.name = "libtozi",
.root_module = toziMod,
});
const checkStep = b.step("check", "Run check on exe");
checkStep.dependOn(&checkExe.step);
checkStep.dependOn(&checkMod.step);
const run_step = b.step("run", "Run the app");
const run_cmd = b.addRunArtifact(exe);
run_step.dependOn(&run_cmd.step);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_mod_tests = b.addRunArtifact(b.addTest(.{ .root_module = toziMod }));
const run_exe_tests = b.addRunArtifact(b.addTest(.{ .root_module = exe.root_module }));
const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_mod_tests.step);
test_step.dependOn(&run_exe_tests.step);
try addBumpStep(b, target, build_options_module);
}
fn addBumpStep(b: *std.Build, target: std.Build.ResolvedTarget, buildOptions: *std.Build.Module) !void {
const bump = b.addExecutable(.{
.name = "bump",
.root_module = b.createModule(.{
.root_source_file = b.path("tools/bump.zig"),
.target = target,
.imports = &[_]std.Build.Module.Import{
.{ .name = "build_options", .module = buildOptions },
},
}),
});
const runBump = b.addRunArtifact(bump);
const commits = b.addSystemCommand(&.{
"git",
"log",
"--pretty=format:%s",
std.fmt.allocPrint(b.allocator, "v{s}..HEAD", .{build_zig_zon.version}) catch unreachable,
});
runBump.step.dependOn(&commits.step);
const generatedBuildZigZon = runBump.addOutputFileArg("build.zig.zon");
runBump.addFileArg(commits.captureStdOut());
runBump.addFileArg(b.path("build.zig.zon"));
const wf = b.addUpdateSourceFiles();
wf.step.dependOn(&runBump.step);
wf.addCopyFileToSource(generatedBuildZigZon, "build.zig.zon");
const gitAdd = b.addSystemCommand(&.{
"git",
"add",
"build.zig.zon",
});
gitAdd.step.dependOn(&wf.step);
const gitCommit = b.addSystemCommand(&.{
"git",
"commit",
"-m chore: bump version",
});
gitCommit.step.dependOn(&gitAdd.step);
const tag = b.addExecutable(.{
.name = "tag",
.root_module = b.createModule(.{
.root_source_file = b.path("tools/git-tag.zig"),
.target = target,
}),
});
const runTag = b.addRunArtifact(tag);
runTag.step.dependOn(&gitCommit.step);
runTag.addFileArg(runBump.captureStdErr());
const bumpStep = b.step("bump", "bump package version and commit");
bumpStep.dependOn(&wf.step);
bumpStep.dependOn(&runTag.step);
}