-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.zig
70 lines (57 loc) · 2.18 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
const std = @import("std");
const builtin = @import("builtin");
const targets: []const std.Target.Query = &.{
.{ .cpu_arch = .aarch64, .os_tag = .macos },
.{ .cpu_arch = .aarch64, .os_tag = .linux },
.{ .cpu_arch = .x86_64, .os_tag = .linux },
.{ .cpu_arch = .x86_64, .os_tag = .macos },
};
fn createExe(b: *std.Build, exe_name: []const u8, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) !*std.Build.Step.Compile {
const libvaxis = b.dependency("vaxis", .{ .target = target }).module("vaxis");
const fuzzig = b.dependency("fuzzig", .{ .target = target }).module("fuzzig");
const zuid = b.dependency("zuid", .{ .target = target }).module("zuid");
const exe = b.addExecutable(.{
.name = exe_name,
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("vaxis", libvaxis);
exe.root_module.addImport("fuzzig", fuzzig);
exe.root_module.addImport("zuid", zuid);
return exe;
}
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Building targets for release.
const build_all = b.option(bool, "all-targets", "Build all targets in ReleaseSafe mode.") orelse false;
if (build_all) {
try buildTargets(b);
return;
}
const exe = try createExe(b, "jido", target, optimize);
b.installArtifact(exe);
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);
}
fn buildTargets(b: *std.Build) !void {
for (targets) |t| {
const target = b.resolveTargetQuery(t);
const exe = try createExe(b, "jido", target, .ReleaseSafe);
b.installArtifact(exe);
const target_output = b.addInstallArtifact(exe, .{
.dest_dir = .{
.override = .{
.custom = try t.zigTriple(b.allocator),
},
},
});
b.getInstallStep().dependOn(&target_output.step);
}
}