-
Notifications
You must be signed in to change notification settings - Fork 22
/
build.zig
72 lines (61 loc) · 1.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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
if (@hasDecl(std.Build, "CreateModuleOptions")) {
// Zig 0.11
_ = b.addModule("regex", .{
.source_file = .{ .path = "src/regex.zig" },
});
} else {
// Zig 0.12-dev.2159
_ = b.addModule("regex", .{
.root_source_file = .{ .path = "src/regex.zig" },
});
}
// library tests
const library_tests = b.addTest(.{
.root_source_file = .{ .path = "src/all_test.zig" },
.target = target,
.optimize = optimize,
});
const run_library_tests = b.addRunArtifact(library_tests);
const test_step = b.step("test", "Run all tests");
test_step.dependOn(&run_library_tests.step);
// C library
const staticLib = b.addStaticLibrary(.{
.name = "regex",
.root_source_file = .{ .path = "src/c_regex.zig" },
.target = target,
.optimize = optimize,
});
staticLib.linkLibC();
b.installArtifact(staticLib);
const sharedLib = b.addSharedLibrary(.{
.name = "regex",
.root_source_file = .{ .path = "src/c_regex.zig" },
.target = target,
.optimize = optimize,
});
sharedLib.linkLibC();
b.installArtifact(sharedLib);
// C example
const c_example = b.addExecutable(.{
.name = "example",
.target = target,
.optimize = optimize,
});
c_example.addCSourceFile(.{
.file = .{
.path = "example/example.c",
},
.flags = &.{"-Wall"},
});
c_example.addIncludePath(.{ .path = "include" });
c_example.linkLibC();
c_example.linkLibrary(staticLib);
const c_example_step = b.step("c-example", "Example using C API");
c_example_step.dependOn(&staticLib.step);
c_example_step.dependOn(&c_example.step);
b.default_step.dependOn(test_step);
}