Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ee9b0dd
update various code sites to handle Zig 0.16.x
silbinarywolf Jan 9, 2026
249d76f
fix environ map naming for current stable Zig
silbinarywolf Jan 9, 2026
9758cb1
fix not returning command line tool
silbinarywolf Jan 9, 2026
0081cb6
improve minor copy issue
silbinarywolf Jan 9, 2026
a95b789
fix 0.14.x
silbinarywolf Jan 9, 2026
755d1cc
fix more build issues
silbinarywolf Jan 10, 2026
a020346
improve more
silbinarywolf Jan 10, 2026
4f03105
more fixes
silbinarywolf Jan 10, 2026
ecf45e5
fix
silbinarywolf Jan 10, 2026
75f00d3
go
silbinarywolf Jan 10, 2026
7f4287c
document fix
silbinarywolf Jan 10, 2026
ef8206d
fix
silbinarywolf Jan 10, 2026
c97f7e1
more fix
silbinarywolf Jan 10, 2026
b40daaf
fix zig 0.14.x
silbinarywolf Jan 10, 2026
ed524ca
more work on Zig compat
silbinarywolf Jan 10, 2026
257cf9b
apply even more fixes
silbinarywolf Jan 10, 2026
f1878b3
fix
silbinarywolf Jan 10, 2026
b999d6c
fix more
silbinarywolf Jan 10, 2026
b182665
more fixes
silbinarywolf Jan 10, 2026
04b26d7
more work
silbinarywolf Jan 10, 2026
a94fa57
more
silbinarywolf Jan 10, 2026
3adb0bf
more
silbinarywolf Jan 10, 2026
443facd
fix log dependency loop
silbinarywolf Jan 10, 2026
953f47c
do each
silbinarywolf Jan 10, 2026
ac67800
fix
silbinarywolf Jan 10, 2026
75f6983
do the work
silbinarywolf Jan 10, 2026
de21edd
update version to 0.3.0
silbinarywolf Jan 10, 2026
c5a5dcd
get zig 0.14.x compiling
silbinarywolf Jan 10, 2026
298e909
fix sdl2
silbinarywolf Jan 10, 2026
b61e2f8
more
silbinarywolf Jan 10, 2026
c7b7e35
update windows sdk
silbinarywolf Jan 10, 2026
74d28c1
remove detection of Android SDK via registry (no longer applicable)
silbinarywolf Jan 10, 2026
f6dea75
remove windows imports
silbinarywolf Jan 10, 2026
21cf309
support standard Android Studio locations for linux
silbinarywolf Jan 10, 2026
d0a5620
remove todo
silbinarywolf Jan 10, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ jobs:
run: zig build -Dandroid=true --verbose
working-directory: examples/sdl2

- name: Build Raylib Example (Zig Stable)
run: zig build -Dandroid=true --verbose
working-directory: examples/raylib
# note(jae): 2026-01-10
# Downstream packages for Raylib won't work with Zig 0.15.2 *and* Zig 0.16.X
#
# - name: Build Raylib Example (Zig Nightly)
# run: zig build -Dandroid=true --verbose
# working-directory: examples/raylib
54 changes: 47 additions & 7 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const std = @import("std");
const builtin = @import("builtin");
const androidbuild = @import("src/androidbuild/androidbuild.zig");

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

const module = b.addModule("android", .{
// Create stub of builtin options.
// This is discovered and then replaced by "Apk" in the build process
const android_builtin_options = std.Build.addOptions(b);
android_builtin_options.addOption([:0]const u8, "package_name", "");
const android_builtin_module = android_builtin_options.createModule();

// Create android module
const android_module = b.addModule("android", .{
.root_source_file = b.path("src/android/android.zig"),
.target = target,
.optimize = optimize,
});
const ndk_module = b.createModule(.{
.root_source_file = b.path("src/android/ndk/ndk.zig"),
.target = target,
.optimize = optimize,
});
android_module.addImport("ndk", ndk_module);
android_module.addImport("android_builtin", android_builtin_module);

// Create stub of builtin options.
// This is discovered and then replaced by "Apk" in the build process
const android_builtin_options = std.Build.addOptions(b);
android_builtin_options.addOption([:0]const u8, "package_name", "");
module.addImport("android_builtin", android_builtin_options.createModule());
// Add backwards compatibility modules
if (builtin.zig_version.major == 0 and builtin.zig_version.minor <= 14) {
// Deprecated: Allow older Zig builds to work
var zig014 = b.createModule(.{
.root_source_file = b.path("src/android/zig014/zig014.zig"),
.target = target,
.optimize = optimize,
});
zig014.addImport("ndk", ndk_module);
zig014.addImport("android_builtin", android_builtin_module);
android_module.addImport("zig014", zig014);
}
if (builtin.zig_version.major == 0 and builtin.zig_version.minor <= 15) {
// Add as a module to deal with @Type(.enum_literal) being deprecated
const zig015 = b.createModule(.{
.root_source_file = b.path("src/android/zig015/zig015.zig"),
.target = target,
.optimize = optimize,
});
android_module.addImport("zig015", zig015);
}
if (builtin.zig_version.major == 0 and builtin.zig_version.minor >= 16) {
// Add as a module to deal with @Type(.enum_literal) being deprecated
const zig016 = b.createModule(.{
.root_source_file = b.path("src/android/zig016/zig016.zig"),
.target = target,
.optimize = optimize,
});
android_module.addImport("zig016", zig016);
}

module.linkSystemLibrary("log", .{});
android_module.linkSystemLibrary("log", .{});
}
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.{
.name = .android,
.version = "0.2.0",
.version = "0.3.0",
.dependencies = .{},
.paths = .{
"build.zig",
Expand Down
4 changes: 2 additions & 2 deletions examples/minimal/src/minimal.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub const std_options: std.Options = if (builtin.abi.isAndroid())
else
.{};

/// custom panic handler for Android
pub const panic = if (builtin.abi.isAndroid())
/// Deprecated: Zig 0.15.2 and lower only, Custom panic handler for Android
pub const panic = if (builtin.abi.isAndroid() and builtin.zig_version.major == 0 and builtin.zig_version.minor <= 15)
android.panic
else
std.debug.FullPanic(std.debug.defaultPanic);
Expand Down
6 changes: 3 additions & 3 deletions examples/raylib/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const builtin = @import("builtin");
const android = @import("android");
const rl = @import("raylib");

pub fn main() void {
pub fn main() !void {
const screenWidth = 800;
const screenHeight = 450;
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
Expand All @@ -19,8 +19,8 @@ pub fn main() void {
}
}

/// custom panic handler for Android
pub const panic = if (builtin.abi.isAndroid())
/// Deprecated: Zig 0.15.2 and lower only, Custom panic handler for Android
pub const panic = if (builtin.abi.isAndroid() and builtin.zig_version.major == 0 and builtin.zig_version.minor <= 15)
android.panic
else
std.debug.FullPanic(std.debug.defaultPanic);
Expand Down
33 changes: 17 additions & 16 deletions examples/sdl2/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub fn build(b: *std.Build) void {
const android_sdk = android.Sdk.create(b, .{});
const apk = android_sdk.createApk(.{
.api_level = .android15,
.build_tools_version = "35.0.1",
.ndk_version = "29.0.13113456",
.build_tools_version = "36.1.0",
.ndk_version = "29.0.14206865",
// NOTE(jae): 2025-03-09
// Previously this example used 'ndk' "27.0.12077973".
//
Expand Down Expand Up @@ -70,14 +70,6 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
.root_source_file = b.path("src/sdl-zig-demo.zig"),
});
var exe: *std.Build.Step.Compile = if (target.result.abi.isAndroid()) b.addLibrary(.{
.name = exe_name,
.root_module = app_module,
.linkage = .dynamic,
}) else b.addExecutable(.{
.name = exe_name,
.root_module = app_module,
});

const library_optimize = if (!target.result.abi.isAndroid())
optimize
Expand All @@ -96,15 +88,15 @@ pub fn build(b: *std.Build) void {
if (target.result.os.tag == .linux and !target.result.abi.isAndroid()) {
// The SDL package doesn't work for Linux yet, so we rely on system
// packages for now.
exe.linkSystemLibrary("SDL2");
exe.linkLibC();
app_module.linkSystemLibrary("SDL2", .{});
app_module.link_libc = true;
} else {
const sdl_lib = sdl_dep.artifact("SDL2");
exe.linkLibrary(sdl_lib);
app_module.linkLibrary(sdl_lib);
}

const sdl_module = sdl_dep.module("sdl");
exe.root_module.addImport("sdl", sdl_module);
app_module.addImport("sdl", sdl_module);
}

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

apk.addArtifact(exe);
const exe_lib = b.addLibrary(.{
.name = exe_name,
.root_module = app_module,
.linkage = .dynamic,
});
apk.addArtifact(exe_lib);
} else {
const exe = b.addExecutable(.{
.name = exe_name,
.root_module = app_module,
});
b.installArtifact(exe);

// If only 1 target, add "run" step
Expand Down
21 changes: 17 additions & 4 deletions examples/sdl2/src/sdl-zig-demo.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ const sdl = @import("sdl");
const log = std.log;
const assert = std.debug.assert;

/// custom standard options for Android
// custom standard options for Android
pub const std_options: std.Options = if (builtin.abi.isAndroid())
.{
.logFn = android.logFn,
}
else
.{};

/// custom panic handler for Android
pub const panic = if (builtin.abi.isAndroid())
/// Deprecated: Zig 0.15.2 and lower only, Custom panic handler for Android
pub const panic = if (builtin.abi.isAndroid() and builtin.zig_version.major == 0 and builtin.zig_version.minor <= 15)
android.panic
else
std.debug.FullPanic(std.debug.defaultPanic);
Expand All @@ -29,7 +29,20 @@ comptime {
/// This needs to be exported for Android builds
fn SDL_main() callconv(.c) void {
if (comptime builtin.abi.isAndroid()) {
_ = std.start.callMain();
if (builtin.zig_version.major == 0 and builtin.zig_version.minor <= 14) {
_ = std.start.callMain();
} else if (builtin.zig_version.major == 0 and builtin.zig_version.minor <= 15) {
main() catch |err| {
log.err("{s}", .{@errorName(err)});
if (@errorReturnTrace()) |trace| {
if (builtin.zig_version.major == 0 and builtin.zig_version.minor <= 15) {
std.debug.dumpStackTrace(trace.*);
} else {
std.debug.dumpStackTrace(trace);
}
}
};
}
} else {
@compileError("SDL_main should not be called outside of Android builds");
}
Expand Down
Loading