-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
99 lines (84 loc) · 3.19 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
89
90
91
92
93
94
95
96
97
98
99
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Create the library
const lib_v1 = b.addStaticLibrary(.{
.name = "chibihash64_v1",
.root_source_file = .{ .cwd_relative = "src/chibihash64_v1.zig" },
.target = target,
.optimize = optimize,
});
const lib_v2 = b.addStaticLibrary(.{
.name = "chibihash64_v2",
.root_source_file = .{ .cwd_relative = "src/chibihash64_v2.zig" },
.target = target,
.optimize = optimize,
});
// Create the module for use as a dependency
const module_v1 = b.addModule("chibihash64_v1", .{
.root_source_file = .{ .cwd_relative = "src/chibihash64_v1.zig" },
});
const module_v2 = b.addModule("chibihash64_v2", .{
.root_source_file = .{ .cwd_relative = "src/chibihash64_v2.zig" },
});
_ = module_v1;
_ = module_v2;
// Install the library
b.installArtifact(lib_v1);
b.installArtifact(lib_v2);
// Create tests
const v1_tests = b.addTest(.{
.root_source_file = .{ .cwd_relative = "src/chibihash64_v1.zig" },
.target = target,
.optimize = optimize,
});
const v2_tests = b.addTest(.{
.root_source_file = .{ .cwd_relative = "src/chibihash64_v2.zig" },
.target = target,
.optimize = optimize,
});
const run_v1_tests = b.addRunArtifact(v1_tests);
const run_v2_tests = b.addRunArtifact(v2_tests);
// Create test steps
const test_step = b.step("test", "Run all library tests");
test_step.dependOn(&run_v1_tests.step);
test_step.dependOn(&run_v2_tests.step);
// Add documentation for both versions
const lib_v1_docs = b.addInstallDirectory(.{
.source_dir = lib_v1.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs/v1",
});
const lib_v2_docs = b.addInstallDirectory(.{
.source_dir = lib_v2.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs/v2",
});
const docs_step = b.step("docs", "Generate library documentation");
docs_step.dependOn(&lib_v1_docs.step);
docs_step.dependOn(&lib_v2_docs.step);
// Create example executable
const example = b.addExecutable(.{
.name = "example",
.root_source_file = .{ .cwd_relative = "example/example.zig" },
.target = target,
.optimize = optimize,
});
// Create modules
const chibihash64_v1 = b.addModule("chibihash64_v1", .{
.root_source_file = .{ .cwd_relative = "src/chibihash64_v1.zig" },
});
const chibihash64_v2 = b.addModule("chibihash64_v2", .{
.root_source_file = .{ .cwd_relative = "src/chibihash64_v2.zig" },
});
// Add module dependencies to example
example.root_module.addImport("chibihash64_v1", chibihash64_v1);
example.root_module.addImport("chibihash64_v2", chibihash64_v2);
// Install the example
b.installArtifact(example);
// Create a run step for the example
const run_example = b.addRunArtifact(example);
const run_step = b.step("run-example", "Run the example program");
run_step.dependOn(&run_example.step);
}