-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
92 lines (76 loc) · 2.7 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
const std = @import("std");
const builtin = @import("builtin");
const Builder = std.build.Builder;
pub fn build(b: *Builder) !void {
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
const options = b.addOptions();
var code: u8 = undefined;
const git_tag = try b.execAllowFail(
&.{ "git", "describe", "--tag" },
&code,
std.ChildProcess.StdIo.Ignore,
);
const version = b.fmt("v{s} ({s}-{s})", .{
git_tag[0 .. git_tag.len - 1],
@tagName(builtin.cpu.arch),
@tagName(builtin.os.tag),
});
options.addOption([]const u8, "version", version);
const exe = b.addExecutable("tldr", "src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.install();
exe.setOutputDir("bin");
exe.addOptions("build_options", options);
for (Packages.all) |pkg| exe.addPackage(pkg);
const run_cmd = exe.run();
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 clean_step = b.step("clean", "Clean build artifacts");
clean_step.makeFn = struct {
fn make(_: *std.build.Step) anyerror!void {
const cwd = std.fs.cwd();
try cwd.deleteTree("bin");
try cwd.deleteTree("zig-out");
try cwd.deleteTree("zig-cache");
}
}.make;
const fmt = b.addFmt(&.{"src"});
const fmt_step = b.step("fmt", "Format all source code");
fmt_step.dependOn(&fmt.step);
}
const Packages = struct {
const clap = std.build.Pkg{
.name = "clap",
.path = std.build.FileSource{ .path = "lib/zig-clap/clap.zig" },
};
const tar = std.build.Pkg{
.name = "tar",
.path = std.build.FileSource{ .path = "./lib/tar/src/main.zig" },
};
const hzzp = std.build.Pkg{
.name = "hzzp",
.path = std.build.FileSource{ .path = "./lib/hzzp/src/main.zig" },
};
const iguanaTLS = std.build.Pkg{
.name = "iguanaTLS",
.path = std.build.FileSource{ .path = "./lib/iguanaTLS/src/main.zig" },
};
const network = std.build.Pkg{
.name = "network",
.path = std.build.FileSource{ .path = "./lib/zig-network/network.zig" },
};
const uri = std.build.Pkg{
.name = "uri",
.path = std.build.FileSource{ .path = "./lib/zig-uri/uri.zig" },
};
const zfetch = std.build.Pkg{
.name = "zfetch",
.path = std.build.FileSource{ .path = "./lib/zfetch/src/main.zig" },
.dependencies = &[_]std.build.Pkg{ hzzp, iguanaTLS, network, uri },
};
const all = &[_]std.build.Pkg{ clap, tar, zfetch };
};