@@ -91,20 +91,24 @@ pub fn buildLibSokol(b: *Build, options: LibSokolOptions) !*CompileStep {
91
91
}
92
92
93
93
// resolve .auto backend into specific backend by platform
94
+ var cflags = try std .BoundedArray ([]const u8 , 64 ).init (0 );
95
+ try cflags .append ("-DIMPL" );
96
+ if (options .optimize != .Debug ) {
97
+ try cflags .append ("-DNDEBUG" );
98
+ }
94
99
const backend = resolveSokolBackend (options .backend , lib .rootModuleTarget ());
95
- const backend_cflags = switch (backend ) {
96
- .d3d11 = > "-DSOKOL_D3D11" ,
97
- .metal = > "-DSOKOL_METAL" ,
98
- .gl = > "-DSOKOL_GLCORE" ,
99
- .gles3 = > "-DSOKOL_GLES3" ,
100
- .wgpu = > "-DSOKOL_WGPU" ,
100
+ switch (backend ) {
101
+ .d3d11 = > try cflags . append ( "-DSOKOL_D3D11" ) ,
102
+ .metal = > try cflags . append ( "-DSOKOL_METAL" ) ,
103
+ .gl = > try cflags . append ( "-DSOKOL_GLCORE" ) ,
104
+ .gles3 = > try cflags . append ( "-DSOKOL_GLES3" ) ,
105
+ .wgpu = > try cflags . append ( "-DSOKOL_WGPU" ) ,
101
106
else = > @panic ("unknown sokol backend" ),
102
- };
107
+ }
103
108
104
109
// platform specific compile and link options
105
- var cflags : []const []const u8 = &.{ "-DIMPL" , backend_cflags };
106
110
if (lib .rootModuleTarget ().isDarwin ()) {
107
- cflags = &.{ "-ObjC" , "-DIMPL" , backend_cflags } ;
111
+ try cflags . append ( "-ObjC" ) ;
108
112
lib .linkFramework ("Foundation" );
109
113
lib .linkFramework ("AudioToolbox" );
110
114
if (.metal == backend ) {
@@ -134,11 +138,10 @@ pub fn buildLibSokol(b: *Build, options: LibSokolOptions) !*CompileStep {
134
138
lib .linkSystemLibrary ("android" );
135
139
lib .linkSystemLibrary ("log" );
136
140
} else if (lib .rootModuleTarget ().os .tag == .linux ) {
137
- const egl_cflags = if (options .use_egl ) "-DSOKOL_FORCE_EGL " else "" ;
138
- const x11_cflags = if (! options .use_x11 ) "-DSOKOL_DISABLE_X11 " else "" ;
139
- const wayland_cflags = if (! options .use_wayland ) "-DSOKOL_DISABLE_WAYLAND" else "" ;
141
+ if (options .use_egl ) try cflags . append ( "-DSOKOL_FORCE_EGL" ) ;
142
+ if (! options .use_x11 ) try cflags . append ( "-DSOKOL_DISABLE_X11" ) ;
143
+ if (! options .use_wayland ) try cflags . append ( "-DSOKOL_DISABLE_WAYLAND" ) ;
140
144
const link_egl = options .use_egl or options .use_wayland ;
141
- cflags = &.{ "-DIMPL" , backend_cflags , egl_cflags , x11_cflags , wayland_cflags };
142
145
lib .linkSystemLibrary ("asound" );
143
146
lib .linkSystemLibrary ("GL" );
144
147
if (options .use_x11 ) {
@@ -153,7 +156,7 @@ pub fn buildLibSokol(b: *Build, options: LibSokolOptions) !*CompileStep {
153
156
lib .linkSystemLibrary ("xkbcommon" );
154
157
}
155
158
if (link_egl ) {
156
- lib .linkSystemLibrary ("egl " );
159
+ lib .linkSystemLibrary ("EGL " );
157
160
}
158
161
} else if (lib .rootModuleTarget ().os .tag == .windows ) {
159
162
lib .linkSystemLibrary ("kernel32" );
@@ -166,44 +169,45 @@ pub fn buildLibSokol(b: *Build, options: LibSokolOptions) !*CompileStep {
166
169
}
167
170
}
168
171
169
- // finally add the C source files
170
172
const csrc_root = "src/sokol/c/" ;
171
173
const csources = [_ ][]const u8 {
172
- csrc_root ++ "sokol_log.c" ,
173
- csrc_root ++ "sokol_app.c" ,
174
- csrc_root ++ "sokol_gfx.c" ,
175
- csrc_root ++ "sokol_time.c" ,
176
- csrc_root ++ "sokol_audio.c" ,
177
- csrc_root ++ "sokol_gl.c" ,
178
- csrc_root ++ "sokol_debugtext.c" ,
179
- csrc_root ++ "sokol_shape.c" ,
180
- csrc_root ++ "sokol_fetch .c" ,
181
- csrc_root ++ "sokol_glue .c" ,
182
- csrc_root ++ "sokol_memtrack.c" ,
174
+ "sokol_log.c" ,
175
+ "sokol_app.c" ,
176
+ "sokol_gfx.c" ,
177
+ "sokol_time.c" ,
178
+ "sokol_audio.c" ,
179
+ "sokol_gl.c" ,
180
+ "sokol_debugtext.c" ,
181
+ "sokol_shape.c" ,
182
+ "sokol_glue .c" ,
183
+ "sokol_fetch .c" ,
184
+ "sokol_memtrack.c" ,
183
185
};
184
- for (csources ) | csrc | {
186
+
187
+ // finally add the C source files
188
+ inline for (csources ) | csrc | {
185
189
lib .addCSourceFile (.{
186
- .file = b .path (csrc ),
187
- .flags = cflags ,
190
+ .file = b .path (csrc_root ++ csrc ),
191
+ .flags = cflags . slice () ,
188
192
});
189
193
}
190
194
191
195
if (options .with_sokol_imgui ) {
192
196
lib .addCSourceFile (.{
193
197
.file = b .path (csrc_root ++ "sokol_imgui.c" ),
194
- .flags = cflags ,
198
+ .flags = cflags . slice () ,
195
199
});
196
- const cimgui = try buildImgui (b , .{
200
+ const imgui = try buildImgui (b , .{
197
201
.target = options .target ,
198
202
.optimize = options .optimize ,
199
203
.emsdk = options .emsdk ,
200
204
.use_tsan = lib .root_module .sanitize_thread orelse false ,
201
205
.use_ubsan = lib .root_module .sanitize_c orelse false ,
202
206
});
203
- for (cimgui .root_module .include_dirs .items ) | dir | {
207
+ for (imgui .root_module .include_dirs .items ) | dir | {
204
208
try lib .root_module .include_dirs .append (b .allocator , dir );
205
209
}
206
- lib .linkLibrary (cimgui );
210
+ lib .linkLibrary (imgui );
207
211
}
208
212
return lib ;
209
213
}
@@ -320,7 +324,10 @@ pub fn ldcBuildStep(b: *Build, options: DCompileStep) !*std.Build.Step.InstallDi
320
324
// set kind of build
321
325
switch (options .kind ) {
322
326
.@"test" = > {
323
- ldc_exec .addArgs (&.{ "-unittest" , "-main" });
327
+ ldc_exec .addArgs (&.{
328
+ "-unittest" ,
329
+ "-main" ,
330
+ });
324
331
},
325
332
.obj = > ldc_exec .addArg ("-c" ),
326
333
else = > {},
@@ -367,27 +374,45 @@ pub fn ldcBuildStep(b: *Build, options: DCompileStep) !*std.Build.Step.InstallDi
367
374
if (options .betterC )
368
375
ldc_exec .addArg ("-betterC" );
369
376
377
+ // verbose error messages
378
+ ldc_exec .addArg ("-verrors=context" );
379
+
370
380
switch (options .optimize ) {
371
381
.Debug = > {
372
- ldc_exec .addArg ("-debug" );
373
- ldc_exec .addArg ("-d-debug" );
374
- ldc_exec .addArg ("-gc" ); // debuginfo for non D dbg
375
- ldc_exec .addArg ("-g" ); // debuginfo for D dbg
376
- ldc_exec .addArg ("-gf" );
377
- ldc_exec .addArg ("-gs" );
378
- ldc_exec .addArg ("-vgc" );
379
- ldc_exec .addArg ("-vtls" );
380
- ldc_exec .addArg ("-verrors=context" );
381
- ldc_exec .addArg ("-boundscheck=on" );
382
+ ldc_exec .addArgs (&.{
383
+ "-debug" ,
384
+ "-d-debug" ,
385
+ "--gc" ,
386
+ "-g" ,
387
+ "-gf" ,
388
+ "-gs" ,
389
+ "-vgc" ,
390
+ "-vtls" ,
391
+ "-boundscheck=on" ,
392
+ "--link-debuglib" ,
393
+ });
382
394
},
383
395
.ReleaseSafe = > {
384
- ldc_exec .addArgs (&.{ "-O2" , "-boundscheck=safeonly" });
396
+ ldc_exec .addArgs (&.{
397
+ "-O" ,
398
+ "-boundscheck=safeonly" ,
399
+ });
385
400
},
386
401
.ReleaseFast = > {
387
- ldc_exec .addArgs (&.{ "-O3" , "-boundscheck=off" , "--enable-asserts=false" });
402
+ ldc_exec .addArgs (&.{
403
+ "-O" ,
404
+ "-boundscheck=off" ,
405
+ "--enable-asserts=false" ,
406
+ "--strip-debug" ,
407
+ });
388
408
},
389
409
.ReleaseSmall = > {
390
- ldc_exec .addArgs (&.{ "-Oz" , "-boundscheck=off" , "--enable-asserts=false" });
410
+ ldc_exec .addArgs (&.{
411
+ "-Oz" ,
412
+ "-boundscheck=off" ,
413
+ "--enable-asserts=false" ,
414
+ "--strip-debug" ,
415
+ });
391
416
},
392
417
}
393
418
@@ -422,7 +447,7 @@ pub fn ldcBuildStep(b: *Build, options: DCompileStep) !*std.Build.Step.InstallDi
422
447
"-i=sokol" ,
423
448
"-i=shaders" ,
424
449
"-i=handmade" ,
425
- "-i=cimgui " ,
450
+ "-i=imgui " ,
426
451
});
427
452
428
453
// sokol include path
@@ -507,6 +532,13 @@ pub fn ldcBuildStep(b: *Build, options: DCompileStep) !*std.Build.Step.InstallDi
507
532
\\
508
533
\\ pragma(printf)
509
534
\\ int fprintf(FILE* __restrict, scope const(char)* __restrict, scope...) @nogc nothrow;
535
+ \\
536
+ \\ // boundchecking
537
+ \\ void _d_arraybounds_index(string file, uint line, size_t index, size_t length) @nogc nothrow
538
+ \\ {
539
+ \\ if (index >= length)
540
+ \\ __assert("Array index out of bounds".ptr, file.ptr, line);
541
+ \\ }
510
542
\\ }
511
543
,
512
544
),
@@ -1148,9 +1180,22 @@ fn buildImgui(b: *Build, options: libImGuiOptions) !*CompileStep {
1148
1180
libimgui .root_module .sanitize_c = options .use_ubsan ;
1149
1181
libimgui .root_module .sanitize_thread = options .use_tsan ;
1150
1182
1183
+ var cflags = try std .BoundedArray ([]const u8 , 64 ).init (0 );
1184
+ if (options .optimize != .Debug ) {
1185
+ try cflags .append ("-DNDEBUG" );
1186
+ }
1187
+ try cflags .appendSlice (&.{
1188
+ "-Wall" ,
1189
+ "-Wextra" ,
1190
+ "-fno-exceptions" ,
1191
+ "-Wno-unused-parameter" ,
1192
+ "-Wno-missing-field-initializers" ,
1193
+ "-fno-threadsafe-statics" ,
1194
+ });
1195
+
1151
1196
if (b .lazyDependency ("imgui" , .{})) | dep | {
1152
- const cimgui = dep .path (imguiver_path );
1153
- libimgui .addIncludePath (cimgui );
1197
+ const imgui = dep .path (imguiver_path );
1198
+ libimgui .addIncludePath (imgui );
1154
1199
1155
1200
if (options .emsdk ) | emsdk | {
1156
1201
if (libimgui .rootModuleTarget ().isWasm ()) {
@@ -1168,28 +1213,21 @@ fn buildImgui(b: *Build, options: libImGuiOptions) !*CompileStep {
1168
1213
}
1169
1214
}
1170
1215
libimgui .addCSourceFiles (.{
1171
- .root = cimgui ,
1216
+ .root = imgui ,
1172
1217
.files = &.{
1173
1218
"cimgui.cpp" ,
1174
1219
},
1175
1220
});
1176
1221
libimgui .addCSourceFiles (.{
1177
- .root = cimgui ,
1222
+ .root = imgui ,
1178
1223
.files = &.{
1179
1224
"imgui.cpp" ,
1180
1225
"imgui_draw.cpp" ,
1181
1226
"imgui_demo.cpp" ,
1182
1227
"imgui_widgets.cpp" ,
1183
1228
"imgui_tables.cpp" ,
1184
1229
},
1185
- .flags = &.{
1186
- "-Wall" ,
1187
- "-Wextra" ,
1188
- "-fno-exceptions" ,
1189
- "-Wno-unused-parameter" ,
1190
- "-Wno-missing-field-initializers" ,
1191
- "-fno-threadsafe-statics" ,
1192
- },
1230
+ .flags = cflags .slice (),
1193
1231
});
1194
1232
libimgui .root_module .sanitize_c = false ;
1195
1233
if (libimgui .rootModuleTarget ().os .tag == .windows )
0 commit comments