@@ -10,9 +10,8 @@ pub fn build(b: *std.Build) void {
1010 const praxis = resources .builder .dependency ("praxis" , .{ .target = target , .optimize = optimize });
1111 const praxis_module = praxis .module ("praxis" );
1212
13- const zigimg = b .dependency ("zigimg" , .{ .target = target , .optimize = optimize });
14- const zigimg_module = zigimg .module ("zigimg" );
15- add_libs (b , & target , zigimg_module );
13+ const zstbi = resources .builder .dependency ("zstbi" , .{ .target = target , .optimize = optimize });
14+ const zstbi_module = zstbi .module ("root" );
1615
1716 const sdl_module = define_sdl_module (b , & target , & optimize );
1817 const mixer_module = define_mixer_module (b , & target , & optimize );
@@ -24,7 +23,7 @@ pub fn build(b: *std.Build) void {
2423 });
2524 lib_mod .addImport ("praxis" , praxis_module );
2625 lib_mod .addImport ("resources" , resources_module );
27- lib_mod .addImport ("zigimg " , zigimg_module );
26+ lib_mod .addImport ("zstbi " , zstbi_module );
2827 lib_mod .addImport ("sdl" , sdl_module );
2928 lib_mod .addImport ("mixer" , mixer_module );
3029 lib_mod .addIncludePath (b .path ("libs/SDL3_mixer.xcframework/macos-arm64_x86_64/SDL3_mixer.framework/Versions/A/Headers/SDL_mixer.h" ));
@@ -44,7 +43,7 @@ pub fn build(b: *std.Build) void {
4443 });
4544 test_mod .addImport ("praxis" , praxis_module );
4645 test_mod .addImport ("resources" , resources_module );
47- test_mod .addImport ("zigimg " , zigimg_module );
46+ test_mod .addImport ("zstbi " , zstbi_module );
4847 test_mod .addImport ("sdl" , sdl_module );
4948 test_mod .addImport ("mixer" , mixer_module );
5049 test_mod .addIncludePath (b .path ("libs/SDL3_mixer.xcframework/macos-arm64_x86_64/SDL3_mixer.framework/Versions/A/Headers/SDL_mixer.h" ));
@@ -126,16 +125,14 @@ pub fn add_translatec_headers(
126125 // For TranslateC to work, we need the system library headers
127126 switch (target .result .os .tag ) {
128127 .macos = > {
129- //const sdk = std.zig.system.darwin.getSdk(b.allocator, b.graph.host.result) orelse
130- const sdk = std .zig .system .darwin .getSdk (b .allocator , & target .result ) orelse
128+ const sdk = std .zig .system .darwin .getSdk (b .allocator , b .graph .io , & target .result ) orelse
131129 @panic ("macOS SDK is missing" );
132130 std .log .info ("engine using macos c headers: {s}" , .{sdk });
133131 lib .addSystemIncludePath (.{ .cwd_relative = b .pathJoin (&.{ sdk , "/usr/include" }) });
134132 lib .addSystemFrameworkPath (.{ .cwd_relative = b .pathJoin (&.{ sdk , "/System/Library/Frameworks" }) });
135133 },
136134 .ios = > {
137- //const sdk = std.zig.system.darwin.getSdk(b.allocator, b.graph.host.result) orelse
138- const sdk = std .zig .system .darwin .getSdk (b .allocator , & target .result ) orelse
135+ const sdk = std .zig .system .darwin .getSdk (b .allocator , b .graph .io , & target .result ) orelse
139136 @panic ("iOS SDK is missing" );
140137 std .log .info ("engine using iphoneos c headers: {s}" , .{sdk });
141138 lib .addSystemIncludePath (.{ .cwd_relative = b .pathJoin (&.{ sdk , "/usr/include" }) });
@@ -144,18 +141,15 @@ pub fn add_translatec_headers(
144141 .linux = > {
145142 if (target .result .abi .isAndroid ()) {
146143 // When building for android, we need to use the android linux headers
147- if (FindNDK .find (b .allocator )) | android_ndk | {
148- const ndk_location = android_ndk .realpathAlloc (b .allocator , "." ) catch {
149- @panic ("printing ndk path failed" );
150- };
151- defer b .allocator .free (ndk_location );
152- std .log .info ("Using android c headers: {s}" , .{ndk_location });
144+ if (FindNDK .find (b .graph .io , b .graph .environ_map ) catch null ) | android_ndk | {
145+ std .log .info ("Using android c headers: {any}" , .{android_ndk });
146+
153147 lib .addSystemIncludePath (.{ .cwd_relative = b .pathJoin (&.{
154- ndk_location ,
148+ android_ndk ,
155149 "toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/" ,
156150 }) });
157151 lib .addSystemIncludePath (.{ .cwd_relative = b .pathJoin (&.{
158- ndk_location ,
152+ android_ndk ,
159153 "toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/aarch64-linux-android/" ,
160154 }) });
161155 } else {
@@ -181,14 +175,14 @@ pub fn add_libs(
181175 // For TranslateC to work, we need the system library headers
182176 switch (target .result .os .tag ) {
183177 .macos = > {
184- const sdk = std .zig .system .darwin .getSdk (b .allocator , & target .result ) orelse
178+ const sdk = std .zig .system .darwin .getSdk (b .allocator , b . graph . io , & target .result ) orelse
185179 @panic ("macOS SDK is missing" );
186180 std .log .info ("engine using macos c headers: {s}" , .{sdk });
187181 lib .addSystemIncludePath (.{ .cwd_relative = b .pathJoin (&.{ sdk , "/usr/include" }) });
188182 lib .addSystemFrameworkPath (.{ .cwd_relative = b .pathJoin (&.{ sdk , "/System/Library/Frameworks" }) });
189183 },
190184 .ios = > {
191- const sdk = std .zig .system .darwin .getSdk (b .allocator , & target .result ) orelse
185+ const sdk = std .zig .system .darwin .getSdk (b .allocator , b . graph . io , & target .result ) orelse
192186 @panic ("iOS SDK is missing" );
193187 std .log .info ("engine using iphoneos c headers: {s}" , .{sdk });
194188 lib .addSystemIncludePath (.{ .cwd_relative = b .pathJoin (&.{ sdk , "/usr/include" }) });
@@ -197,18 +191,14 @@ pub fn add_libs(
197191 .linux = > {
198192 // When building for android, we need to use the android linux headers
199193 if (target .result .abi .isAndroid ()) {
200- if (FindNDK .find (b .allocator )) | android_ndk | {
201- const ndk_location = android_ndk .realpathAlloc (b .allocator , "." ) catch {
202- @panic ("printing ndk path failed" );
203- };
204- defer b .allocator .free (ndk_location );
205- std .log .info ("Using android c headers: {s}" , .{ndk_location });
194+ if (FindNDK .find (b .graph .io , b .graph .environ_map ) catch null ) | android_ndk | {
195+ std .log .info ("Using android c headers: {s}" , .{android_ndk });
206196 lib .addSystemIncludePath (.{ .cwd_relative = b .pathJoin (&.{
207- ndk_location ,
197+ android_ndk ,
208198 "toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/" ,
209199 }) });
210200 lib .addSystemIncludePath (.{ .cwd_relative = b .pathJoin (&.{
211- ndk_location ,
201+ android_ndk ,
212202 "toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/aarch64-linux-android/" ,
213203 }) });
214204 } else {
@@ -290,140 +280,7 @@ pub fn link_sdl_framework(
290280 }
291281}
292282
293- /// Attempt to find the location of the NDK by searching ANDROID_NDK_HOME,
294- /// ANDROID_SDK_ROOT, and fallback to searching known locations inside the
295- /// user home folder.
296- const FindNDK = struct {
297- const ndk_versions = [_ ][]const u8 {
298- "29.0.13846066" , // Pre-release
299- "28.2.13676358" , // Stable
300- "27.3.13750724" , // LTS
301- "27.0.12077973" ,
302- "25.1.8937393" ,
303- "23.2.8568313" ,
304- "23.1.7779620" ,
305- "21.0.6113669" ,
306- "20.1.5948944" ,
307- };
308-
309- pub fn find (gpa : std.mem.Allocator ) ? std.fs.Dir {
310- const android_ndk_home = find_android_ndk_home (gpa ) catch | e | {
311- std .log .err ("error while searching for ndk: {any}" , .{e });
312- return null ;
313- };
314- if (android_ndk_home != null ) return android_ndk_home .? ;
315-
316- const android_sdk_root = find_android_sdk_root (gpa ) catch | e | {
317- std .log .err ("error while searching for sdk: {any}" , .{e });
318- return null ;
319- };
320- if (android_sdk_root != null ) {
321- if (android_sdk_root .? .openDir ("ndk" , .{})) | dir | {
322- std .log .debug ("searching inside ANDROID_SDK_ROOT/ndk" , .{});
323- const found = search_ndk_folder (gpa , dir );
324- if (found != null ) return found .? ;
325- } else | _ | {
326- std .log .debug ("no ndk in ANDROID_SDK_ROOT" , .{});
327- }
328- }
329-
330- const home = find_user_home (gpa ) catch | e | {
331- std .log .err ("error while searching for ndk: {any}" , .{e });
332- return null ;
333- };
334- if (home == null ) {
335- std .log .err ("ndk not found. No HOME or USERPROFILE set." , .{});
336- return null ;
337- }
338- const ndk_base = home .? .openDir ("Library/Android/sdk/ndk/" , .{}) catch | e | {
339- std .log .err ("ndk not found. Error {any} reading HOME/Library/Android/sdk/ndk/" , .{e });
340- return null ;
341- };
342- return search_ndk_folder (gpa , ndk_base );
343- }
344-
345- pub fn search_ndk_folder (_ : std.mem.Allocator , ndk_base : std.fs.Dir ) ? std.fs.Dir {
346- for (ndk_versions ) | version | {
347- const folder = ndk_base .openDir (version , .{}) catch {
348- std .log .debug ("ndk version {s} not found" , .{version });
349- continue ;
350- };
351- std .log .debug ("ndk version found: {any}" , .{folder });
352- return folder ;
353- }
354- return null ;
355- }
356-
357- /// If ANDROID_NDK_HOME is set, just use that
358- pub fn find_android_ndk_home (gpa : std.mem.Allocator ) ! ? std.fs.Dir {
359- var env_map = try std .process .getEnvMap (gpa );
360- defer env_map .deinit ();
361- var iter = env_map .iterator ();
362- var home : ? []const u8 = null ;
363- while (iter .next ()) | entry | {
364- if (std .ascii .eqlIgnoreCase ("ANDROID_NDK_HOME" , entry .key_ptr .* )) {
365- home = entry .value_ptr .* ;
366- break ;
367- }
368- }
369- if (home == null ) {
370- std .log .warn ("ANDROID_NDK_HOME not set." , .{});
371- return null ;
372- }
373- const d = std .fs .openDirAbsolute (home .? , .{}) catch {
374- std .log .warn ("Failed to read ANDROID_NDK_HOME directory {any}" , .{home .? });
375- return null ;
376- };
377- return d ;
378- }
379-
380- /// If ANDROID_SDK_ROOT is set, just use that
381- pub fn find_android_sdk_root (gpa : std.mem.Allocator ) ! ? std.fs.Dir {
382- var env_map = try std .process .getEnvMap (gpa );
383- defer env_map .deinit ();
384- var iter = env_map .iterator ();
385- var home : ? []const u8 = null ;
386- while (iter .next ()) | entry | {
387- if (std .ascii .eqlIgnoreCase ("ANDROID_SDK_ROOT" , entry .key_ptr .* )) {
388- home = entry .value_ptr .* ;
389- break ;
390- }
391- }
392- if (home == null ) {
393- std .log .info ("ANDROID_SDK_ROOT not set." , .{});
394- return null ;
395- }
396- const d = std .fs .openDirAbsolute (home .? , .{}) catch {
397- std .log .warn ("Failed to read ANDROID_SDK_ROOT directory {any}" , .{home .? });
398- return null ;
399- };
400- return d ;
401- }
402-
403- /// Sometimes, the NDK is in the users home folder
404- pub fn find_user_home (gpa : std.mem.Allocator ) ! ? std.fs.Dir {
405- var env_map = try std .process .getEnvMap (gpa );
406- defer env_map .deinit ();
407- var iter = env_map .iterator ();
408- var home : ? []const u8 = null ;
409- while (iter .next ()) | entry | {
410- if (std .ascii .eqlIgnoreCase ("HOME" , entry .key_ptr .* )) {
411- home = entry .value_ptr .* ;
412- }
413- if (std .ascii .eqlIgnoreCase ("UserProfile" , entry .key_ptr .* )) {
414- home = entry .value_ptr .* ;
415- }
416- }
417- if (home != null ) {
418- const d = std .fs .openDirAbsolute (home .? , .{}) catch {
419- std .log .warn ("Failed to read directory {any}" , .{home .? });
420- return null ;
421- };
422- return d ;
423- }
424- return null ;
425- }
426- };
427-
428283const std = @import ("std" );
429284const debug = std .log .debug ;
285+
286+ const FindNDK = @import ("build/find_ndk.zig" ).FindNDK ;
0 commit comments