-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbuild.zig
52 lines (47 loc) · 1.58 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
const std = @import("std");
const builtin = @import("builtin");
pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});
const opt_use_shared = b.option(bool, "shared", "Make shared (default: false)") orelse false;
_ = b.addModule("root", .{
.root_source_file = b.path("src/zflecs.zig"),
});
const flecs = if (opt_use_shared) b.addSharedLibrary(.{
.name = "flecs",
.target = target,
.optimize = optimize,
}) else b.addStaticLibrary(.{
.name = "flecs",
.target = target,
.optimize = optimize,
});
flecs.linkLibC();
flecs.addIncludePath(b.path("libs/flecs"));
flecs.addCSourceFile(.{
.file = b.path("libs/flecs/flecs.c"),
.flags = &.{
"-fno-sanitize=undefined",
"-DFLECS_NO_CPP",
"-DFLECS_USE_OS_ALLOC",
if (builtin.mode == .Debug) "-DFLECS_SANITIZE" else "",
if (opt_use_shared) "-DFLECS_SHARED" else "",
},
});
b.installArtifact(flecs);
if (target.result.os.tag == .windows) {
flecs.linkSystemLibrary("ws2_32");
}
const test_step = b.step("test", "Run zflecs tests");
const tests = b.addTest(.{
.name = "zflecs-tests",
.root_source_file = b.path("src/tests.zig"),
.target = target,
.optimize = optimize,
});
tests.linkLibC();
tests.addIncludePath(b.path("libs/flecs"));
b.installArtifact(tests);
tests.linkLibrary(flecs);
test_step.dependOn(&b.addRunArtifact(tests).step);
}