@@ -29,53 +29,54 @@ pub fn build(b: *std.Build) void {
29
29
.root_source_file = b .path ("src/sdl3.zig" ),
30
30
});
31
31
32
- const test_step = b .step ("test" , "Run bindings tests" );
33
- { // Test SDL2 bindings
34
- const zsdl2_tests = addTests (test_step , target , optimize , "zsdl2-tests" , "src/sdl2.zig" );
35
- link_SDL2 (zsdl2_tests );
36
- }
37
- { // Test SDL2_ttf bindings
38
- const zsdl2_ttf_tests = addTestsAux (
39
- test_step ,
40
- target ,
41
- optimize ,
42
- "zsdl2_ttf-tests" ,
43
- "src/sdl2_ttf.zig" ,
44
- "zsdl2" ,
45
- zsdl2_module ,
46
- );
47
- link_SDL2 (zsdl2_ttf_tests );
48
- link_SDL2_ttf (zsdl2_ttf_tests );
49
- }
50
- { // Test SDL2_image bindings
51
- const zsdl2_image_tests = addTestsAux (
52
- test_step ,
53
- target ,
54
- optimize ,
55
- "zsdl2_ttf-image" ,
56
- "src/sdl2_image.zig" ,
57
- "zsdl2" ,
58
- zsdl2_module ,
59
- );
60
- link_SDL2 (zsdl2_image_tests );
61
- link_SDL2_image (zsdl2_image_tests );
62
- }
63
- { // Test SDL3 bindings
64
- const zsdl3_tests = addTests (test_step , target , optimize , "zsdl3-tests" , "src/sdl3.zig" );
65
- link_SDL3 (zsdl3_tests );
66
- }
32
+ {
33
+ const test_step = b .step ("test" , "Run bindings tests" );
34
+ { // Test SDL2 bindings
35
+ const zsdl2_tests = addTests (test_step , target , optimize , "zsdl2-tests" , "src/sdl2.zig" );
36
+ link_SDL2 (zsdl2_tests );
37
+ prebuilt_sdl2 .addLibraryPathsTo (zsdl2_tests );
38
+ }
39
+ { // Test SDL2_ttf bindings
40
+ const zsdl2_ttf_tests = addTestsAux (
41
+ test_step ,
42
+ target ,
43
+ optimize ,
44
+ "zsdl2_ttf-tests" ,
45
+ "src/sdl2_ttf.zig" ,
46
+ "zsdl2" ,
47
+ zsdl2_module ,
48
+ );
49
+ link_SDL2 (zsdl2_ttf_tests );
50
+ link_SDL2_ttf (zsdl2_ttf_tests );
51
+ prebuilt_sdl2 .addLibraryPathsTo (zsdl2_ttf_tests );
52
+ }
53
+ { // Test SDL2_image bindings
54
+ const zsdl2_image_tests = addTestsAux (
55
+ test_step ,
56
+ target ,
57
+ optimize ,
58
+ "zsdl2_ttf-image" ,
59
+ "src/sdl2_image.zig" ,
60
+ "zsdl2" ,
61
+ zsdl2_module ,
62
+ );
63
+ link_SDL2 (zsdl2_image_tests );
64
+ link_SDL2_image (zsdl2_image_tests );
65
+ prebuilt_sdl2 .addLibraryPathsTo (zsdl2_image_tests );
66
+ }
67
+ { // Test SDL3 bindings
68
+ const zsdl3_tests = addTests (test_step , target , optimize , "zsdl3-tests" , "src/sdl3.zig" );
69
+ link_SDL3 (zsdl3_tests );
70
+ prebuilt_sdl3 .addLibraryPathsTo (zsdl3_tests );
71
+ }
67
72
68
- if (prebuilt .install_SDL2 (b , target .result , .bin )) | install_sdl2_step | {
69
- b .getInstallStep ().dependOn (install_sdl2_step );
70
- }
71
- if (prebuilt .install_SDL2_ttf (b , target .result , .bin )) | install_sdl2_ttf_step | {
72
- b .getInstallStep ().dependOn (install_sdl2_ttf_step );
73
- }
74
- if (prebuilt .install_SDL2_image (b , target .result , .bin )) | install_sdl2_image_step | {
75
- b .getInstallStep ().dependOn (install_sdl2_image_step );
76
- }
77
- if (prebuilt .install_SDL3 (b , target .result , .bin )) | install_sdl3_step | {
78
- b .getInstallStep ().dependOn (install_sdl3_step );
73
+ if (prebuilt_sdl2 .install (b , target .result , .bin , .{ .ttf = true , .image = true })) | install_sdl2_step | {
74
+ b .getInstallStep ().dependOn (install_sdl2_step );
75
+ }
76
+
77
+ if (prebuilt_sdl3 .install (b , target .result , .bin , .{})) | install_sdl3_step | {
78
+ b .getInstallStep ().dependOn (install_sdl3_step );
79
+ }
79
80
}
80
81
}
81
82
@@ -158,7 +159,7 @@ pub fn testVersionCheckSDL2(b: *std.Build, target: std.Build.ResolvedTarget) *st
158
159
159
160
link_SDL2 (test_sdl2_version_check );
160
161
161
- prebuilt .addLibraryPathsTo (test_sdl2_version_check );
162
+ prebuilt_sdl2 .addLibraryPathsTo (test_sdl2_version_check );
162
163
163
164
const version_check_run = b .addRunArtifact (test_sdl2_version_check );
164
165
@@ -170,14 +171,14 @@ pub fn testVersionCheckSDL2(b: *std.Build, target: std.Build.ResolvedTarget) *st
170
171
171
172
version_check_run .step .dependOn (& test_sdl2_version_check .step );
172
173
173
- if (prebuilt . install_SDL2 (b , target .result , .bin )) | install_sdl2_step | {
174
+ if (prebuilt_sdl2 . install (b , target .result , .bin , .{} )) | install_sdl2_step | {
174
175
version_check_run .step .dependOn (install_sdl2_step );
175
176
}
176
177
177
178
return & version_check_run .step ;
178
179
}
179
180
180
- pub const prebuilt = struct {
181
+ pub const prebuilt_sdl2 = struct {
181
182
pub fn addLibraryPathsTo (compile_step : * std.Build.Step.Compile ) void {
182
183
const b = compile_step .step .owner ;
183
184
const target = compile_step .rootModuleTarget ();
@@ -187,164 +188,153 @@ pub const prebuilt = struct {
187
188
if (b .lazyDependency ("sdl2-prebuilt-x86_64-windows-gnu" , .{})) | sdl2_prebuilt | {
188
189
compile_step .addLibraryPath (sdl2_prebuilt .path ("lib" ));
189
190
}
190
- if (b .lazyDependency ("sdl3-prebuilt-x86_64-windows-gnu" , .{})) | sdl3_prebuilt | {
191
- compile_step .addLibraryPath (sdl3_prebuilt .path ("bin" ));
192
- }
193
191
}
194
192
},
195
193
.linux = > {
196
194
if (target .cpu .arch .isX86 ()) {
197
195
if (b .lazyDependency ("sdl2-prebuilt-x86_64-linux-gnu" , .{})) | sdl2_prebuilt | {
198
196
compile_step .addLibraryPath (sdl2_prebuilt .path ("lib" ));
199
197
}
200
- if (b .lazyDependency ("sdl3-prebuilt-x86_64-linux-gnu" , .{})) | sdl3_prebuilt | {
201
- compile_step .addLibraryPath (sdl3_prebuilt .path ("lib" ));
202
- }
203
198
}
204
199
},
205
200
.macos = > {
206
201
if (b .lazyDependency ("sdl2-prebuilt-macos" , .{})) | sdl2_prebuilt | {
207
202
compile_step .addFrameworkPath (sdl2_prebuilt .path ("Frameworks" ));
208
203
}
209
- if (b .lazyDependency ("sdl3-prebuilt-macos" , .{})) | sdl3_prebuilt | {
210
- compile_step .addFrameworkPath (sdl3_prebuilt .path ("Frameworks" ));
211
- }
212
204
},
213
205
else = > {},
214
206
}
215
207
}
216
208
217
- pub fn install_SDL2 (
209
+ pub fn install (
218
210
b : * std.Build ,
219
211
target : std.Target ,
220
212
install_dir : std.Build.InstallDir ,
213
+ aux_libs : packed struct {
214
+ ttf : bool = false ,
215
+ image : bool = false ,
216
+ },
221
217
) ? * std.Build.Step {
218
+ var install_step = b .step ("Install SDL2" , "Installs SDL2 and auxillary runtime libraries." );
219
+
222
220
switch (target .os .tag ) {
223
221
.windows = > {
224
222
if (target .cpu .arch .isX86 ()) {
225
223
if (b .lazyDependency ("sdl2-prebuilt-x86_64-windows-gnu" , .{})) | sdl2_prebuilt | {
226
- return & b .addInstallFileWithDir (
224
+ install_step . dependOn ( & b .addInstallFileWithDir (
227
225
sdl2_prebuilt .path ("bin/SDL2.dll" ),
228
226
install_dir ,
229
227
"SDL2.dll" ,
230
- ).step ;
228
+ ).step );
229
+ if (aux_libs .ttf ) {
230
+ install_step .dependOn (& b .addInstallFileWithDir (
231
+ sdl2_prebuilt .path ("bin/SDL2_ttf.dll" ),
232
+ install_dir ,
233
+ "SDL2_ttf.dll" ,
234
+ ).step );
235
+ }
236
+ if (aux_libs .image ) {
237
+ install_step .dependOn (& b .addInstallFileWithDir (
238
+ sdl2_prebuilt .path ("bin/SDL2_image.dll" ),
239
+ install_dir ,
240
+ "SDL2_image.dll" ,
241
+ ).step );
242
+ }
231
243
}
232
244
}
233
245
},
234
246
.linux = > {
235
247
if (target .cpu .arch .isX86 ()) {
236
248
if (b .lazyDependency ("sdl2-prebuilt-x86_64-linux-gnu" , .{})) | sdl2_prebuilt | {
237
- return & b .addInstallFileWithDir (
249
+ install_step . dependOn ( & b .addInstallFileWithDir (
238
250
sdl2_prebuilt .path ("lib/libSDL2.so" ),
239
251
install_dir ,
240
252
"libSDL2.so" ,
241
- ).step ;
253
+ ).step );
254
+ if (aux_libs .ttf ) {
255
+ install_step .dependOn (& b .addInstallFileWithDir (
256
+ sdl2_prebuilt .path ("lib/libSDL2_ttf.so" ),
257
+ install_dir ,
258
+ "libSDL2_ttf.so" ,
259
+ ).step );
260
+ }
261
+ if (aux_libs .image ) {
262
+ install_step .dependOn (& b .addInstallFileWithDir (
263
+ sdl2_prebuilt .path ("lib/libSDL2_image.so" ),
264
+ install_dir ,
265
+ "libSDL2_image.so" ,
266
+ ).step );
267
+ }
242
268
}
243
269
}
244
270
},
245
271
.macos = > {
246
272
if (b .lazyDependency ("sdl2-prebuilt-macos" , .{})) | sdl2_prebuilt | {
247
- return & b .addInstallDirectory (.{
273
+ install_step . dependOn ( & b .addInstallDirectory (.{
248
274
.source_dir = sdl2_prebuilt .path ("Frameworks/SDL2.framework" ),
249
275
.install_dir = install_dir ,
250
276
.install_subdir = "SDL2.framework" ,
251
- }).step ;
252
- }
253
- },
254
- else = > {},
255
- }
256
- return null ;
257
- }
258
-
259
- pub fn install_SDL2_ttf (
260
- b : * std.Build ,
261
- target : std.Target ,
262
- install_dir : std.Build.InstallDir ,
263
- ) ? * std.Build.Step {
264
- switch (target .os .tag ) {
265
- .windows = > {
266
- if (target .cpu .arch .isX86 ()) {
267
- if (b .lazyDependency ("sdl2-prebuilt-x86_64-windows-gnu" , .{})) | sdl2_prebuilt | {
268
- return & b .addInstallFileWithDir (
269
- sdl2_prebuilt .path ("bin/SDL2_ttf.dll" ),
270
- install_dir ,
271
- "SDL2_ttf.dll" ,
272
- ).step ;
277
+ }).step );
278
+ if (aux_libs .ttf ) {
279
+ install_step .dependOn (& b .addInstallDirectory (.{
280
+ .source_dir = sdl2_prebuilt .path ("Frameworks/SDL2_ttf.framework" ),
281
+ .install_dir = install_dir ,
282
+ .install_subdir = "SDL2_ttf.framework" ,
283
+ }).step );
273
284
}
274
- }
275
- },
276
- .linux = > {
277
- if (target .cpu .arch .isX86 ()) {
278
- if (b .lazyDependency ("sdl2-prebuilt-x86_64-linux-gnu" , .{})) | sdl2_prebuilt | {
279
- return & b .addInstallFileWithDir (
280
- sdl2_prebuilt .path ("lib/libSDL2_ttf.so" ),
281
- install_dir ,
282
- "libSDL2_ttf.so" ,
283
- ).step ;
285
+ if (aux_libs .image ) {
286
+ install_step .dependOn (& b .addInstallDirectory (.{
287
+ .source_dir = sdl2_prebuilt .path ("Frameworks/SDL2_image.framework" ),
288
+ .install_dir = install_dir ,
289
+ .install_subdir = "SDL2_image.framework" ,
290
+ }).step );
284
291
}
285
292
}
286
293
},
287
- .macos = > {
288
- if (b .lazyDependency ("sdl2-prebuilt-macos" , .{})) | sdl2_prebuilt | {
289
- return & b .addInstallDirectory (.{
290
- .source_dir = sdl2_prebuilt .path ("Frameworks/SDL2_ttf.framework" ),
291
- .install_dir = install_dir ,
292
- .install_subdir = "SDL2_ttf.framework" ,
293
- }).step ;
294
- }
295
- },
296
294
else = > {},
297
295
}
298
- return null ;
296
+
297
+ return install_step ;
299
298
}
299
+ };
300
300
301
- pub fn install_SDL2_image (
302
- b : * std.Build ,
303
- target : std.Target ,
304
- install_dir : std.Build.InstallDir ,
305
- ) ? * std.Build.Step {
301
+ pub const prebuilt_sdl3 = struct {
302
+ pub fn addLibraryPathsTo (compile_step : * std.Build.Step.Compile ) void {
303
+ const b = compile_step .step .owner ;
304
+ const target = compile_step .rootModuleTarget ();
306
305
switch (target .os .tag ) {
307
306
.windows = > {
308
307
if (target .cpu .arch .isX86 ()) {
309
- if (b .lazyDependency ("sdl2-prebuilt-x86_64-windows-gnu" , .{})) | sdl2_prebuilt | {
310
- return & b .addInstallFileWithDir (
311
- sdl2_prebuilt .path ("bin/SDL2_image.dll" ),
312
- install_dir ,
313
- "SDL2_image.dll" ,
314
- ).step ;
308
+ if (b .lazyDependency ("sdl3-prebuilt-x86_64-windows-gnu" , .{})) | sdl3_prebuilt | {
309
+ compile_step .addLibraryPath (sdl3_prebuilt .path ("bin" ));
315
310
}
316
311
}
317
312
},
318
313
.linux = > {
319
314
if (target .cpu .arch .isX86 ()) {
320
- if (b .lazyDependency ("sdl2-prebuilt-x86_64-linux-gnu" , .{})) | sdl2_prebuilt | {
321
- return & b .addInstallFileWithDir (
322
- sdl2_prebuilt .path ("lib/libSDL2_image.so" ),
323
- install_dir ,
324
- "libSDL2_image.so" ,
325
- ).step ;
315
+ if (b .lazyDependency ("sdl3-prebuilt-x86_64-linux-gnu" , .{})) | sdl3_prebuilt | {
316
+ compile_step .addLibraryPath (sdl3_prebuilt .path ("lib" ));
326
317
}
327
318
}
328
319
},
329
320
.macos = > {
330
- if (b .lazyDependency ("sdl2-prebuilt-macos" , .{})) | sdl2_prebuilt | {
331
- return & b .addInstallDirectory (.{
332
- .source_dir = sdl2_prebuilt .path ("Frameworks/SDL2_image.framework" ),
333
- .install_dir = install_dir ,
334
- .install_subdir = "SDL2_image.framework" ,
335
- }).step ;
321
+ if (b .lazyDependency ("sdl3-prebuilt-macos" , .{})) | sdl3_prebuilt | {
322
+ compile_step .addFrameworkPath (sdl3_prebuilt .path ("Frameworks" ));
336
323
}
337
324
},
338
325
else = > {},
339
326
}
340
- return null ;
341
327
}
342
328
343
- pub fn install_SDL3 (
329
+ pub fn install (
344
330
b : * std.Build ,
345
331
target : std.Target ,
346
332
install_dir : std.Build.InstallDir ,
333
+ aux_libs : packed struct {
334
+ // TODO
335
+ },
347
336
) ? * std.Build.Step {
337
+ _ = aux_libs ;
348
338
switch (target .os .tag ) {
349
339
.windows = > {
350
340
if (target .cpu .arch .isX86 ()) {
@@ -397,8 +387,6 @@ fn addTests(
397
387
.target = target ,
398
388
.optimize = optimize ,
399
389
});
400
- // TODO(hazeycode): Using prebuilt libs for now. Compile from source in future.
401
- prebuilt .addLibraryPathsTo (tests );
402
390
b .installArtifact (tests );
403
391
test_step .dependOn (& b .addRunArtifact (tests ).step );
404
392
return tests ;
0 commit comments