Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 17 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,31 @@ jobs:
with:
packages: 'tools platform-tools platforms;android-35 build-tools;35.0.0 ndk;29.0.13113456'

- name: Setup Zig 0.13.0
- name: Setup Zig Stable (0.14.0)
# note(jae): 2024-09-15
# Uses download mirror first as preferred by Zig Foundation
# see: https://ziglang.org/news/migrate-to-self-hosting/
uses: mlugg/setup-zig@v1
with:
version: "0.13.0"
version: "0.14.0"

- name: Build Minimal Example (Zig 0.13.0)
- name: Build Minimal Example (Zig Stable)
run: zig build -Dandroid=true --verbose
working-directory: examples/minimal

- name: Build SDL2 Example (Zig 0.13.0)
- name: Build SDL2 Example (Zig Stable)
run: zig build -Dandroid=true --verbose
working-directory: examples/sdl2

- name: Setup Zig Nightly
uses: mlugg/setup-zig@v1
with:
version: "master"

- name: Build Minimal Example (Zig Nightly)
run: zig build -Dandroid=true --verbose
working-directory: examples/minimal

- name: Build SDL2 Example (Zig Nightly)
run: zig build -Dandroid=true --verbose
working-directory: examples/sdl2
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
.{
.name = "android",
.name = .android,
.version = "0.1.0",
.dependencies = .{},
.paths = .{
"build.zig",
"build.zig.zon",
"src",
},
.minimum_zig_version = "0.13.0",
.minimum_zig_version = "0.14.0",
.fingerprint = 0x92bcb62d42fb2cee,
}
4 changes: 2 additions & 2 deletions examples/minimal/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn build(b: *std.Build) void {
};

for (targets) |target| {
var exe: *std.Build.Step.Compile = if (target.result.isAndroid()) b.addSharedLibrary(.{
var exe: *std.Build.Step.Compile = if (target.result.abi.isAndroid()) b.addSharedLibrary(.{
.name = exe_name,
.root_source_file = b.path("src/minimal.zig"),
.target = target,
Expand All @@ -52,7 +52,7 @@ pub fn build(b: *std.Build) void {
// if building as library for Android, add this target
// NOTE: Android has different CPU targets so you need to build a version of your
// code for x86, x86_64, arm, arm64 and more
if (target.result.abi == .android) {
if (target.result.abi.isAndroid()) {
const apk: *android.APK = android_apk orelse @panic("Android APK should be initialized");
const android_dep = b.dependency("android", .{
.optimize = optimize,
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.{
.name = "minimal",
.name = .minimal,
.version = "0.0.0",
.dependencies = .{
.android = .{
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 @@ -5,15 +5,15 @@ const androidbind = @import("android-bind.zig");
const log = std.log;

/// custom standard options for Android
pub const std_options: std.Options = if (builtin.abi == .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 == .android)
pub const panic = if (builtin.abi.isAndroid())
android.panic
else
std.builtin.default_panic;
Expand Down
6 changes: 3 additions & 3 deletions examples/sdl2/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn build(b: *std.Build) void {

for (targets) |target| {
const exe_name: []const u8 = "sdl-zig-demo";
var exe: *std.Build.Step.Compile = if (target.result.abi == .android) b.addSharedLibrary(.{
var exe: *std.Build.Step.Compile = if (target.result.abi.isAndroid()) b.addSharedLibrary(.{
.name = exe_name,
.root_source_file = b.path("src/sdl-zig-demo.zig"),
.target = target,
Expand All @@ -74,7 +74,7 @@ pub fn build(b: *std.Build) void {
.optimize = .ReleaseFast,
.target = target,
});
if (target.result.os.tag == .linux and target.result.abi != .android) {
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");
Expand All @@ -91,7 +91,7 @@ pub fn build(b: *std.Build) void {
// if building as library for Android, add this target
// NOTE: Android has different CPU targets so you need to build a version of your
// code for x86, x86_64, arm, arm64 and more
if (target.result.abi == .android) {
if (target.result.abi.isAndroid()) {
const apk: *android.APK = android_apk orelse @panic("Android APK should be initialized");
const android_dep = b.dependency("android", .{
.optimize = optimize,
Expand Down
2 changes: 1 addition & 1 deletion examples/sdl2/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.{
.name = "sdl2",
.name = .sdl2,
.version = "0.0.0",
.dependencies = .{
.android = .{
Expand Down
6 changes: 3 additions & 3 deletions examples/sdl2/src/sdl-zig-demo.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ const log = std.log;
const assert = std.debug.assert;

/// custom standard options for Android
pub const std_options: std.Options = if (builtin.abi == .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 == .android)
pub const panic = if (builtin.abi.isAndroid())
android.panic
else
std.builtin.default_panic;

/// This needs to be exported for Android builds
export fn SDL_main() callconv(.C) void {
if (builtin.abi == .android) {
if (builtin.abi.isAndroid()) {
_ = std.start.callMain();
} else {
@panic("SDL_main should not be called outside of Android builds");
Expand Down
4 changes: 2 additions & 2 deletions examples/sdl2/third-party/sdl2/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn build(b: *std.Build) !void {
const sdl_path = sdl_dep.path("");
const sdl_include_path = sdl_path.path(b, "include");

const is_shared_library = target.result.abi == .android; // NOTE(jae): 2024-09-22: Android uses shared library as SDL2 loads it as part of SDLActivity.java
const is_shared_library = target.result.abi.isAndroid(); // NOTE(jae): 2024-09-22: Android uses shared library as SDL2 loads it as part of SDLActivity.java
const lib = if (!is_shared_library) b.addStaticLibrary(.{
.name = "SDL2",
.target = target,
Expand Down Expand Up @@ -72,7 +72,7 @@ pub fn build(b: *std.Build) !void {
lib.linkFramework("CoreHaptics");
},
else => {
if (target.result.abi == .android) {
if (target.result.abi.isAndroid()) {
lib.root_module.addCSourceFiles(.{
.root = sdl_path,
.files = &android_src_files,
Expand Down
4 changes: 2 additions & 2 deletions src/android/android.zig
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ pub const Panic = struct {

fn dumpStackTrace(stack_trace: std.builtin.StackTrace) void {
nosuspend {
if (comptime builtin.target.isWasm()) {
if (comptime builtin.target.cpu.arch.isWasm()) {
if (native_os == .wasi) {
const stderr = io.getStdErr().writer();
stderr.print("Unable to dump stack trace: not implemented for Wasm\n", .{}) catch return;
Expand Down Expand Up @@ -341,7 +341,7 @@ pub const Panic = struct {
const writeCurrentStackTrace = std.debug.writeCurrentStackTrace;
fn dumpCurrentStackTrace(start_addr: ?usize) void {
nosuspend {
if (comptime builtin.target.isWasm()) {
if (comptime builtin.target.cpu.arch.isWasm()) {
if (native_os == .wasi) {
const stderr = io.getStdErr().writer();
stderr.print("Unable to dump stack trace: not implemented for Wasm\n", .{}) catch return;
Expand Down
22 changes: 9 additions & 13 deletions src/androidbuild/androidbuild.zig
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub const KeyStore = struct {
};

pub fn getAndroidTriple(target: ResolvedTarget) error{InvalidAndroidTarget}![]const u8 {
if (target.result.abi != .android) return error.InvalidAndroidTarget;
if (!target.result.abi.isAndroid()) return error.InvalidAndroidTarget;
return switch (target.result.cpu.arch) {
.x86 => "i686-linux-android",
.x86_64 => "x86_64-linux-android",
Expand All @@ -66,7 +66,7 @@ pub fn standardTargets(b: *std.Build, target: ResolvedTarget) []ResolvedTarget {
if (all_targets) {
return getAllAndroidTargets(b);
}
if (target.result.abi != .android) {
if (!target.result.abi.isAndroid()) {
return &[0]ResolvedTarget{};
}
if (target.result.os.tag != .linux) {
Expand Down Expand Up @@ -130,11 +130,7 @@ const AndroidTargetQuery = struct {
return .{
.os_tag = .linux,
.cpu_model = .baseline,
.abi = comptime if (builtin.zig_version.major == 0 and builtin.zig_version.minor == 13)
// NOTE(jae): 2025-03-09
// Zig 0.13.0 doesn't have androideabi
.android
else if (android_target.cpu_arch != .arm) .android else .androideabi,
.abi = if (android_target.cpu_arch != .arm) .android else .androideabi,
.cpu_arch = android_target.cpu_arch,
.cpu_features_add = android_target.cpu_features_add,
};
Expand All @@ -156,10 +152,10 @@ const supported_android_targets = [_]AndroidTargetQuery{
.cpu_features_add = Target.aarch64.featureSet(&.{.v8a}),
},
// NOTE(jae): 2024-09-08
// 'arm-linux-androideabi' doesn't work with Zig 0.13.0 for compiling C code like SDL2 or OpenXR due to "__ARM_ARCH" not being "7"
// .{
// // arm-linux-androideabi
// .cpu_arch = .arm,
// .cpu_features_add = Target.arm.featureSet(&.{.v7a}),
// },
// 'arm-linux-androideabi' previously didn't work with Zig 0.13.0 for compiling C code like SDL2 or OpenXR due to "__ARM_ARCH" not being "7"
.{
// arm-linux-androideabi
.cpu_arch = .arm,
.cpu_features_add = Target.arm.featureSet(&.{.v7a}),
},
};
6 changes: 3 additions & 3 deletions src/androidbuild/apk.zig
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub const APK = struct {
}
}
if (artifact.root_module.resolved_target) |target| {
if (target.result.abi != .android) {
if (!target.result.abi.isAndroid()) {
try errors.append(b.fmt("artifact[{}]: must be targetting Android abi", .{i}));
continue;
}
Expand Down Expand Up @@ -392,7 +392,7 @@ pub const APK = struct {
}
}
apk.tools.setLibCFile(artifact);
apk.addLibraryPaths(&artifact.root_module);
apk.addLibraryPaths(artifact.root_module);
artifact.linkLibC();
}

Expand Down Expand Up @@ -629,7 +629,7 @@ pub const APK = struct {
}

// Add library paths to find "android", "log", etc
apk.addLibraryPaths(&artifact.root_module);
apk.addLibraryPaths(artifact.root_module);

// Update libraries linked to this library
apk.updateLinkObjects(artifact, so_dir, raw_top_level_apk_files);
Expand Down