forked from Lulzx/zpdf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
199 lines (163 loc) · 5.78 KB
/
build.zig
File metadata and controls
199 lines (163 loc) · 5.78 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Main library
const lib = b.addLibrary(.{
.linkage = .static,
.name = "zpdf",
.root_module = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
}),
});
b.installArtifact(lib);
// Shared library for Python bindings
const shared_lib = b.addLibrary(.{
.linkage = .dynamic,
.name = "zpdf",
.root_module = b.createModule(.{
.root_source_file = b.path("src/capi.zig"),
.target = target,
.optimize = optimize,
}),
});
b.installArtifact(shared_lib);
const shared_step = b.step("shared", "Build shared library for FFI");
shared_step.dependOn(&shared_lib.step);
// WebAssembly build
const wasm = b.addExecutable(.{
.name = "zpdf",
.root_module = b.createModule(.{
.root_source_file = b.path("src/wapi.zig"),
.target = b.resolveTargetQuery(.{
.cpu_arch = .wasm32,
.os_tag = .freestanding,
}),
.optimize = .ReleaseSmall,
}),
});
wasm.entry = .disabled;
wasm.rdynamic = true;
const wasm_step = b.step("wasm", "Build WebAssembly module");
const install_wasm = b.addInstallArtifact(wasm, .{});
wasm_step.dependOn(&install_wasm.step);
// CLI tool
const exe = b.addExecutable(.{
.name = "zpdf",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}),
});
b.installArtifact(exe);
// Run command
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the zpdf CLI");
run_step.dependOn(&run_cmd.step);
// Unit tests
const lib_unit_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
const simd_unit_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/simd.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_simd_unit_tests = b.addRunArtifact(simd_unit_tests);
const decompress_unit_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/decompress.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_decompress_unit_tests = b.addRunArtifact(decompress_unit_tests);
const parser_unit_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/parser.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_parser_unit_tests = b.addRunArtifact(parser_unit_tests);
const xref_unit_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/xref.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_xref_unit_tests = b.addRunArtifact(xref_unit_tests);
const encoding_unit_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/encoding.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_encoding_unit_tests = b.addRunArtifact(encoding_unit_tests);
const interpreter_unit_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/interpreter.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_interpreter_unit_tests = b.addRunArtifact(interpreter_unit_tests);
const testpdf_unit_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/testpdf.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_testpdf_unit_tests = b.addRunArtifact(testpdf_unit_tests);
const integration_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/integration_test.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_integration_tests = b.addRunArtifact(integration_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
test_step.dependOn(&run_simd_unit_tests.step);
test_step.dependOn(&run_decompress_unit_tests.step);
test_step.dependOn(&run_parser_unit_tests.step);
test_step.dependOn(&run_xref_unit_tests.step);
test_step.dependOn(&run_encoding_unit_tests.step);
test_step.dependOn(&run_interpreter_unit_tests.step);
test_step.dependOn(&run_testpdf_unit_tests.step);
test_step.dependOn(&run_integration_tests.step);
// Benchmark
const bench = b.addExecutable(.{
.name = "bench",
.root_module = b.createModule(.{
.root_source_file = b.path("src/bench.zig"),
.target = target,
.optimize = .ReleaseFast,
}),
});
const bench_cmd = b.addRunArtifact(bench);
bench_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
bench_cmd.addArgs(args);
}
const bench_step = b.step("bench", "Run benchmarks");
bench_step.dependOn(&bench_cmd.step);
}