Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
119 lines (98 loc) · 3.92 KB
/
Copy pathbuild.zig
File metadata and controls
119 lines (98 loc) · 3.92 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
const std = @import("std");
// Export the main module for use with zig fetch
// 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: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const pbt_mod = b.addModule("zlowcheck", .{
.root_source_file = b.path("src/zlowcheck.zig"),
.target = target,
.optimize = optimize,
});
// Create the PRNG module separately for internal use
const prng_mod = b.createModule(.{
.root_source_file = b.path("src/finite_prng.zig"),
.target = target,
.optimize = optimize,
});
// Create the test_helpers module
const test_helpers_mod = b.createModule(.{
.root_source_file = b.path("src/test_helpers.zig"),
.target = target,
.optimize = optimize,
});
// Add dependencies for the main modules
pbt_mod.addImport("finite_prng", prng_mod);
// Now, we will create a static library based on the module we created above.
// This creates a `std.Build.Step.Compile`, which is the build step responsible
// for actually invoking the compiler.
const pbt_lib = b.addLibrary(.{
.linkage = .static,
.name = "zlowcheck",
.root_module = pbt_mod,
});
const prng_lib = b.addLibrary(.{
.linkage = .static,
.name = "FinitePrng",
.root_module = prng_mod,
});
b.installArtifact(pbt_lib);
b.installArtifact(prng_lib);
// Set up tests with the test_helpers module
const pbt_unit_tests = b.addTest(.{
.root_module = pbt_mod,
});
// Add test_helpers to the test build only
pbt_unit_tests.root_module.addImport("test_helpers", test_helpers_mod);
const prng_unit_tests = b.addTest(.{
.root_module = prng_mod,
});
// Add finite_prng to itself for testing
prng_unit_tests.root_module.addImport("finite_prng", prng_mod);
// Add test_helpers to the test build only
prng_unit_tests.root_module.addImport("test_helpers", test_helpers_mod);
const run_lib_unit_tests = b.addRunArtifact(pbt_unit_tests);
const run_prng_unit_tests = b.addRunArtifact(prng_unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
test_step.dependOn(&run_prng_unit_tests.step);
docs_gen(
b,
.{ .prng_mod = prng_mod, .zlowcheck = pbt_lib },
);
draft_no_module(
b,
.{ .prng_mod = prng_mod, .test_helpers_mod = test_helpers_mod },
.{ .target = target, .optimize = optimize },
);
}
fn docs_gen(b: *std.Build, modules: anytype) void {
const install_docs = b.addInstallDirectory(.{
.install_dir = .prefix,
.install_subdir = "docs",
.source_dir = modules.zlowcheck.getEmittedDocs(),
});
const docs_step = b.step("docs", "Generate library documentation");
docs_step.dependOn(&install_docs.step);
}
pub fn draft_no_module(b: *std.Build, modules: anytype, build_config: anytype) void {
const draft_step = b.step("test-draft", "Run tests for draft_no_shrink module");
// Create a single module for the draft library
const draft_lib_mod = b.createModule(.{
.root_source_file = b.path("draft_no_shrink/draft_no_shrink_lib.zig"),
.target = build_config.target,
.optimize = build_config.optimize,
});
// Add dependencies to the draft library module
draft_lib_mod.addImport("finite_prng", modules.prng_mod);
draft_lib_mod.addImport("test_helpers", modules.test_helpers_mod);
// Create a single test for the draft library
const draft_tests = b.addTest(.{
.root_module = draft_lib_mod,
});
// Create the run artifact and connect it to the step
const run_draft_tests = b.addRunArtifact(draft_tests);
draft_step.dependOn(&run_draft_tests.step);
}