-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
75 lines (67 loc) · 2.83 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
const std = @import("std");
const builtin = std.builtin;
const Build = std.Build;
const Step = Build.Step;
const Run = Step.Run;
const Compile = Build.Step.Compile;
const CrossTarget = std.zig.CrossTarget;
// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
pub fn build(b: *Build) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target: CrossTarget = b.standardTargetOptions(.{});
// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize: builtin.OptimizeMode = b.standardOptimizeOption(.{});
const exe: *Compile = b.addExecutable(.{
.name = "algorithms.zig",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
b.installArtifact(exe);
const run_cmd: *Run = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
// This allows the user to pass arguments to the application in the build
// command itself, like this: `zig build run -- arg1 arg2 etc`
if (b.args) |args| {
run_cmd.addArgs(args);
}
// This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build run`
// This will evaluate the `run` step rather than the default, which is "install".
const run_step: *Step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const test_step: *Step = b.step("test", "Run unit tests");
var test_steps_file_names = [_][]const u8{
"src/main.zig",
"src/BubbleSort.zig",
"src/LinkedList.zig",
"src/Queue.zig",
"src/TwoCrystalProblem.zig",
"src/Stack.zig",
"src/MazeSolver.zig",
"src/QuickSort.zig",
"src/BinarySearch.zig",
"src/DoublyLinkedList.zig",
"src/TreeTraversal.zig",
"src/BreadthFirstSearch.zig",
"src/BinaryTreeComparison.zig",
};
inline for (test_steps_file_names) |test_step_file_name| {
populateTestSteps(b, test_step, b.addTest(.{
.root_source_file = .{ .path = test_step_file_name },
.target = target,
.optimize = optimize,
}));
}
}
fn populateTestSteps(b: *Build, test_step: *Step, compile: *Compile) void {
var run_tests: *Run = b.addRunArtifact(compile);
test_step.dependOn(&run_tests.step);
}