-
Notifications
You must be signed in to change notification settings - Fork 12
/
build.zig
85 lines (76 loc) · 2.94 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
const std = @import("std");
pub fn build(b: *std.Build) !void {
// Options
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const default_stack_size = b.option(usize, "libcoro_default_stack_size", "Default stack size for coroutines") orelse 1024 * 4;
const debug_log_level = b.option(usize, "libcoro_debug_log_level", "Debug log level for coroutines") orelse 0;
// Deps
const xev = b.dependency("libxev", .{}).module("xev");
// Module
const coro_options = b.addOptions();
coro_options.addOption(usize, "default_stack_size", default_stack_size);
coro_options.addOption(usize, "debug_log_level", debug_log_level);
const coro_options_module = coro_options.createModule();
const coro = b.addModule("libcoro", .{
.root_source_file = b.path("src/main.zig"),
.imports = &.{
.{ .name = "xev", .module = xev },
.{ .name = "libcoro_options", .module = coro_options_module },
},
});
{
const coro_test = b.addTest(.{
.name = "corotest",
.root_source_file = b.path("src/test.zig"),
.target = target,
.optimize = optimize,
});
coro_test.root_module.addImport("libcoro", coro);
coro_test.linkLibC();
const internal_test = b.addTest(.{
.name = "corotest-internal",
.root_source_file = b.path("src/coro.zig"),
.target = target,
.optimize = optimize,
});
internal_test.root_module.addImport("libcoro_options", coro_options_module);
internal_test.linkLibC();
// Test step
const test_step = b.step("test", "Run tests");
test_step.dependOn(&b.addRunArtifact(coro_test).step);
test_step.dependOn(&b.addRunArtifact(internal_test).step);
}
{
const aio_test = b.addTest(.{
.name = "aiotest",
.root_source_file = b.path("src/test_aio.zig"),
.target = target,
.optimize = optimize,
});
aio_test.root_module.addImport("libcoro", coro);
aio_test.root_module.addImport("xev", xev);
aio_test.linkLibC();
// Test step
const test_step = b.step("test-aio", "Run async io tests");
test_step.dependOn(&b.addRunArtifact(aio_test).step);
}
{
// Benchmark
const bench = b.addExecutable(.{
.name = "benchmark",
.root_source_file = b.path("benchmark.zig"),
.target = target,
.optimize = .ReleaseFast,
});
bench.root_module.addImport("libcoro", coro);
bench.linkLibC();
const bench_run = b.addRunArtifact(bench);
if (b.args) |args| {
bench_run.addArgs(args);
}
const bench_step = b.step("benchmark", "Run benchmark");
bench_step.dependOn(&bench_run.step);
bench_step.dependOn(&b.addInstallArtifact(bench, .{}).step);
}
}