-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.zig
More file actions
134 lines (120 loc) · 4.67 KB
/
build.zig
File metadata and controls
134 lines (120 loc) · 4.67 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
const std = @import("std");
const HypergraphZPath = "src/hypergraphz.zig";
const BenchPath = "bench/main.zig";
const TestRootPath = "tests/root.zig";
const CAbiPath = "src/hgz_c_api.zig";
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const root_source_file = b.path(HypergraphZPath);
const root_module = b.addModule("hypergraphz", .{
.root_source_file = root_source_file,
.target = target,
.optimize = optimize,
});
const test_module = b.createModule(.{
.root_source_file = b.path(TestRootPath),
.imports = &.{.{ .name = "hypergraphz", .module = root_module }},
.target = target,
.optimize = optimize,
});
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const unit_tests = b.addTest(.{
.root_module = test_module,
});
const run_lib_unit_tests = b.addRunArtifact(unit_tests);
// Disable cache for unit tests to get logs.
// https://ziggit.dev/t/how-to-enable-more-logging-and-disable-caching-with-zig-build-test/2654/11
run_lib_unit_tests.has_side_effects = true;
// Similar to creating the run step earlier, this exposes a `test` step to
// the `zig build --help` menu, providing a way for the user to request
// running the unit tests.
// Notes:
// - `zig build test -Doptimize=ReleaseFast` to run the unit tests in release-fast mode.
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
// Generate docs step.
const docs_step = b.step("docs", "Build the HypergraphZ docs");
const docs_obj = b.addObject(.{
.name = "HypergraphZ",
.root_module = b.createModule(.{
.root_source_file = root_source_file,
.target = target,
.optimize = optimize,
}),
});
const docs = docs_obj.getEmittedDocs();
docs_step.dependOn(&b.addInstallDirectory(.{
.source_dir = docs,
.install_dir = .prefix,
.install_subdir = "docs",
}).step);
// Format step.
const fmt_step = b.step("fmt", "Format all source files");
const fmt = b.addFmt(.{
.paths = &.{ HypergraphZPath, "bench", "build.zig", "tests", "examples" },
});
fmt_step.dependOn(&fmt.step);
// Check step used by the zls configuration.
const check_step = b.step("check", "Check if HypergraphZ compiles");
const check = b.addTest(.{
.root_module = test_module,
});
check_step.dependOn(&check.step);
const bench_check = b.addExecutable(.{
.name = "bench",
.root_module = b.createModule(.{
.root_source_file = b.path(BenchPath),
.target = target,
.optimize = optimize,
.imports = &.{.{ .name = "hypergraphz", .module = root_module }},
}),
});
check_step.dependOn(&bench_check.step);
// Example step.
const example_step = b.step("example", "Run the co-authorship network example");
const example_exe = b.addExecutable(.{
.name = "coauthorship",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/coauthorship.zig"),
.imports = &.{.{ .name = "hypergraphz", .module = root_module }},
.target = target,
.optimize = optimize,
}),
});
example_step.dependOn(&b.addRunArtifact(example_exe).step);
check_step.dependOn(&example_exe.step);
// Shared library step (C ABI for Python bindings).
const lib_step = b.step("lib", "Build the HypergraphZ shared library (C ABI)");
const lib = b.addLibrary(.{
.name = "hypergraphz",
.linkage = .dynamic,
.root_module = b.createModule(.{
.root_source_file = b.path(CAbiPath),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{.{ .name = "hypergraphz", .module = root_module }},
}),
});
lib_step.dependOn(&b.addInstallArtifact(lib, .{}).step);
// Bench step.
const bench_source_file = b.path(BenchPath);
const bench_module = b.addModule("bench", .{
.root_source_file = bench_source_file,
.target = target,
.optimize = .ReleaseFast,
.imports = &.{.{ .name = "hypergraphz", .module = root_module }},
});
const bench_step = b.step("bench", "Run benchmarks");
const bench_exe = b.addExecutable(.{
.name = "bench",
.root_module = bench_module,
});
const bench_run = b.addRunArtifact(bench_exe);
if (b.args) |args| {
bench_run.addArgs(args);
}
bench_step.dependOn(&bench_run.step);
}