Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
109 lines (103 loc) · 4.44 KB
/
Copy pathbuild.zig
File metadata and controls
109 lines (103 loc) · 4.44 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const io = b.graph.io;
const lib_source = b.path("src/lib.zig");
const lib_module = b.addModule("ordered", .{
.root_source_file = lib_source,
.target = target,
.optimize = optimize,
});
const lib = b.addLibrary(.{
.name = "ordered",
.root_module = lib_module,
});
b.installArtifact(lib);
// --- Docs Setup ---
const docs_step = b.step("docs", "Generate API documentation");
const install_docs = b.addInstallDirectory(.{
.source_dir = lib.getEmittedDocs(),
.install_dir = .{ .custom = b.root.joinString(b.allocator, "docs/api") catch @panic("OOM") },
.install_subdir = "",
});
docs_step.dependOn(&install_docs.step);
// --- Tests ---
const lib_unit_tests = b.addTest(.{
.root_module = lib_module,
});
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);
// --- Examples ---
const examples_path = "examples";
if (b.root.openDir(io, examples_path, .{ .iterate = true })) |examples_dir| {
b.dependOnDirectoryContents(b.path(examples_path));
var dir = examples_dir;
defer dir.close(io);
const run_all_examples = b.step("run-all", "Run all examples");
var it = dir.iterate();
while (it.next(io) catch null) |entry| {
if (entry.kind != .file) continue;
if (!std.mem.endsWith(u8, entry.name, ".zig")) continue;
const exe_name = entry.name[0 .. entry.name.len - 4];
const exe_path = b.fmt("{s}/{s}", .{ examples_path, entry.name });
const exe_module = b.addModule(exe_name, .{
.root_source_file = b.path(exe_path),
.target = target,
.optimize = optimize,
});
exe_module.addImport("ordered", lib_module);
const exe = b.addExecutable(.{
.name = exe_name,
.root_module = exe_module,
});
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
const run_step_name = b.fmt("run-{s}", .{exe_name});
const run_step_desc = b.fmt("Run the {s} example", .{exe_name});
const run_step = b.step(run_step_name, run_step_desc);
run_step.dependOn(&run_cmd.step);
run_all_examples.dependOn(run_step);
}
} else |err| switch (err) {
// Used as a library dependency: no examples directory at the import root.
error.FileNotFound, error.NotDir => {},
else => @panic(@errorName(err)),
}
// --- Benchmarks ---
const benches_path = "benches";
if (b.root.openDir(io, benches_path, .{ .iterate = true })) |benches_dir| {
b.dependOnDirectoryContents(b.path(benches_path));
var dir = benches_dir;
defer dir.close(io);
const bench_all = b.step("bench-all", "Run all benchmarks");
var it = dir.iterate();
while (it.next(io) catch null) |entry| {
if (entry.kind != .file) continue;
if (!std.mem.endsWith(u8, entry.name, ".zig")) continue;
const bench_name = entry.name[0 .. entry.name.len - 4];
const bench_path = b.fmt("{s}/{s}", .{ benches_path, entry.name });
const bench_module = b.addModule(bench_name, .{
.root_source_file = b.path(bench_path),
.target = target,
.optimize = .ReleaseFast, // Use ReleaseFast for benchmarks
});
bench_module.addImport("ordered", lib_module);
const bench_exe = b.addExecutable(.{
.name = bench_name,
.root_module = bench_module,
});
b.installArtifact(bench_exe);
const run_bench_cmd = b.addRunArtifact(bench_exe);
const bench_step_name = b.fmt("bench-{s}", .{bench_name});
const bench_step_desc = b.fmt("Run the {s} benchmark", .{bench_name});
const bench_step = b.step(bench_step_name, bench_step_desc);
bench_step.dependOn(&run_bench_cmd.step);
bench_all.dependOn(bench_step);
}
} else |err| switch (err) {
error.FileNotFound, error.NotDir => {},
else => @panic(@errorName(err)),
}
}