-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
88 lines (75 loc) · 3.04 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
const std = @import("std");
const Example = struct {
name: []const u8,
path: []const u8,
};
fn discoverExamples(allocator: std.mem.Allocator) !std.ArrayList(Example) {
var examples = std.ArrayList(Example).init(allocator);
var examples_dir = try std.fs.cwd().openDir("examples", .{ .iterate = true });
defer examples_dir.close();
var examples_it = examples_dir.iterate();
while (try examples_it.next()) |entry| {
if (entry.kind == .file and std.mem.endsWith(u8, entry.name, ".zig")) {
const name = try std.mem.concat(allocator, u8, &[_][]const u8{ "example-", entry.name[0 .. entry.name.len - 4] });
const path = try std.fs.path.join(allocator, &[_][]const u8{ "examples", entry.name });
try examples.append(.{ .name = name, .path = path });
}
}
return examples;
}
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Create radio module
const radio_module = b.addModule("radio", .{ .root_source_file = b.path("src/radio.zig") });
radio_module.addImport("radio", radio_module);
// Discover examples
var examples = try discoverExamples(b.allocator);
defer {
for (examples.items) |example| {
examples.allocator.free(example.name);
examples.allocator.free(example.path);
}
examples.deinit();
}
// Build examples
const examples_step = b.step("examples", "Build examples");
for (examples.items) |example| {
const exe = b.addExecutable(.{
.name = example.name,
.root_source_file = b.path(example.path),
.target = target,
.optimize = .ReleaseFast,
});
exe.root_module.addImport("radio", radio_module);
exe.linkLibC();
examples_step.dependOn(&b.addInstallArtifact(exe, .{}).step);
}
// Run unit tests
const tests = b.addTest(.{
.root_source_file = b.path("src/radio.zig"),
.target = target,
.optimize = optimize,
});
tests.linkLibC();
const run_tests = b.addRunArtifact(tests);
const test_step = b.step("test", "Run framework tests");
test_step.dependOn(&run_tests.step);
// Run benchmark suite
const benchmark_step = b.step("benchmark", "Run benchmark suite");
const benchmark_suite = b.addExecutable(.{
.name = "benchmark",
.root_source_file = b.path("benchmarks/benchmark.zig"),
.target = target,
.optimize = .ReleaseFast,
});
benchmark_suite.root_module.addImport("radio", radio_module);
benchmark_suite.linkLibC();
const run_benchmark_suite = b.addRunArtifact(benchmark_suite);
if (b.args) |args| run_benchmark_suite.addArgs(args);
benchmark_step.dependOn(&run_benchmark_suite.step);
// Generate test vectors
const generate_step = b.step("generate", "Generate test vectors");
const generate_cmd = b.addSystemCommand(&[_][]const u8{ "python3", "generate.py" });
generate_step.dependOn(&generate_cmd.step);
}