-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.zig
67 lines (56 loc) · 2.26 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
const std = @import("std");
pub fn build(b: *std.build.Builder) void
{
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
const test_step = b.step("test", "Run unit tests directly.");
const run_step = b.step("run", "Run example.");
const default_example = b.option(bool, "default_example", "A simple example of using nanoid.") orelse false;
const custom_alphabet_example = b.option(bool, "custom_alphabet_example", "A simple example of using nanoid.") orelse false;
const tests = b.option(bool, "tests", "The unit tests of the library.") orelse false;
if (default_example)
{
const exe = b.addExecutable("nanoid-zig-default-example", "examples/default-example.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.addPackage(getPackage("nanoid"));
exe.install();
const exe_run = exe.run();
exe_run.step.dependOn(b.getInstallStep());
run_step.dependOn(&exe_run.step);
}
if (custom_alphabet_example)
{
const exe = b.addExecutable("nanoid-zig-custom-alphabet-example", "examples/custom-alphabet-example.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.addPackage(getPackage("nanoid"));
exe.install();
const exe_run = exe.run();
exe_run.step.dependOn(b.getInstallStep());
run_step.dependOn(&exe_run.step);
}
if (tests)
{
const exe = b.addTestExe("nanoid-zig-test", "src/nanoid.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.install();
const exe_run = exe.run();
exe_run.step.dependOn(b.getInstallStep());
run_step.dependOn(&exe_run.step);
}
// Test runner
const test_runner = b.addTest("src/nanoid.zig");
test_runner.setBuildMode(mode);
test_runner.setTarget(target);
test_step.dependOn(&test_runner.step);
}
pub fn getPackage(name: []const u8) std.build.Pkg
{
return std.build.Pkg{
.name = name,
.source = .{ .path = comptime std.fs.path.dirname(@src().file).? ++ "/src/nanoid.zig" },
.dependencies = null, // null by default, but can be set to a slice of `std.build.Pkg`s that your package depends on.
};
}