Skip to content

Commit 83c80cf

Browse files
Update to Zig 0.14.0 (#16)
**Goals before merge:** - Investigate and look into making any code changes where we can retain 0.13.0 compatibility - #17 **Fixes** - #3 - SDL2's android/hidapi.cpp is able to be compiled by avoiding linking C++ with Zig (currently explodes)
1 parent 8f635ee commit 83c80cf

File tree

12 files changed

+47
-38
lines changed

12 files changed

+47
-38
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,31 @@ jobs:
3737
with:
3838
packages: 'tools platform-tools platforms;android-35 build-tools;35.0.0 ndk;29.0.13113456'
3939

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

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

52-
- name: Build SDL2 Example (Zig 0.13.0)
52+
- name: Build SDL2 Example (Zig Stable)
53+
run: zig build -Dandroid=true --verbose
54+
working-directory: examples/sdl2
55+
56+
- name: Setup Zig Nightly
57+
uses: mlugg/setup-zig@v1
58+
with:
59+
version: "master"
60+
61+
- name: Build Minimal Example (Zig Nightly)
62+
run: zig build -Dandroid=true --verbose
63+
working-directory: examples/minimal
64+
65+
- name: Build SDL2 Example (Zig Nightly)
5366
run: zig build -Dandroid=true --verbose
5467
working-directory: examples/sdl2

build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
.{
2-
.name = "android",
2+
.name = .android,
33
.version = "0.1.0",
44
.dependencies = .{},
55
.paths = .{
66
"build.zig",
77
"build.zig.zon",
88
"src",
99
},
10-
.minimum_zig_version = "0.13.0",
10+
.minimum_zig_version = "0.14.0",
1111
.fingerprint = 0x92bcb62d42fb2cee,
1212
}

examples/minimal/build.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub fn build(b: *std.Build) void {
3737
};
3838

3939
for (targets) |target| {
40-
var exe: *std.Build.Step.Compile = if (target.result.isAndroid()) b.addSharedLibrary(.{
40+
var exe: *std.Build.Step.Compile = if (target.result.abi.isAndroid()) b.addSharedLibrary(.{
4141
.name = exe_name,
4242
.root_source_file = b.path("src/minimal.zig"),
4343
.target = target,
@@ -52,7 +52,7 @@ pub fn build(b: *std.Build) void {
5252
// if building as library for Android, add this target
5353
// NOTE: Android has different CPU targets so you need to build a version of your
5454
// code for x86, x86_64, arm, arm64 and more
55-
if (target.result.abi == .android) {
55+
if (target.result.abi.isAndroid()) {
5656
const apk: *android.APK = android_apk orelse @panic("Android APK should be initialized");
5757
const android_dep = b.dependency("android", .{
5858
.optimize = optimize,

examples/minimal/build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.{
2-
.name = "minimal",
2+
.name = .minimal,
33
.version = "0.0.0",
44
.dependencies = .{
55
.android = .{

examples/minimal/src/minimal.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ const androidbind = @import("android-bind.zig");
55
const log = std.log;
66

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

1515
/// custom panic handler for Android
16-
pub const panic = if (builtin.abi == .android)
16+
pub const panic = if (builtin.abi.isAndroid())
1717
android.panic
1818
else
1919
std.builtin.default_panic;

examples/sdl2/build.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn build(b: *std.Build) void {
5656

5757
for (targets) |target| {
5858
const exe_name: []const u8 = "sdl-zig-demo";
59-
var exe: *std.Build.Step.Compile = if (target.result.abi == .android) b.addSharedLibrary(.{
59+
var exe: *std.Build.Step.Compile = if (target.result.abi.isAndroid()) b.addSharedLibrary(.{
6060
.name = exe_name,
6161
.root_source_file = b.path("src/sdl-zig-demo.zig"),
6262
.target = target,
@@ -74,7 +74,7 @@ pub fn build(b: *std.Build) void {
7474
.optimize = .ReleaseFast,
7575
.target = target,
7676
});
77-
if (target.result.os.tag == .linux and target.result.abi != .android) {
77+
if (target.result.os.tag == .linux and !target.result.abi.isAndroid()) {
7878
// The SDL package doesn't work for Linux yet, so we rely on system
7979
// packages for now.
8080
exe.linkSystemLibrary("SDL2");
@@ -91,7 +91,7 @@ pub fn build(b: *std.Build) void {
9191
// if building as library for Android, add this target
9292
// NOTE: Android has different CPU targets so you need to build a version of your
9393
// code for x86, x86_64, arm, arm64 and more
94-
if (target.result.abi == .android) {
94+
if (target.result.abi.isAndroid()) {
9595
const apk: *android.APK = android_apk orelse @panic("Android APK should be initialized");
9696
const android_dep = b.dependency("android", .{
9797
.optimize = optimize,

examples/sdl2/build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.{
2-
.name = "sdl2",
2+
.name = .sdl2,
33
.version = "0.0.0",
44
.dependencies = .{
55
.android = .{

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ const log = std.log;
77
const assert = std.debug.assert;
88

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

1717
/// custom panic handler for Android
18-
pub const panic = if (builtin.abi == .android)
18+
pub const panic = if (builtin.abi.isAndroid())
1919
android.panic
2020
else
2121
std.builtin.default_panic;
2222

2323
/// This needs to be exported for Android builds
2424
export fn SDL_main() callconv(.C) void {
25-
if (builtin.abi == .android) {
25+
if (builtin.abi.isAndroid()) {
2626
_ = std.start.callMain();
2727
} else {
2828
@panic("SDL_main should not be called outside of Android builds");

examples/sdl2/third-party/sdl2/build.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn build(b: *std.Build) !void {
99
const sdl_path = sdl_dep.path("");
1010
const sdl_include_path = sdl_path.path(b, "include");
1111

12-
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
12+
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
1313
const lib = if (!is_shared_library) b.addStaticLibrary(.{
1414
.name = "SDL2",
1515
.target = target,
@@ -72,7 +72,7 @@ pub fn build(b: *std.Build) !void {
7272
lib.linkFramework("CoreHaptics");
7373
},
7474
else => {
75-
if (target.result.abi == .android) {
75+
if (target.result.abi.isAndroid()) {
7676
lib.root_module.addCSourceFiles(.{
7777
.root = sdl_path,
7878
.files = &android_src_files,

src/android/android.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ pub const Panic = struct {
306306

307307
fn dumpStackTrace(stack_trace: std.builtin.StackTrace) void {
308308
nosuspend {
309-
if (comptime builtin.target.isWasm()) {
309+
if (comptime builtin.target.cpu.arch.isWasm()) {
310310
if (native_os == .wasi) {
311311
const stderr = io.getStdErr().writer();
312312
stderr.print("Unable to dump stack trace: not implemented for Wasm\n", .{}) catch return;
@@ -341,7 +341,7 @@ pub const Panic = struct {
341341
const writeCurrentStackTrace = std.debug.writeCurrentStackTrace;
342342
fn dumpCurrentStackTrace(start_addr: ?usize) void {
343343
nosuspend {
344-
if (comptime builtin.target.isWasm()) {
344+
if (comptime builtin.target.cpu.arch.isWasm()) {
345345
if (native_os == .wasi) {
346346
const stderr = io.getStdErr().writer();
347347
stderr.print("Unable to dump stack trace: not implemented for Wasm\n", .{}) catch return;

0 commit comments

Comments
 (0)