forked from truemedian/zig-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
102 lines (79 loc) · 3.14 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
100
101
102
const std = @import("std");
const Builder = std.Build;
const tests = .{
"read_zip",
"write_zip",
};
const bench = .{
"bench_zip",
};
pub fn addArchive(b: *Builder, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode) *std.Build.CompileStep {
const archive = b.addStaticLibrary(.{
.root_source_file = b.path("src/main.zig"),
.name = "archive",
.target = target,
.optimize = optimize,
});
return archive;
}
pub fn addModuleArchive(b: *Builder, step: *Builder.CompileStep) void {
const archive_module = b.addModule("archive", .{
.source_file = b.path("zig-archive/src/main.zig"),
});
step.addModule("archive", archive_module);
}
pub fn build(b: *Builder) void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});
const archive_module = b.addModule("archive", .{
.root_source_file = b.path("src/main.zig"),
});
// Library Tests
const lib_tests = b.addTest(.{
.root_source_file = b.path("src/main.zig"),
.optimize = optimize,
.target = target,
});
const lib_tests_step = b.step("test", "Run all library tests");
lib_tests_step.dependOn(&lib_tests.step);
const docs = b.option(bool, "emit_docs", "Build library documentation") orelse false;
if (docs)
_ = lib_tests.getEmittedDocs();
// Test Runners
inline for (tests) |file| {
const zip_runner = b.addExecutable(.{
.name = file,
.target = target,
.root_source_file = b.path("tests/" ++ file ++ ".zig"),
.optimize = optimize,
});
zip_runner.linkLibC();
zip_runner.root_module.addImport("archive", archive_module);
b.installArtifact(zip_runner);
const run_zip_runner = b.addRunArtifact(zip_runner);
const run_tests = b.step(file, "Run tests");
run_tests.dependOn(&run_zip_runner.step);
}
// Benchmarks
const preallocate = b.option(bool, "preallocate", "Allocate the file into memory rather than reading from disk [true].") orelse true;
const void_write = b.option(bool, "void_write", "Write to a void file rather than a real file when extracting [true].") orelse true;
const runtime = b.option(u32, "runtime", "How long to run benchmarks in seconds [60].") orelse 60;
const bench_options = b.addOptions();
bench_options.addOption(bool, "preallocate", preallocate);
bench_options.addOption(bool, "void_write", void_write);
bench_options.addOption(u32, "runtime", runtime);
inline for (bench) |file| {
const zip_bench = b.addExecutable(.{
.name = file,
.root_source_file = b.path("tests/" ++ file ++ ".zig"),
.target = target,
.optimize = optimize,
});
zip_bench.root_module.addOptions("build_options", bench_options);
zip_bench.root_module.addImport("archive", archive_module);
b.installArtifact(zip_bench);
const run_zip_bench = b.addRunArtifact(zip_bench);
const zip_bench_step = b.step(file, "Run benchmark");
zip_bench_step.dependOn(&run_zip_bench.step);
}
}