-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
148 lines (127 loc) · 3.64 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
const std = @import("std");
pub fn build(b: *std.Build) void {
const options = .{
.target = b.standardTargetOptions(.{}),
.optimize = b.standardOptimizeOption(.{}),
};
//
// Module
//
// Dependencies
const box2d_dep = b.dependency("box2d", .{});
// Provide the (native) library as zig module.
const mod = b.addModule("zbox2d", .{
.root_source_file = b.path("src/root.zig"),
.target = options.target,
.optimize = options.optimize,
.link_libc = true,
});
for (box2d_include_paths) |include_path| {
mod.addIncludePath(box2d_dep.path(include_path));
}
for (box2d_source_files) |file| {
mod.addCSourceFile(.{
.file = box2d_dep.path(b.pathJoin(&.{ "src", file })),
});
}
//
// Example
//
// Dependencies
const raylib_dep = b.dependency("raylib-zig", .{});
// Provide an executable to run a basic box2d example.
const exe = b.addExecutable(.{
.name = "zbox2d-example",
.root_source_file = b.path("src/main.zig"),
.target = options.target,
.optimize = options.optimize,
});
// Add box2d include paths to a compile step.
// NOTE:
// This might be necessary in order to make ZLS happy and provide LSP support
// for native box2d symbols.
// Otherwise, ZLS will complain about missing headers included in this modules
// `root.zig`.
//
// If you're consuming this package in your own project, you can add the
// include paths from the dependency to your compile step to also have LSP
// support.
// The following example code shows how to do that:
// ```zig
// const zbox2d_dep = b.dependency("zbox2d", options);
// //...
// for (zbox2d_dep.module("zbox2d").include_dirs.items) |include_dir| {
// exe.addIncludePath(include_dir.path.dupe(b));
// }
// ```
for (box2d_include_paths) |include_path| {
exe.addIncludePath(box2d_dep.path(include_path));
}
exe.linkLibrary(raylib_dep.artifact("raylib"));
exe.root_module.addImport("zbox2d", mod);
exe.root_module.addImport("raylib", raylib_dep.module("raylib"));
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
//
// Unit tests
//
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
// Module unit tests.
const mod_unit_tests = b.addTest(.{
.root_source_file = b.path("src/root.zig"),
.target = options.target,
.optimize = options.optimize,
});
const run_mod_unit_tests = b.addRunArtifact(mod_unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_mod_unit_tests.step);
}
const box2d_include_paths = &[_][]const u8{
"src",
"include",
"extern/glad",
"extern/jsmn",
"extern/simde",
};
const box2d_source_files = &[_][]const u8{
"aabb.c",
"allocate.c",
"array.c",
"bitset.c",
"block_array.c",
"body.c",
"broad_phase.c",
"constraint_graph.c",
"contact.c",
"contact_solver.c",
"core.c",
"distance.c",
"distance_joint.c",
"dynamic_tree.c",
"geometry.c",
"hull.c",
"id_pool.c",
"island.c",
"joint.c",
"manifold.c",
"math_functions.c",
"motor_joint.c",
"mouse_joint.c",
"prismatic_joint.c",
"revolute_joint.c",
"shape.c",
"solver.c",
"solver_set.c",
"stack_allocator.c",
"table.c",
"timer.c",
"types.c",
"weld_joint.c",
"wheel_joint.c",
"world.c",
};