forked from zig-gamedev/zig-gamedev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
288 lines (262 loc) · 12.8 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
const std = @import("std");
pub const Options = struct {
use_double_precision: bool = false,
enable_asserts: bool = false,
enable_cross_platform_determinism: bool = true,
enable_debug_renderer: bool = false,
};
pub const Package = struct {
options: Options,
zphysics: *std.Build.Module,
zphysics_options: *std.Build.Module,
zphysics_c_cpp: *std.Build.CompileStep,
pub fn link(pkg: Package, exe: *std.Build.CompileStep) void {
exe.addIncludePath(.{ .path = thisDir() ++ "/libs/JoltC" });
exe.linkLibrary(pkg.zphysics_c_cpp);
exe.addModule("zphysics", pkg.zphysics);
exe.addModule("zphysics_options", pkg.zphysics_options);
}
};
pub fn package(
b: *std.Build,
target: std.zig.CrossTarget,
optimize: std.builtin.Mode,
args: struct {
options: Options = .{},
},
) Package {
const step = b.addOptions();
step.addOption(bool, "use_double_precision", args.options.use_double_precision);
step.addOption(bool, "enable_asserts", args.options.enable_asserts);
step.addOption(bool, "enable_cross_platform_determinism", args.options.enable_cross_platform_determinism);
step.addOption(bool, "enable_debug_renderer", args.options.enable_debug_renderer);
const zphysics_options = step.createModule();
const zphysics = b.createModule(.{
.source_file = .{ .path = thisDir() ++ "/src/zphysics.zig" },
.dependencies = &.{
.{ .name = "zphysics_options", .module = zphysics_options },
},
});
const zphysics_c_cpp = b.addStaticLibrary(.{
.name = "zphysics",
.target = target,
.optimize = optimize,
});
const abi = (std.zig.system.NativeTargetInfo.detect(target) catch unreachable).target.abi;
zphysics_c_cpp.addIncludePath(.{ .path = thisDir() ++ "/libs" });
zphysics_c_cpp.addIncludePath(.{ .path = thisDir() ++ "/libs/JoltC" });
zphysics_c_cpp.linkLibC();
if (abi != .msvc)
zphysics_c_cpp.linkLibCpp();
const flags = &.{
"-std=c++17",
if (abi != .msvc) "-DJPH_COMPILER_MINGW" else "",
if (args.options.enable_cross_platform_determinism) "-DJPH_CROSS_PLATFORM_DETERMINISTIC" else "",
if (args.options.enable_debug_renderer) "-DJPH_DEBUG_RENDERER" else "",
if (args.options.use_double_precision) "-DJPH_DOUBLE_PRECISION" else "",
if (args.options.enable_asserts or zphysics_c_cpp.optimize == .Debug) "-DJPH_ENABLE_ASSERTS" else "",
"-fno-sanitize=undefined",
};
const src_dir = thisDir() ++ "/libs/Jolt";
zphysics_c_cpp.addCSourceFiles(&.{
thisDir() ++ "/libs/JoltC/JoltPhysicsC.cpp",
thisDir() ++ "/libs/JoltC/JoltPhysicsC_Extensions.cpp",
src_dir ++ "/AABBTree/AABBTreeBuilder.cpp",
src_dir ++ "/Core/Color.cpp",
src_dir ++ "/Core/Factory.cpp",
src_dir ++ "/Core/IssueReporting.cpp",
src_dir ++ "/Core/JobSystemThreadPool.cpp",
src_dir ++ "/Core/JobSystemWithBarrier.cpp",
src_dir ++ "/Core/LinearCurve.cpp",
src_dir ++ "/Core/Memory.cpp",
src_dir ++ "/Core/Profiler.cpp",
src_dir ++ "/Core/RTTI.cpp",
src_dir ++ "/Core/Semaphore.cpp",
src_dir ++ "/Core/StringTools.cpp",
src_dir ++ "/Core/TickCounter.cpp",
src_dir ++ "/Geometry/ConvexHullBuilder.cpp",
src_dir ++ "/Geometry/ConvexHullBuilder2D.cpp",
src_dir ++ "/Geometry/Indexify.cpp",
src_dir ++ "/Geometry/OrientedBox.cpp",
src_dir ++ "/Math/UVec4.cpp",
src_dir ++ "/Math/Vec3.cpp",
src_dir ++ "/ObjectStream/ObjectStream.cpp",
src_dir ++ "/ObjectStream/ObjectStreamBinaryIn.cpp",
src_dir ++ "/ObjectStream/ObjectStreamBinaryOut.cpp",
src_dir ++ "/ObjectStream/ObjectStreamIn.cpp",
src_dir ++ "/ObjectStream/ObjectStreamOut.cpp",
src_dir ++ "/ObjectStream/ObjectStreamTextIn.cpp",
src_dir ++ "/ObjectStream/ObjectStreamTextOut.cpp",
src_dir ++ "/ObjectStream/SerializableObject.cpp",
src_dir ++ "/ObjectStream/TypeDeclarations.cpp",
src_dir ++ "/Physics/Body/Body.cpp",
src_dir ++ "/Physics/Body/BodyAccess.cpp",
src_dir ++ "/Physics/Body/BodyCreationSettings.cpp",
src_dir ++ "/Physics/Body/BodyInterface.cpp",
src_dir ++ "/Physics/Body/BodyManager.cpp",
src_dir ++ "/Physics/Body/MassProperties.cpp",
src_dir ++ "/Physics/Body/MotionProperties.cpp",
src_dir ++ "/Physics/Character/Character.cpp",
src_dir ++ "/Physics/Character/CharacterBase.cpp",
src_dir ++ "/Physics/Character/CharacterVirtual.cpp",
src_dir ++ "/Physics/Collision/BroadPhase/BroadPhase.cpp",
src_dir ++ "/Physics/Collision/BroadPhase/BroadPhaseBruteForce.cpp",
src_dir ++ "/Physics/Collision/BroadPhase/BroadPhaseQuadTree.cpp",
src_dir ++ "/Physics/Collision/BroadPhase/QuadTree.cpp",
src_dir ++ "/Physics/Collision/CastConvexVsTriangles.cpp",
src_dir ++ "/Physics/Collision/CastSphereVsTriangles.cpp",
src_dir ++ "/Physics/Collision/CollideConvexVsTriangles.cpp",
src_dir ++ "/Physics/Collision/CollideSphereVsTriangles.cpp",
src_dir ++ "/Physics/Collision/CollisionDispatch.cpp",
src_dir ++ "/Physics/Collision/CollisionGroup.cpp",
src_dir ++ "/Physics/Collision/GroupFilter.cpp",
src_dir ++ "/Physics/Collision/GroupFilterTable.cpp",
src_dir ++ "/Physics/Collision/ManifoldBetweenTwoFaces.cpp",
src_dir ++ "/Physics/Collision/NarrowPhaseQuery.cpp",
src_dir ++ "/Physics/Collision/NarrowPhaseStats.cpp",
src_dir ++ "/Physics/Collision/PhysicsMaterial.cpp",
src_dir ++ "/Physics/Collision/PhysicsMaterialSimple.cpp",
src_dir ++ "/Physics/Collision/Shape/BoxShape.cpp",
src_dir ++ "/Physics/Collision/Shape/CapsuleShape.cpp",
src_dir ++ "/Physics/Collision/Shape/CompoundShape.cpp",
src_dir ++ "/Physics/Collision/Shape/ConvexHullShape.cpp",
src_dir ++ "/Physics/Collision/Shape/ConvexShape.cpp",
src_dir ++ "/Physics/Collision/Shape/CylinderShape.cpp",
src_dir ++ "/Physics/Collision/Shape/DecoratedShape.cpp",
src_dir ++ "/Physics/Collision/Shape/HeightFieldShape.cpp",
src_dir ++ "/Physics/Collision/Shape/MeshShape.cpp",
src_dir ++ "/Physics/Collision/Shape/MutableCompoundShape.cpp",
src_dir ++ "/Physics/Collision/Shape/OffsetCenterOfMassShape.cpp",
src_dir ++ "/Physics/Collision/Shape/RotatedTranslatedShape.cpp",
src_dir ++ "/Physics/Collision/Shape/ScaledShape.cpp",
src_dir ++ "/Physics/Collision/Shape/Shape.cpp",
src_dir ++ "/Physics/Collision/Shape/SphereShape.cpp",
src_dir ++ "/Physics/Collision/Shape/StaticCompoundShape.cpp",
src_dir ++ "/Physics/Collision/Shape/TaperedCapsuleShape.cpp",
src_dir ++ "/Physics/Collision/Shape/TriangleShape.cpp",
src_dir ++ "/Physics/Collision/TransformedShape.cpp",
src_dir ++ "/Physics/Constraints/ConeConstraint.cpp",
src_dir ++ "/Physics/Constraints/Constraint.cpp",
src_dir ++ "/Physics/Constraints/ConstraintManager.cpp",
src_dir ++ "/Physics/Constraints/ContactConstraintManager.cpp",
src_dir ++ "/Physics/Constraints/DistanceConstraint.cpp",
src_dir ++ "/Physics/Constraints/FixedConstraint.cpp",
src_dir ++ "/Physics/Constraints/GearConstraint.cpp",
src_dir ++ "/Physics/Constraints/HingeConstraint.cpp",
src_dir ++ "/Physics/Constraints/MotorSettings.cpp",
src_dir ++ "/Physics/Constraints/PathConstraint.cpp",
src_dir ++ "/Physics/Constraints/PathConstraintPath.cpp",
src_dir ++ "/Physics/Constraints/PathConstraintPathHermite.cpp",
src_dir ++ "/Physics/Constraints/PointConstraint.cpp",
src_dir ++ "/Physics/Constraints/RackAndPinionConstraint.cpp",
src_dir ++ "/Physics/Constraints/SixDOFConstraint.cpp",
src_dir ++ "/Physics/Constraints/SliderConstraint.cpp",
src_dir ++ "/Physics/Constraints/SwingTwistConstraint.cpp",
src_dir ++ "/Physics/Constraints/TwoBodyConstraint.cpp",
src_dir ++ "/Physics/Constraints/PulleyConstraint.cpp",
src_dir ++ "/Physics/DeterminismLog.cpp",
src_dir ++ "/Physics/IslandBuilder.cpp",
src_dir ++ "/Physics/LargeIslandSplitter.cpp",
src_dir ++ "/Physics/PhysicsScene.cpp",
src_dir ++ "/Physics/PhysicsSystem.cpp",
src_dir ++ "/Physics/PhysicsUpdateContext.cpp",
src_dir ++ "/Physics/PhysicsLock.cpp",
src_dir ++ "/Physics/Ragdoll/Ragdoll.cpp",
src_dir ++ "/Physics/StateRecorderImpl.cpp",
src_dir ++ "/Physics/Vehicle/TrackedVehicleController.cpp",
src_dir ++ "/Physics/Vehicle/VehicleAntiRollBar.cpp",
src_dir ++ "/Physics/Vehicle/VehicleCollisionTester.cpp",
src_dir ++ "/Physics/Vehicle/VehicleConstraint.cpp",
src_dir ++ "/Physics/Vehicle/VehicleController.cpp",
src_dir ++ "/Physics/Vehicle/VehicleDifferential.cpp",
src_dir ++ "/Physics/Vehicle/VehicleEngine.cpp",
src_dir ++ "/Physics/Vehicle/VehicleTrack.cpp",
src_dir ++ "/Physics/Vehicle/VehicleTransmission.cpp",
src_dir ++ "/Physics/Vehicle/Wheel.cpp",
src_dir ++ "/Physics/Vehicle/WheeledVehicleController.cpp",
src_dir ++ "/Physics/Vehicle/MotorcycleController.cpp",
src_dir ++ "/RegisterTypes.cpp",
src_dir ++ "/Renderer/DebugRenderer.cpp",
src_dir ++ "/Renderer/DebugRendererPlayback.cpp",
src_dir ++ "/Renderer/DebugRendererRecorder.cpp",
src_dir ++ "/Skeleton/SkeletalAnimation.cpp",
src_dir ++ "/Skeleton/Skeleton.cpp",
src_dir ++ "/Skeleton/SkeletonMapper.cpp",
src_dir ++ "/Skeleton/SkeletonPose.cpp",
src_dir ++ "/TriangleGrouper/TriangleGrouperClosestCentroid.cpp",
src_dir ++ "/TriangleGrouper/TriangleGrouperMorton.cpp",
src_dir ++ "/TriangleSplitter/TriangleSplitter.cpp",
src_dir ++ "/TriangleSplitter/TriangleSplitterBinning.cpp",
src_dir ++ "/TriangleSplitter/TriangleSplitterFixedLeafSize.cpp",
src_dir ++ "/TriangleSplitter/TriangleSplitterLongestAxis.cpp",
src_dir ++ "/TriangleSplitter/TriangleSplitterMean.cpp",
src_dir ++ "/TriangleSplitter/TriangleSplitterMorton.cpp",
}, flags);
return .{
.options = args.options,
.zphysics = zphysics,
.zphysics_options = zphysics_options,
.zphysics_c_cpp = zphysics_c_cpp,
};
}
pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});
const test_step = b.step("test", "Run zphysics tests");
test_step.dependOn(runTests(b, optimize, target));
}
pub fn runTests(
b: *std.Build,
optimize: std.builtin.Mode,
target: std.zig.CrossTarget,
) *std.Build.Step {
const parent_step = b.allocator.create(std.Build.Step) catch @panic("OOM");
parent_step.* = std.Build.Step.init(.{ .id = .custom, .name = "zphysics-tests", .owner = b });
const test0 = testStep(b, "zphysics-tests-f32", optimize, target, .{
.use_double_precision = false,
.enable_debug_renderer = true,
});
parent_step.dependOn(&test0.step);
// const test1 = testStep(b, "zphysics-tests-f64", optimize, target, .{
// .use_double_precision = true,
// .enable_debug_renderer = true,
// });
// parent_step.dependOn(&test1.step);
return parent_step;
}
fn testStep(
b: *std.Build,
name: []const u8,
optimize: std.builtin.Mode,
target: std.zig.CrossTarget,
options: Options,
) *std.Build.RunStep {
const test_exe = b.addTest(.{
.name = name,
.root_source_file = .{ .path = thisDir() ++ "/src/zphysics.zig" },
.target = target,
.optimize = optimize,
});
// TODO: Problems with LTO on Windows.
test_exe.want_lto = false;
const abi = (std.zig.system.NativeTargetInfo.detect(target) catch unreachable).target.abi;
test_exe.addCSourceFile(.{
.file = .{ .path = thisDir() ++ "/libs/JoltC/JoltPhysicsC_Tests.c" },
.flags = &.{
"-std=c11",
if (abi != .msvc) "-DJPH_COMPILER_MINGW" else "",
if (options.use_double_precision) "-DJPH_DOUBLE_PRECISION" else "",
if (options.enable_asserts or optimize == .Debug) "-DJPH_ENABLE_ASSERTS" else "",
if (options.enable_cross_platform_determinism) "-DJPH_CROSS_PLATFORM_DETERMINISTIC" else "",
if (options.enable_debug_renderer) "-DJPH_DEBUG_RENDERER" else "",
"-fno-sanitize=undefined",
},
});
const zphysics_pkg = package(b, target, optimize, .{ .options = options });
zphysics_pkg.link(test_exe);
test_exe.addModule("zphysics_options", zphysics_pkg.zphysics_options);
return b.addRunArtifact(test_exe);
}
inline fn thisDir() []const u8 {
return comptime std.fs.path.dirname(@src().file) orelse ".";
}