-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild.zig
93 lines (75 loc) · 2.95 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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const zzz = b.addModule("zzz", .{
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
});
const tardy = b.dependency("tardy", .{
.target = target,
.optimize = optimize,
}).module("tardy");
zzz.addImport("tardy", tardy);
const bearssl = b.dependency("bearssl", .{
.target = target,
.optimize = optimize,
// Without this, you get an illegal instruction error on certain paths.
// This makes it slightly slower but prevents faults.
.BR_LE_UNALIGNED = false,
.BR_BE_UNALIGNED = false,
}).artifact("bearssl");
zzz.linkLibrary(bearssl);
add_example(b, "basic", false, target, optimize, zzz);
add_example(b, "sse", false, target, optimize, zzz);
add_example(b, "tls", true, target, optimize, zzz);
add_example(b, "minram", false, target, optimize, zzz);
add_example(b, "fs", false, target, optimize, zzz);
add_example(b, "middleware", false, target, optimize, zzz);
add_example(b, "multithread", false, target, optimize, zzz);
add_example(b, "benchmark", false, target, optimize, zzz);
add_example(b, "valgrind", true, target, optimize, zzz);
if (target.result.os.tag != .windows) {
add_example(b, "unix", false, target, optimize, zzz);
}
const tests = b.addTest(.{
.name = "unit-test",
.root_source_file = b.path("./src/unit_test.zig"),
});
tests.root_module.addImport("tardy", tardy);
tests.root_module.linkLibrary(bearssl);
const run_test = b.addRunArtifact(tests);
run_test.step.dependOn(&tests.step);
const test_step = b.step("test", "Run general unit tests");
test_step.dependOn(&run_test.step);
}
fn add_example(
b: *std.Build,
name: []const u8,
link_libc: bool,
target: std.Build.ResolvedTarget,
optimize: std.builtin.Mode,
zzz_module: *std.Build.Module,
) void {
const example = b.addExecutable(.{
.name = name,
.root_source_file = b.path(b.fmt("./examples/{s}/main.zig", .{name})),
.target = target,
.optimize = optimize,
.strip = false,
});
if (link_libc) {
example.linkLibC();
}
example.root_module.addImport("zzz", zzz_module);
const install_artifact = b.addInstallArtifact(example, .{});
b.getInstallStep().dependOn(&install_artifact.step);
const build_step = b.step(b.fmt("{s}", .{name}), b.fmt("Build zzz example ({s})", .{name}));
build_step.dependOn(&install_artifact.step);
const run_artifact = b.addRunArtifact(example);
run_artifact.step.dependOn(&install_artifact.step);
const run_step = b.step(b.fmt("run_{s}", .{name}), b.fmt("Run zzz example ({s})", .{name}));
run_step.dependOn(&install_artifact.step);
run_step.dependOn(&run_artifact.step);
}