@@ -15,9 +15,21 @@ pub const Backend = enum {
15
15
wgpu ,
16
16
};
17
17
18
+ pub const SokolBuildOpts = struct {
19
+ zig_assert_hook : bool = false ,
20
+ zig_log_hook : bool = false ,
21
+ backend : Backend ,
22
+ };
23
+
18
24
// build sokol into a static library
19
- pub fn buildSokol (b : * Builder , target : CrossTarget , mode : Mode , backend : Backend , comptime prefix_path : []const u8 ) * LibExeObjStep {
20
- const lib = b .addStaticLibrary ("sokol" , null );
25
+ pub fn buildSokol (
26
+ b : * Builder ,
27
+ target : CrossTarget ,
28
+ mode : Mode ,
29
+ opts : SokolBuildOpts ,
30
+ comptime prefix_path : []const u8 ,
31
+ ) * LibExeObjStep {
32
+ const lib = b .addStaticLibrary ("sokol" , "src/sokol_zig_hooks.zig" );
21
33
lib .setBuildMode (mode );
22
34
lib .setTarget (target );
23
35
lib .linkLibC ();
@@ -31,7 +43,7 @@ pub fn buildSokol(b: *Builder, target: CrossTarget, mode: Mode, backend: Backend
31
43
"sokol_debugtext.c" ,
32
44
"sokol_shape.c" ,
33
45
};
34
- var _backend = backend ;
46
+ var _backend = opts . backend ;
35
47
if (_backend == .auto ) {
36
48
if (lib .target .isDarwin ()) { _backend = .metal ; }
37
49
else if (lib .target .isWindows ()) { _backend = .d3d11 ; }
@@ -46,10 +58,14 @@ pub fn buildSokol(b: *Builder, target: CrossTarget, mode: Mode, backend: Backend
46
58
.wgpu = > "-DSOKOL_WGPU" ,
47
59
else = > unreachable ,
48
60
};
61
+ const log_def = if (opts .zig_log_hook ) "-DSOKOL_ZIG_LOG_HOOK" else "" ;
62
+ const assert_def = if (opts .zig_assert_hook ) "-DSOKOL_ZIG_ASSERT_HOOK" else "" ;
63
+
49
64
if (lib .target .isDarwin ()) {
50
65
inline for (csources ) | csrc | {
51
- lib .addCSourceFile (sokol_path ++ csrc , &[_ ][]const u8 {"-ObjC" , "-DIMPL" , backend_option });
66
+ lib .addCSourceFile (sokol_path ++ csrc , &[_ ][]const u8 {"-ObjC" , "-DIMPL" , backend_option , log_def , assert_def });
52
67
}
68
+
53
69
lib .linkFramework ("Cocoa" );
54
70
lib .linkFramework ("QuartzCore" );
55
71
lib .linkFramework ("AudioToolbox" );
@@ -62,8 +78,9 @@ pub fn buildSokol(b: *Builder, target: CrossTarget, mode: Mode, backend: Backend
62
78
}
63
79
} else {
64
80
inline for (csources ) | csrc | {
65
- lib .addCSourceFile (sokol_path ++ csrc , &[_ ][]const u8 {"-DIMPL" , backend_option });
81
+ lib .addCSourceFile (sokol_path ++ csrc , &[_ ][]const u8 {"-DIMPL" , backend_option , log_def , assert_def });
66
82
}
83
+
67
84
if (lib .target .isLinux ()) {
68
85
lib .linkSystemLibrary ("X11" );
69
86
lib .linkSystemLibrary ("Xi" );
@@ -102,7 +119,7 @@ pub fn build(b: *Builder) void {
102
119
103
120
const target = b .standardTargetOptions (.{});
104
121
const mode = b .standardReleaseOptions ();
105
- const sokol = buildSokol (b , target , mode , backend , "" );
122
+ const sokol = buildSokol (b , target , mode , .{. backend = backend } , "" );
106
123
const examples = .{
107
124
"clear" ,
108
125
"triangle" ,
0 commit comments