-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.zig
93 lines (77 loc) · 2.85 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
93
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// The main library
const lib = b.addStaticLibrary(.{
.name = "ziglet",
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
b.installArtifact(lib);
// setup logging
const nexlog_dep = b.dependency("nexlog", .{
.target = target,
.optimize = optimize,
});
lib.root_module.addImport("nexlog", nexlog_dep.module("nexlog"));
// Create module for use as a dependency
const ziglet_module = b.addModule("ziglet", .{
.root_source_file = b.path("src/root.zig"),
});
ziglet_module.addImport("nexlog", nexlog_dep.module("nexlog"));
// Unit tests
const lib_unit_tests = b.addTest(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
lib_unit_tests.root_module.addImport("nexlog", nexlog_dep.module("nexlog"));
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
const examples = [_]struct {
name: []const u8,
path: []const u8,
// If true, corresponding example will link to libc (default: false)
// example below
libc: bool = false,
}{
.{ .name = "simple", .path = "examples/simple.zig" },
.{ .name = "calculator", .path = "examples/calculator.zig" },
.{
.name = "jump",
.path = "examples/jump_instructions.zig",
// .libc = true,
},
.{ .name = "default_config", .path = "examples/default_config.zig" },
.{ .name = "custom_config", .path = "examples/custom_config.zig" },
.{ .name = "fib", .path = "examples/fib.zig" },
};
const all_examples_step = b.step("all-examples", "Run all examples (for CI)");
{
for (examples) |example| {
const exe = b.addExecutable(.{
.name = example.name,
.target = target,
.optimize = optimize,
.root_source_file = b.path(example.path),
});
exe.root_module.addImport("ziglet", ziglet_module);
if (example.libc) {
exe.linkLibC();
}
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(example.name, example.path);
run_step.dependOn(&run_cmd.step);
test_step.dependOn(&run_cmd.step);
all_examples_step.dependOn(&run_cmd.step);
}
}
}