-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
84 lines (69 loc) · 2.24 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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const version = std.SemanticVersion{ .major = 0, .minor = 1, .patch = 0 };
// OS restrictions
switch (target.result.os.tag) {
.linux => {},
else => @panic("Only Linux is supported at the moment"),
}
// CPU restrictions
switch (target.result.cpu.arch) {
.x86_64, .aarch64, .aarch64_be, .aarch64_32 => {},
else => @panic("Only x86_64 and aarch64 are supported at the moment"),
}
// Dependencies
const clap_dep = b.dependency("clap", .{
.target = target,
.optimize = optimize,
});
const clap_mod = clap_dep.module("clap");
// Executable
const exe_step = b.step("exe", "Run executable");
const exe = b.addExecutable(.{
.name = "dobby",
.target = target,
.version = version,
.optimize = optimize,
.root_source_file = b.path("src/main.zig"),
});
exe.root_module.addImport("clap", clap_mod);
exe.linkLibC();
const exe_run = b.addRunArtifact(exe);
if (b.args) |args| {
exe_run.addArgs(args);
}
exe_step.dependOn(&exe_run.step);
b.default_step.dependOn(exe_step);
// Example suite
const examples_step = b.step("example", "Install example suite");
inline for (EXAMPLE_NAMES) |EXAMPLE_NAME| {
const example = b.addExecutable(.{
.name = EXAMPLE_NAME,
.target = target,
.version = version,
.optimize = .Debug,
.root_source_file = b.path(EXAMPLES_DIR ++ EXAMPLE_NAME ++ ".zig"),
});
const example_install = b.addInstallArtifact(example, .{});
examples_step.dependOn(&example_install.step);
}
b.default_step.dependOn(examples_step);
// Formatting checks
const fmt_step = b.step("fmt", "Run formatting checks");
const fmt = b.addFmt(.{
.paths = &.{
"src/",
"build.zig",
EXAMPLES_DIR,
},
.check = true,
});
fmt_step.dependOn(&fmt.step);
b.default_step.dependOn(fmt_step);
}
const EXAMPLES_DIR = "examples/";
const EXAMPLE_NAMES = &.{
"basic",
};