diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 022720a..465b4fa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/build.zig.zon b/build.zig.zon index 06ac663..8b19a3c 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,5 +1,5 @@ .{ - .name = "android", + .name = .android, .version = "0.1.0", .dependencies = .{}, .paths = .{ @@ -7,6 +7,6 @@ "build.zig.zon", "src", }, - .minimum_zig_version = "0.13.0", + .minimum_zig_version = "0.14.0", .fingerprint = 0x92bcb62d42fb2cee, } diff --git a/examples/minimal/build.zig b/examples/minimal/build.zig index fe67f51..6b8837a 100644 --- a/examples/minimal/build.zig +++ b/examples/minimal/build.zig @@ -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, @@ -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, diff --git a/examples/minimal/build.zig.zon b/examples/minimal/build.zig.zon index d32c5a9..cc8982c 100644 --- a/examples/minimal/build.zig.zon +++ b/examples/minimal/build.zig.zon @@ -1,5 +1,5 @@ .{ - .name = "minimal", + .name = .minimal, .version = "0.0.0", .dependencies = .{ .android = .{ diff --git a/examples/minimal/src/minimal.zig b/examples/minimal/src/minimal.zig index f3e8222..fd69a33 100644 --- a/examples/minimal/src/minimal.zig +++ b/examples/minimal/src/minimal.zig @@ -5,7 +5,7 @@ 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, } @@ -13,7 +13,7 @@ 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; diff --git a/examples/sdl2/build.zig b/examples/sdl2/build.zig index 0b89686..eec6e45 100644 --- a/examples/sdl2/build.zig +++ b/examples/sdl2/build.zig @@ -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, @@ -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"); @@ -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, diff --git a/examples/sdl2/build.zig.zon b/examples/sdl2/build.zig.zon index 4a3d6aa..ca57d66 100644 --- a/examples/sdl2/build.zig.zon +++ b/examples/sdl2/build.zig.zon @@ -1,5 +1,5 @@ .{ - .name = "sdl2", + .name = .sdl2, .version = "0.0.0", .dependencies = .{ .android = .{ diff --git a/examples/sdl2/src/sdl-zig-demo.zig b/examples/sdl2/src/sdl-zig-demo.zig index 01d5e66..cbba322 100644 --- a/examples/sdl2/src/sdl-zig-demo.zig +++ b/examples/sdl2/src/sdl-zig-demo.zig @@ -7,7 +7,7 @@ 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, } @@ -15,14 +15,14 @@ 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"); diff --git a/examples/sdl2/third-party/sdl2/build.zig b/examples/sdl2/third-party/sdl2/build.zig index 21a5ec8..ee23f92 100644 --- a/examples/sdl2/third-party/sdl2/build.zig +++ b/examples/sdl2/third-party/sdl2/build.zig @@ -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, @@ -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, diff --git a/src/android/android.zig b/src/android/android.zig index 7218030..0628e7f 100644 --- a/src/android/android.zig +++ b/src/android/android.zig @@ -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; @@ -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; diff --git a/src/androidbuild/androidbuild.zig b/src/androidbuild/androidbuild.zig index 94976b6..e422bbf 100644 --- a/src/androidbuild/androidbuild.zig +++ b/src/androidbuild/androidbuild.zig @@ -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", @@ -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) { @@ -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, }; @@ -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}), + }, }; diff --git a/src/androidbuild/apk.zig b/src/androidbuild/apk.zig index b4d1202..b039daa 100644 --- a/src/androidbuild/apk.zig +++ b/src/androidbuild/apk.zig @@ -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; } @@ -392,7 +392,7 @@ pub const APK = struct { } } apk.tools.setLibCFile(artifact); - apk.addLibraryPaths(&artifact.root_module); + apk.addLibraryPaths(artifact.root_module); artifact.linkLibC(); } @@ -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);