11const std = @import ("std" );
22
3+ fn addMacros (module : * std.Build.Module , options : anytype ) void {
4+ if (options .enable_cross_platform_determinism )
5+ module .addCMacro ("JPH_CROSS_PLATFORM_DETERMINISTIC" , "" );
6+ if (options .enable_debug_renderer )
7+ module .addCMacro ("JPH_DEBUG_RENDERER" , "" );
8+ if (options .use_double_precision )
9+ module .addCMacro ("JPH_DOUBLE_PRECISION" , "" );
10+ if (options .enable_asserts )
11+ module .addCMacro ("JPH_ENABLE_ASSERTS" , "" );
12+ }
13+
314pub fn build (b : * std.Build ) void {
415 const optimize = b .standardOptimizeOption (.{});
516 const target = b .standardTargetOptions (.{});
@@ -58,21 +69,18 @@ pub fn build(b: *std.Build) void {
5869 });
5970 zjolt .addIncludePath (b .path ("libs/JoltC" ));
6071
61- const joltc = if (options .shared ) blk : {
62- const lib = b .addSharedLibrary (.{
63- .name = "joltc" ,
72+ const joltc = b .addLibrary (.{
73+ .name = "joltc" ,
74+ .linkage = if (options .shared ) .dynamic else .static ,
75+ .root_module = b .createModule (.{
6476 .target = target ,
6577 .optimize = optimize ,
66- });
67- if (target .result .os .tag == .windows ) {
68- lib .root_module .addCMacro ("JPC_API" , "extern __declspec(dllexport)" );
69- }
70- break :blk lib ;
71- } else b .addStaticLibrary (.{
72- .name = "joltc" ,
73- .target = target ,
74- .optimize = optimize ,
78+ }),
7579 });
80+
81+ if (options .shared and target .result .os .tag == .windows )
82+ joltc .root_module .addCMacro ("JPC_API" , "extern __declspec(dllexport)" );
83+
7684 b .installArtifact (joltc );
7785
7886 joltc .addIncludePath (b .path ("libs" ));
@@ -87,15 +95,12 @@ pub fn build(b: *std.Build) void {
8795 const src_dir = "libs/Jolt" ;
8896 const c_flags = &.{
8997 "-std=c++17" ,
90- if (options .enable_cross_platform_determinism ) "-DJPH_CROSS_PLATFORM_DETERMINISTIC" else "" ,
91- if (options .enable_debug_renderer ) "-DJPH_DEBUG_RENDERER" else "" ,
92- if (options .use_double_precision ) "-DJPH_DOUBLE_PRECISION" else "" ,
93- if (options .enable_asserts ) "-DJPH_ENABLE_ASSERTS" else "" ,
9498 if (options .no_exceptions ) "-fno-exceptions" else "" ,
9599 "-fno-access-control" ,
96100 "-fno-sanitize=undefined" ,
97101 };
98102
103+ addMacros (joltc .root_module , options );
99104 joltc .addCSourceFiles (.{
100105 .files = &.{
101106 "libs/JoltC/JoltPhysicsC.cpp" ,
@@ -248,9 +253,11 @@ pub fn build(b: *std.Build) void {
248253
249254 const tests = b .addTest (.{
250255 .name = "zphysics-tests" ,
251- .root_source_file = b .path ("src/zphysics.zig" ),
252- .target = target ,
253- .optimize = optimize ,
256+ .root_module = b .createModule (.{
257+ .root_source_file = b .path ("src/zphysics.zig" ),
258+ .target = target ,
259+ .optimize = optimize ,
260+ }),
254261 });
255262 b .installArtifact (tests );
256263
@@ -259,17 +266,17 @@ pub fn build(b: *std.Build) void {
259266 tests .want_lto = false ;
260267 }
261268
269+ addMacros (tests .root_module , options );
262270 tests .addCSourceFile (.{
263271 .file = b .path ("libs/JoltC/JoltPhysicsC_Tests.c" ),
264272 .flags = &.{
265- if (options .enable_cross_platform_determinism ) "-DJPH_CROSS_PLATFORM_DETERMINISTIC" else "" ,
266- if (options .enable_debug_renderer ) "-DJPH_DEBUG_RENDERER" else "" ,
267- if (options .use_double_precision ) "-DJPH_DOUBLE_PRECISION" else "" ,
268- if (options .enable_asserts ) "-DJPH_ENABLE_ASSERTS" else "" ,
269273 "-fno-sanitize=undefined" ,
270274 },
271275 });
272276
277+ if (b .option (bool , "verbose" , "Print verbose test debug output to stderr" ) orelse false )
278+ tests .root_module .addCMacro ("PRINT_OUTPUT" , "" );
279+
273280 tests .root_module .addImport ("zphysics_options" , options_module );
274281 tests .addIncludePath (b .path ("libs/JoltC" ));
275282 tests .linkLibrary (joltc );
0 commit comments