-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
88 lines (69 loc) · 2.55 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
const std = @import("std");
const Allocator = std.mem.Allocator;
const VERSION = "1.0.0";
fn embedConfig(b: *std.Build, exe: *std.Build.Step.Compile) !void {
var options = b.addOptions();
options.addOption([]const u8, "version", try getVersion(b.allocator));
exe.root_module.addOptions("config", options);
}
fn getVersion(allocator: Allocator) ![]const u8 {
var file = try std.fs.cwd().openFile("pages/updated_on", .{});
defer file.close();
const updated_on = try file.readToEndAlloc(allocator, 11);
return try std.fmt.allocPrint(allocator, "v{s}, database updated on {s}", .{ VERSION, updated_on });
}
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const tool = b.addExecutable(.{
.name = "compile_pages",
.root_source_file = b.path("src/compile_pages.zig"),
.target = b.host,
.optimize = optimize,
});
const tool_step = b.addRunArtifact(tool);
tool_step.addFileInput(b.path("pages/updated_on"));
const output = tool_step.addOutputFileArg("pages.zig");
const exe = b.addExecutable(.{
.name = "drtl",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
try embedConfig(b, exe);
exe.root_module.addAnonymousImport("pages", .{
.root_source_file = output,
});
b.installArtifact(exe);
const release = b.step("release", "create binaries for common targets");
const release_targets = [_][]const u8{
"x86-linux",
"x86_64-linux",
"x86_64-macos",
"x86_64-windows",
"aarch64-linux",
"aarch64-macos",
"aarch64-windows",
"riscv64-linux",
};
for (release_targets) |target_string| {
const query = std.zig.CrossTarget.parse(.{
.arch_os_abi = target_string,
}) catch unreachable;
const rel_exe = b.addExecutable(.{
.name = "drtl",
.root_source_file = b.path("src/main.zig"),
.target = b.resolveTargetQuery(query),
.optimize = .ReleaseSafe,
.strip = true,
});
try embedConfig(b, rel_exe);
rel_exe.root_module.addAnonymousImport("pages", .{
.root_source_file = output,
});
const install = b.addInstallArtifact(rel_exe, .{});
install.dest_dir = .prefix;
install.dest_sub_path = b.fmt("{s}-v{s}-{s}", .{ rel_exe.name, VERSION, target_string });
release.dependOn(&install.step);
}
}