Skip to content

Commit c2ff337

Browse files
committed
Fix build for zig 0.14.0
1 parent 6b3c134 commit c2ff337

File tree

5 files changed

+30
-26
lines changed

5 files changed

+30
-26
lines changed

Sdk.zig

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ const auto_detect = @import("build/auto-detect.zig");
1111
pub fn toolchainHostTag() []const u8 {
1212
const os = builtin.os.tag;
1313
const arch = builtin.cpu.arch;
14-
return (comptime if (std.mem.eql(u8, @tagName(os), "macos")) "darwin" else @tagName(os)) ++ "-" ++ @tagName(arch);
14+
if (std.mem.eql(u8, @tagName(os), "macos")) {
15+
// NOTE: There is no darwin-aarch64 toolchain for Android currently
16+
return "darwin-x86_64";
17+
} else {
18+
return @tagName(os) ++ "-" ++ @tagName(arch);
19+
}
1520
}
1621

1722
/// This file encodes a instance of an Android SDK interface.
@@ -108,8 +113,8 @@ pub fn init(b: *Build, user_config: ?UserConfig, toolchains: ToolchainVersions)
108113
}
109114

110115
pub const ToolchainVersions = struct {
111-
build_tools_version: []const u8 = "33.0.1",
112-
ndk_version: []const u8 = "25.1.8937393",
116+
build_tools_version: []const u8 = "34.0.0",
117+
ndk_version: []const u8 = "27.2.12479018",
113118
};
114119

115120
pub const AndroidVersion = enum(u16) {
@@ -179,8 +184,7 @@ pub const AppConfig = struct {
179184
package_name: []const u8,
180185

181186
/// The android version which is embedded in the manifset.
182-
/// The default is Android 9, it's more than 4 years old by now and should be widespread enough to be a reasonable default.
183-
target_version: AndroidVersion = .android9,
187+
target_version: AndroidVersion = .android13,
184188

185189
/// The resource directory that will contain the manifest and other app resources.
186190
/// This should be a distinct directory per app.
@@ -466,7 +470,7 @@ pub fn createApp(
466470
\\android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
467471
else
468472
\\
469-
;
473+
;
470474

471475
writer.print(
472476
\\ <application android:debuggable="true" android:hasCode="{[hasCode]}" android:label="@string/app_name" {[theme]s} tools:replace="android:icon,android:theme,android:allowBackup,label" android:icon="@mipmap/icon" >
@@ -877,7 +881,7 @@ pub fn compileAppLibrary(
877881
exe.bundle_compiler_rt = true;
878882
exe.export_table = true;
879883

880-
exe.defineCMacro("ANDROID", null);
884+
exe.root_module.addCMacro("ANDROID", "");
881885

882886
exe.linkLibC();
883887
for (app_config.libraries) |lib| {

build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn build(b: *std.Build) !void {
99
// Default-initialize SDK
1010
const sdk = Sdk.init(b, null, .{});
1111
const mode = b.standardOptimizeOption(.{});
12-
const android_version = b.option(Sdk.AndroidVersion, "android", "Select the android version, default is 'android5'") orelse .android5;
12+
const android_version = b.option(Sdk.AndroidVersion, "android", "Select the android version, default is 'android13'") orelse .android13;
1313
const aaudio = b.option(bool, "aaudio", "Compile with support for AAudio, default is 'false'") orelse false;
1414
const opensl = b.option(bool, "opensl", "Compile with support for OpenSL ES, default is 'true'") orelse true;
1515

examples/invocationhandler/main.zig

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ const ButtonData = struct {
2020
};
2121

2222
pub fn timerInvoke(data: ?*anyopaque, jni: *android.JNI, method: android.jobject, args: android.jobjectArray) !android.jobject {
23-
var btn_data = @ptrCast(*ButtonData, @alignCast(@alignOf(*ButtonData), data));
23+
var btn_data: *ButtonData = @ptrCast(@alignCast(data));
2424
btn_data.count += 1;
2525
std.log.info("Running invoke!", .{});
2626
const method_name = try android.JNI.String.init(jni, try jni.callObjectMethod(method, "getName", "()Ljava/lang/String;", .{}));
2727
defer method_name.deinit(jni);
28-
std.log.info("Method {}", .{std.unicode.fmtUtf16le(method_name.slice)});
28+
std.log.info("Method {}", .{std.unicode.fmtUtf16Le(method_name.slice)});
2929

3030
const length = try jni.invokeJni(.GetArrayLength, .{args});
3131
var i: i32 = 0;
3232
while (i < length) : (i += 1) {
3333
const object = try jni.invokeJni(.GetObjectArrayElement, .{ args, i });
3434
const string = try android.JNI.String.init(jni, try jni.callObjectMethod(object, "toString", "()Ljava/lang/String;", .{}));
3535
defer string.deinit(jni);
36-
std.log.info("Arg {}: {}", .{ i, std.unicode.fmtUtf16le(string.slice) });
36+
std.log.info("Arg {}: {}", .{ i, std.unicode.fmtUtf16Le(string.slice) });
3737

3838
if (i == 0) {
3939
const Button = try jni.findClass("android/widget/Button");
@@ -61,10 +61,10 @@ pub const AndroidApp = struct {
6161

6262
// This is needed because to run a callback on the UI thread Looper you must
6363
// react to a fd change, so we use a pipe to force it
64-
pipe: [2]std.os.fd_t = undefined,
64+
pipe: [2]std.posix.fd_t = undefined,
6565
// This is used with futexes so that runOnUiThread waits until the callback is completed
6666
// before returning.
67-
uiThreadCondition: std.atomic.Atomic(u32) = std.atomic.Atomic(u32).init(0),
67+
uiThreadCondition: std.atomic.Value(u32) = std.atomic.Value(u32).init(0),
6868
uiThreadLooper: *android.ALooper = undefined,
6969
uiThreadId: std.Thread.Id = undefined,
7070

@@ -83,10 +83,10 @@ pub const AndroidApp = struct {
8383
// Initialize the variables we need to execute functions on the UI thread
8484
self.uiThreadLooper = android.ALooper_forThread().?;
8585
self.uiThreadId = std.Thread.getCurrentId();
86-
self.pipe = try std.os.pipe();
86+
self.pipe = try std.posix.pipe();
8787
android.ALooper_acquire(self.uiThreadLooper);
8888

89-
var native_activity = android.NativeActivity.init(self.activity);
89+
const native_activity = android.NativeActivity.init(self.activity);
9090
var jni = native_activity.jni;
9191
self.uiJni = native_activity;
9292

@@ -125,7 +125,7 @@ pub const AndroidApp = struct {
125125

126126
const Instance = struct {
127127
fn callback(_: c_int, _: c_int, data: ?*anyopaque) callconv(.C) c_int {
128-
const data_struct = @ptrCast(*Data, @alignCast(@alignOf(Data), data.?));
128+
const data_struct: *Data = @ptrCast(@alignCast(data.?));
129129
const self_ptr = data_struct.self;
130130
defer self_ptr.allocator.destroy(data_struct);
131131

@@ -143,7 +143,7 @@ pub const AndroidApp = struct {
143143
Instance.callback,
144144
data_ptr,
145145
);
146-
std.debug.assert(try std.os.write(self.pipe[1], "hello") == 5);
146+
std.debug.assert(try std.posix.write(self.pipe[1], "hello") == 5);
147147
if (result == -1) {
148148
return error.LooperError;
149149
}
@@ -156,7 +156,7 @@ pub const AndroidApp = struct {
156156
}
157157

158158
pub fn deinit(self: *AndroidApp) void {
159-
@atomicStore(bool, &self.running, false, .SeqCst);
159+
@atomicStore(bool, &self.running, false, .seq_cst);
160160
if (self.thread) |thread| {
161161
thread.join();
162162
self.thread = null;

examples/textview/main.zig

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const c = android.egl.c;
1313
const app_log = std.log.scoped(.app);
1414
comptime {
1515
_ = android.ANativeActivity_createFunc;
16-
_ = @import("root").log;
1716
}
1817

1918
pub const AndroidApp = struct {
@@ -29,10 +28,10 @@ pub const AndroidApp = struct {
2928

3029
// This is needed because to run a callback on the UI thread Looper you must
3130
// react to a fd change, so we use a pipe to force it
32-
pipe: [2]std.os.fd_t = undefined,
31+
pipe: [2]std.posix.fd_t = undefined,
3332
// This is used with futexes so that runOnUiThread waits until the callback is completed
3433
// before returning.
35-
uiThreadCondition: std.atomic.Atomic(u32) = std.atomic.Atomic(u32).init(0),
34+
uiThreadCondition: std.atomic.Value(u32) = std.atomic.Value(u32).init(0),
3635
uiThreadLooper: *android.ALooper = undefined,
3736
uiThreadId: std.Thread.Id = undefined,
3837

@@ -49,7 +48,7 @@ pub const AndroidApp = struct {
4948
// Initialize the variables we need to execute functions on the UI thread
5049
self.uiThreadLooper = android.ALooper_forThread().?;
5150
self.uiThreadId = std.Thread.getCurrentId();
52-
self.pipe = try std.os.pipe();
51+
self.pipe = try std.posix.pipe();
5352
android.ALooper_acquire(self.uiThreadLooper);
5453

5554
var native_activity = NativeActivity.init(self.activity);
@@ -91,7 +90,7 @@ pub const AndroidApp = struct {
9190

9291
const Instance = struct {
9392
fn callback(_: c_int, _: c_int, data: ?*anyopaque) callconv(.C) c_int {
94-
const data_struct = @ptrCast(*Data, @alignCast(@alignOf(Data), data.?));
93+
const data_struct: *Data = @ptrCast(@alignCast(data.?));
9594
const self_ptr = data_struct.self;
9695
defer self_ptr.allocator.destroy(data_struct);
9796

@@ -109,7 +108,7 @@ pub const AndroidApp = struct {
109108
Instance.callback,
110109
data_ptr,
111110
);
112-
std.debug.assert(try std.os.write(self.pipe[1], "hello") == 5);
111+
std.debug.assert(try std.posix.write(self.pipe[1], "hello") == 5);
113112
if (result == -1) {
114113
return error.LooperError;
115114
}
@@ -122,7 +121,7 @@ pub const AndroidApp = struct {
122121
}
123122

124123
pub fn deinit(self: *AndroidApp) void {
125-
@atomicStore(bool, &self.running, false, .SeqCst);
124+
@atomicStore(bool, &self.running, false, .seq_cst);
126125
if (self.thread) |thread| {
127126
thread.join();
128127
self.thread = null;

src/NativeInvocationHandler.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ const InvocationHandler = struct {
5959
const Class = try jni.invokeJni(.GetObjectClass, .{this});
6060
const ptrField = try jni.invokeJni(.GetFieldID, .{ Class, "ptr", "J" });
6161
const jptr = try jni.getLongField(this, ptrField);
62-
const h = @as(*InvocationHandler, @ptrFromInt(jptr));
62+
const uptr: usize = @intCast(jptr);
63+
const h = @as(*InvocationHandler, @ptrFromInt(uptr));
6364
return h.function(h.pointer, jni, method, args);
6465
}
6566
};

0 commit comments

Comments
 (0)