Skip to content

Commit 3abb282

Browse files
committed
Update for 0.16-dev/main
1 parent 2e2a0b3 commit 3abb282

File tree

4 files changed

+39
-182
lines changed

4 files changed

+39
-182
lines changed

build.zig

Lines changed: 19 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
428283
const std = @import("std");
429284
const debug = std.log.debug;
285+
286+
const FindNDK = @import("build/find_ndk.zig").FindNDK;

build.zig.zon

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
.{
22
.name = .engine,
3-
.version = "0.12.6",
3+
.version = "0.13.0",
44
.fingerprint = 0xe8a81a8d0aa558d5,
5-
.minimum_zig_version = "0.15.2",
5+
.minimum_zig_version = "0.16.0",
66
.dependencies = .{
7+
.resources = .{
8+
.url = "git+https://github.com/loftafi/resources.git#b7475973e692f7aa8d06a5d4c8510a6fbc93bc9a",
9+
.hash = "resources-0.9.0-J0GwIxhUAgC04XsG-EAjdg1ykMpoW5WcMJHBR7UdE_kk",
10+
},
711
.sdl = .{
8-
.url = "git+https://github.com/castholm/SDL.git#f103a1439670c35be756d4491b296a6e3ccffaed",
9-
.hash = "sdl-0.3.2+3.2.26-7uIn9BNgfwHaS0qXiSIBLkJf8Jfrh5P6gSWdQvtnvxEp",
12+
.url = "git+https://github.com/castholm/SDL.git#887fa805e40d5c7bb3955ae69b89ed566c6a0471",
13+
.hash = "sdl-0.4.0+3.4.0-SDL--rq2owEZsySGuHCuVJ9naEvH3i3e_pyUIjziBtJ-",
1014
},
1115
.sdl_ttf = .{
12-
.url = "git+https://github.com/loftafi/SDL_ttf.git#119d2eec127c4ca9de159939c95f5f3b55794155",
13-
.hash = "sdl_ttf-3.2.26-9xyaiOgVBwA6HIB5v3N8mf-hRpDwexBaJ2vFckQeqZNH",
16+
.url = "git+https://github.com/loftafi/SDL_ttf.git#1664f9dd72900cc54902222c656e922e62812206",
17+
.hash = "sdl_ttf-3.2.26-2-9xyaiOwVBwBas0CEbu59d9QdQHmBKgpjDso-g1kjSdCP",
1418
},
15-
.zigimg = .{
16-
.url = "git+https://github.com/zigimg/zigimg.git#f5783e87627cbd9e0b45fad112e9f73503914f36",
17-
.hash = "zigimg-0.1.0-8_eo2vBrFQBhsrLpexdcDQY-zrlzkyFZfKuYX-Nry6KN",
18-
},
19-
.resources = .{
20-
.url = "git+https://github.com/loftafi/resources.git#a99463a20ac15977ba43b28df18a889f7f2d4a03",
21-
.hash = "resources-0.8.6-J0GwI1pBAgCwkbBvzefL_M4UpK2WPxBh47xJyoUt9G59",
19+
.zstbi = .{
20+
.url = "git+https://github.com/zaddok/zstbi.git#456b7620bf8036d29454d98cb506e0428e6510ae",
21+
.hash = "zstbi-0.11.0-dev-L0Ea_06WBwCZoJBl6SD0bcHOLEEIrD5xbQ0TbXe-SQ5Y",
2222
},
2323
},
2424
.paths = .{

src/engine.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,7 +2204,7 @@ pub const LanguageFont = struct {
22042204

22052205
pub const SurfaceInfo = struct {
22062206
buffer: []const u8,
2207-
img: zigimg.Image,
2207+
img: zstbi.Image,
22082208
surface: *sdl.SDL_Surface,
22092209

22102210
pub fn deinit(si: *@This(), gpa: Allocator) void {
@@ -2223,7 +2223,7 @@ fn load_image_resource(
22232223
) (Error || Allocator.Error)!void {
22242224
si.buffer = try sdl_load_resource(bucket, resource, allocator);
22252225
errdefer allocator.free(si.buffer);
2226-
si.img = zigimg.Image.fromMemory(allocator, si.buffer[0..]) catch |e| {
2226+
si.img = zstbi.Image.fromMemory(allocator, si.buffer[0..]) catch |e| {
22272227
if (e == error.OutOfMemory) return error.OutOfMemory;
22282228
return error.UnknownImageFormat;
22292229
};
@@ -2519,7 +2519,7 @@ pub const LogLevel = enum {
25192519
/// Write a log message to stderr in debug mode or to SDL in release mode
25202520
pub fn log_output(
25212521
comptime level: LogLevel,
2522-
comptime scope: @Type(.enum_literal),
2522+
comptime scope: @EnumLiteral(),
25232523
comptime format: []const u8,
25242524
args: anytype,
25252525
) void {
@@ -2572,7 +2572,7 @@ pub const std_options: std.Options = .{
25722572
/// Zig log output handler captures zig log calls
25732573
pub fn log_output_handler(
25742574
comptime level: std.log.Level,
2575-
comptime scope: @Type(.enum_literal),
2575+
comptime scope: @EnumLiteral(),
25762576
comptime format: []const u8,
25772577
args: anytype,
25782578
) void {
@@ -3001,7 +3001,7 @@ const sdl = @import("sdl");
30013001
const builtin = @import("builtin");
30023002
const assert = std.debug.assert;
30033003

3004-
const zigimg = @import("zigimg");
3004+
const zstbi = @import("zstbi");
30053005

30063006
pub const engine = @import("engine.zig");
30073007
pub const Animator = @import("animator.zig").Animator;

src/entity.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ pub fn Entity(comptime T: type) type {
175175
}
176176
i.*.children.deinit(allocator);
177177
},
178-
.progress_bar => |_| {
178+
.progress_bar => {
179179
//
180180
},
181-
.expander => |_| {
181+
.expander => {
182182
//
183183
},
184184
.text_input => |*i| {

0 commit comments

Comments
 (0)