Skip to content

Commit 870c7c2

Browse files
update various code sites to handle Zig 0.16.x (#57)
- add various fixes to support Zig 0.16.0-dev.2040+c475f1fcd - add `b.graph.io` parameter to various file handling operations if building with Zig 0.16.X or higher. - no longer supporting custom panic handler if building with Zig 0.16.x-dev or higher. - Linux: add automatic detection of Android Studio so it's jarsigner/java/etc binaries can be utilized. - Windows: remove deprecated Android Studio registry check logic
1 parent 941fc65 commit 870c7c2

25 files changed

Lines changed: 1035 additions & 1070 deletions

.github/workflows/ci.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ jobs:
138138
run: zig build -Dandroid=true --verbose
139139
working-directory: examples/sdl2
140140

141-
- name: Build Raylib Example (Zig Stable)
142-
run: zig build -Dandroid=true --verbose
143-
working-directory: examples/raylib
141+
# note(jae): 2026-01-10
142+
# Downstream packages for Raylib won't work with Zig 0.15.2 *and* Zig 0.16.X
143+
#
144+
# - name: Build Raylib Example (Zig Nightly)
145+
# run: zig build -Dandroid=true --verbose
146+
# working-directory: examples/raylib

build.zig

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const std = @import("std");
2+
const builtin = @import("builtin");
23
const androidbuild = @import("src/androidbuild/androidbuild.zig");
34

45
// Expose Android build functionality for use in your build.zig
@@ -27,17 +28,56 @@ pub fn build(b: *std.Build) void {
2728
const target = b.standardTargetOptions(.{});
2829
const optimize = b.standardOptimizeOption(.{});
2930

30-
const module = b.addModule("android", .{
31+
// Create stub of builtin options.
32+
// This is discovered and then replaced by "Apk" in the build process
33+
const android_builtin_options = std.Build.addOptions(b);
34+
android_builtin_options.addOption([:0]const u8, "package_name", "");
35+
const android_builtin_module = android_builtin_options.createModule();
36+
37+
// Create android module
38+
const android_module = b.addModule("android", .{
3139
.root_source_file = b.path("src/android/android.zig"),
3240
.target = target,
3341
.optimize = optimize,
3442
});
43+
const ndk_module = b.createModule(.{
44+
.root_source_file = b.path("src/android/ndk/ndk.zig"),
45+
.target = target,
46+
.optimize = optimize,
47+
});
48+
android_module.addImport("ndk", ndk_module);
49+
android_module.addImport("android_builtin", android_builtin_module);
3550

36-
// Create stub of builtin options.
37-
// This is discovered and then replaced by "Apk" in the build process
38-
const android_builtin_options = std.Build.addOptions(b);
39-
android_builtin_options.addOption([:0]const u8, "package_name", "");
40-
module.addImport("android_builtin", android_builtin_options.createModule());
51+
// Add backwards compatibility modules
52+
if (builtin.zig_version.major == 0 and builtin.zig_version.minor <= 14) {
53+
// Deprecated: Allow older Zig builds to work
54+
var zig014 = b.createModule(.{
55+
.root_source_file = b.path("src/android/zig014/zig014.zig"),
56+
.target = target,
57+
.optimize = optimize,
58+
});
59+
zig014.addImport("ndk", ndk_module);
60+
zig014.addImport("android_builtin", android_builtin_module);
61+
android_module.addImport("zig014", zig014);
62+
}
63+
if (builtin.zig_version.major == 0 and builtin.zig_version.minor <= 15) {
64+
// Add as a module to deal with @Type(.enum_literal) being deprecated
65+
const zig015 = b.createModule(.{
66+
.root_source_file = b.path("src/android/zig015/zig015.zig"),
67+
.target = target,
68+
.optimize = optimize,
69+
});
70+
android_module.addImport("zig015", zig015);
71+
}
72+
if (builtin.zig_version.major == 0 and builtin.zig_version.minor >= 16) {
73+
// Add as a module to deal with @Type(.enum_literal) being deprecated
74+
const zig016 = b.createModule(.{
75+
.root_source_file = b.path("src/android/zig016/zig016.zig"),
76+
.target = target,
77+
.optimize = optimize,
78+
});
79+
android_module.addImport("zig016", zig016);
80+
}
4181

42-
module.linkSystemLibrary("log", .{});
82+
android_module.linkSystemLibrary("log", .{});
4383
}

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.{
22
.name = .android,
3-
.version = "0.2.0",
3+
.version = "0.3.0",
44
.dependencies = .{},
55
.paths = .{
66
"build.zig",

examples/minimal/src/minimal.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ pub const std_options: std.Options = if (builtin.abi.isAndroid())
1212
else
1313
.{};
1414

15-
/// custom panic handler for Android
16-
pub const panic = if (builtin.abi.isAndroid())
15+
/// Deprecated: Zig 0.15.2 and lower only, Custom panic handler for Android
16+
pub const panic = if (builtin.abi.isAndroid() and builtin.zig_version.major == 0 and builtin.zig_version.minor <= 15)
1717
android.panic
1818
else
1919
std.debug.FullPanic(std.debug.defaultPanic);

examples/raylib/src/main.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const builtin = @import("builtin");
33
const android = @import("android");
44
const rl = @import("raylib");
55

6-
pub fn main() void {
6+
pub fn main() !void {
77
const screenWidth = 800;
88
const screenHeight = 450;
99
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
@@ -19,8 +19,8 @@ pub fn main() void {
1919
}
2020
}
2121

22-
/// custom panic handler for Android
23-
pub const panic = if (builtin.abi.isAndroid())
22+
/// Deprecated: Zig 0.15.2 and lower only, Custom panic handler for Android
23+
pub const panic = if (builtin.abi.isAndroid() and builtin.zig_version.major == 0 and builtin.zig_version.minor <= 15)
2424
android.panic
2525
else
2626
std.debug.FullPanic(std.debug.defaultPanic);

examples/sdl2/build.zig

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ pub fn build(b: *std.Build) void {
2121
const android_sdk = android.Sdk.create(b, .{});
2222
const apk = android_sdk.createApk(.{
2323
.api_level = .android15,
24-
.build_tools_version = "35.0.1",
25-
.ndk_version = "29.0.13113456",
24+
.build_tools_version = "36.1.0",
25+
.ndk_version = "29.0.14206865",
2626
// NOTE(jae): 2025-03-09
2727
// Previously this example used 'ndk' "27.0.12077973".
2828
//
@@ -70,14 +70,6 @@ pub fn build(b: *std.Build) void {
7070
.optimize = optimize,
7171
.root_source_file = b.path("src/sdl-zig-demo.zig"),
7272
});
73-
var exe: *std.Build.Step.Compile = if (target.result.abi.isAndroid()) b.addLibrary(.{
74-
.name = exe_name,
75-
.root_module = app_module,
76-
.linkage = .dynamic,
77-
}) else b.addExecutable(.{
78-
.name = exe_name,
79-
.root_module = app_module,
80-
});
8173

8274
const library_optimize = if (!target.result.abi.isAndroid())
8375
optimize
@@ -96,15 +88,15 @@ pub fn build(b: *std.Build) void {
9688
if (target.result.os.tag == .linux and !target.result.abi.isAndroid()) {
9789
// The SDL package doesn't work for Linux yet, so we rely on system
9890
// packages for now.
99-
exe.linkSystemLibrary("SDL2");
100-
exe.linkLibC();
91+
app_module.linkSystemLibrary("SDL2", .{});
92+
app_module.link_libc = true;
10193
} else {
10294
const sdl_lib = sdl_dep.artifact("SDL2");
103-
exe.linkLibrary(sdl_lib);
95+
app_module.linkLibrary(sdl_lib);
10496
}
10597

10698
const sdl_module = sdl_dep.module("sdl");
107-
exe.root_module.addImport("sdl", sdl_module);
99+
app_module.addImport("sdl", sdl_module);
108100
}
109101

110102
// if building as library for Android, add this target
@@ -116,10 +108,19 @@ pub fn build(b: *std.Build) void {
116108
.optimize = optimize,
117109
.target = target,
118110
});
119-
exe.root_module.addImport("android", android_dep.module("android"));
111+
app_module.addImport("android", android_dep.module("android"));
120112

121-
apk.addArtifact(exe);
113+
const exe_lib = b.addLibrary(.{
114+
.name = exe_name,
115+
.root_module = app_module,
116+
.linkage = .dynamic,
117+
});
118+
apk.addArtifact(exe_lib);
122119
} else {
120+
const exe = b.addExecutable(.{
121+
.name = exe_name,
122+
.root_module = app_module,
123+
});
123124
b.installArtifact(exe);
124125

125126
// If only 1 target, add "run" step

examples/sdl2/src/sdl-zig-demo.zig

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ const sdl = @import("sdl");
66
const log = std.log;
77
const assert = std.debug.assert;
88

9-
/// custom standard options for Android
9+
// custom standard options for Android
1010
pub const std_options: std.Options = if (builtin.abi.isAndroid())
1111
.{
1212
.logFn = android.logFn,
1313
}
1414
else
1515
.{};
1616

17-
/// custom panic handler for Android
18-
pub const panic = if (builtin.abi.isAndroid())
17+
/// Deprecated: Zig 0.15.2 and lower only, Custom panic handler for Android
18+
pub const panic = if (builtin.abi.isAndroid() and builtin.zig_version.major == 0 and builtin.zig_version.minor <= 15)
1919
android.panic
2020
else
2121
std.debug.FullPanic(std.debug.defaultPanic);
@@ -29,7 +29,20 @@ comptime {
2929
/// This needs to be exported for Android builds
3030
fn SDL_main() callconv(.c) void {
3131
if (comptime builtin.abi.isAndroid()) {
32-
_ = std.start.callMain();
32+
if (builtin.zig_version.major == 0 and builtin.zig_version.minor <= 14) {
33+
_ = std.start.callMain();
34+
} else if (builtin.zig_version.major == 0 and builtin.zig_version.minor <= 15) {
35+
main() catch |err| {
36+
log.err("{s}", .{@errorName(err)});
37+
if (@errorReturnTrace()) |trace| {
38+
if (builtin.zig_version.major == 0 and builtin.zig_version.minor <= 15) {
39+
std.debug.dumpStackTrace(trace.*);
40+
} else {
41+
std.debug.dumpStackTrace(trace);
42+
}
43+
}
44+
};
45+
}
3346
} else {
3447
@compileError("SDL_main should not be called outside of Android builds");
3548
}

0 commit comments

Comments
 (0)