Skip to content

Commit e113b13

Browse files
committed
start work on updating to Zig 0.14.0
1 parent ea49343 commit e113b13

File tree

12 files changed

+106
-116
lines changed

12 files changed

+106
-116
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Add the following to your build.zig.zon file and run `zig build`.
5252
```zig
5353
.{
5454
.dependencies = .{
55-
.@"zig-android-sdk" = .{
55+
.android = .{
5656
.path = "https://github.com/silbinarywolf/zig-android-sdk/archive/REPLACE_WITH_WANTED_COMMIT.tar.gz",
5757
// .hash = REPLACE_WITH_HASH_FROM_BUILD_ERROR
5858
},

build.zig.zon

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

examples/minimal/build.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const std = @import("std");
22
const builtin = @import("builtin");
3-
const android = @import("zig-android-sdk");
3+
const android = @import("android");
44

55
pub fn build(b: *std.Build) void {
66
const exe_name: []const u8 = "minimal";
@@ -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,9 +52,9 @@ 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.isAndroid()) {
55+
if (target.result.abi.isAndroid()) {
5656
const apk: *android.APK = android_apk orelse @panic("Android APK should be initialized");
57-
const android_dep = b.dependency("zig-android-sdk", .{
57+
const android_dep = b.dependency("android", .{
5858
.optimize = optimize,
5959
.target = target,
6060
});

examples/minimal/build.zig.zon

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.{
2-
.name = "minimal",
2+
.name = .minimal,
33
.version = "0.0.0",
44
.dependencies = .{
5-
.@"zig-android-sdk" = .{
5+
.android = .{
66
.path = "../..",
77
},
88
},
@@ -11,4 +11,5 @@
1111
"build.zig.zon",
1212
"src",
1313
},
14+
.fingerprint = 0x4037f28ad1eb4832,
1415
}

examples/sdl2/android/src/ZigSDLActivity.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public class ZigSDLActivity extends SDLActivity {
99
// @Override
1010
// protected String[] getLibraries() {
1111
// return new String[] {
12-
// "hidapi",
1312
// "SDL2",
1413
// // "SDL2_image",
1514
// // "SDL2_mixer",

examples/sdl2/build.zig

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const std = @import("std");
22
const builtin = @import("builtin");
3-
const android = @import("zig-android-sdk");
3+
const android = @import("android");
44

55
pub fn build(b: *std.Build) void {
66
const root_target = b.standardTargetOptions(.{});
@@ -47,7 +47,7 @@ pub fn build(b: *std.Build) void {
4747

4848
for (targets) |target| {
4949
const exe_name: []const u8 = "sdl-zig-demo";
50-
var exe: *std.Build.Step.Compile = if (target.result.isAndroid()) b.addSharedLibrary(.{
50+
var exe: *std.Build.Step.Compile = if (target.result.abi.isAndroid()) b.addSharedLibrary(.{
5151
.name = exe_name,
5252
.root_source_file = b.path("src/sdl-zig-demo.zig"),
5353
.target = target,
@@ -65,7 +65,7 @@ pub fn build(b: *std.Build) void {
6565
.optimize = .ReleaseFast,
6666
.target = target,
6767
});
68-
if (target.result.os.tag == .linux and !target.result.isAndroid()) {
68+
if (target.result.os.tag == .linux and !target.result.abi.isAndroid()) {
6969
// The SDL package doesn't work for Linux yet, so we rely on system
7070
// packages for now.
7171
exe.linkSystemLibrary("SDL2");
@@ -75,22 +75,16 @@ pub fn build(b: *std.Build) void {
7575
exe.linkLibrary(sdl_lib);
7676
}
7777

78-
// NOTE(jae): 2024-09-22
79-
// Load additional dynamic libraries that SDLActivity.java loads such as hidapi
80-
if (target.result.isAndroid()) {
81-
exe.linkLibrary(sdl_dep.artifact("hidapi"));
82-
}
83-
8478
const sdl_module = sdl_dep.module("sdl");
8579
exe.root_module.addImport("sdl", sdl_module);
8680
}
8781

8882
// if building as library for Android, add this target
8983
// NOTE: Android has different CPU targets so you need to build a version of your
9084
// code for x86, x86_64, arm, arm64 and more
91-
if (target.result.isAndroid()) {
85+
if (target.result.abi.isAndroid()) {
9286
const apk: *android.APK = android_apk orelse @panic("Android APK should be initialized");
93-
const android_dep = b.dependency("zig-android-sdk", .{
87+
const android_dep = b.dependency("android", .{
9488
.optimize = optimize,
9589
.target = target,
9690
});

examples/sdl2/build.zig.zon

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.{
2-
.name = "minimal",
2+
.name = .sdl2,
33
.version = "0.0.0",
44
.dependencies = .{
5-
.@"zig-android-sdk" = .{
5+
.android = .{
66
.path = "../..",
77
},
88
.sdl2 = .{
@@ -14,4 +14,5 @@
1414
"build.zig.zon",
1515
"src",
1616
},
17+
.fingerprint = 0x168fc6b9a7d0df48,
1718
}

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

Lines changed: 71 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -72,89 +72,78 @@ pub fn build(b: *std.Build) !void {
7272
lib.linkFramework("CoreHaptics");
7373
},
7474
else => {
75-
switch (target.result.abi) {
76-
.android => {
75+
if (target.result.abi.isAndroid()) {
76+
lib.root_module.addCSourceFiles(.{
77+
.root = sdl_path,
78+
.files = &android_src_files,
79+
});
80+
81+
// This is needed for "src/render/opengles/SDL_render_gles.c" to compile
82+
lib.root_module.addCMacro("GL_GLEXT_PROTOTYPES", "1");
83+
84+
// Add Java files to dependency
85+
const java_dir = sdl_dep.path("android-project/app/src/main/java/org/libsdl/app");
86+
const java_files: []const []const u8 = &.{
87+
"SDL.java",
88+
"SDLSurface.java",
89+
"SDLActivity.java",
90+
"SDLAudioManager.java",
91+
"SDLControllerManager.java",
92+
"HIDDevice.java",
93+
"HIDDeviceUSB.java",
94+
"HIDDeviceManager.java",
95+
"HIDDeviceBLESteamController.java",
96+
};
97+
const java_write_files = b.addNamedWriteFiles("sdljava");
98+
for (java_files) |java_file_basename| {
99+
_ = java_write_files.addCopyFile(java_dir.path(b, java_file_basename), java_file_basename);
100+
}
101+
102+
// https://github.com/libsdl-org/SDL/blob/release-2.30.6/Android.mk#L82C62-L82C69
103+
lib.linkSystemLibrary("dl");
104+
lib.linkSystemLibrary("GLESv1_CM");
105+
lib.linkSystemLibrary("GLESv2");
106+
lib.linkSystemLibrary("OpenSLES");
107+
lib.linkSystemLibrary("log");
108+
lib.linkSystemLibrary("android");
109+
110+
// SDLActivity.java's getMainFunction defines the entrypoint as "SDL_main"
111+
// So your main / root file will need something like this for Android
112+
//
113+
// fn android_sdl_main() callconv(.C) void {
114+
// _ = std.start.callMain();
115+
// }
116+
// comptime {
117+
// if (builtin.abi == .android) @export(android_sdl_main, .{ .name = "SDL_main", .linkage = .strong });
118+
// }
119+
120+
// TODO(jae): 2025-03-08
121+
// Need to investigate why hidapi is failing as of Zig 0.14.0
122+
const use_hidapi = false;
123+
if (!use_hidapi) {
124+
lib.root_module.addCMacro("SDL_HIDAPI_DISABLED", "");
125+
} else {
126+
// NOTE(jae): 2024-09-22
127+
// Build settings taken from: src/hidapi/android/jni/Android.mk
128+
// SDLActivity.java by default expects to be able to load this library
77129
lib.root_module.addCSourceFiles(.{
78130
.root = sdl_path,
79-
.files = &android_src_files,
131+
.files = &[_][]const u8{
132+
"src/hidapi/android/hid.cpp",
133+
},
134+
.flags = &.{"-std=c++11"},
80135
});
81-
82-
// This is needed for "src/render/opengles/SDL_render_gles.c" to compile
83-
lib.root_module.addCMacro("GL_GLEXT_PROTOTYPES", "1");
84-
85-
// Add Java files to dependency
86-
const java_dir = sdl_dep.path("android-project/app/src/main/java/org/libsdl/app");
87-
const java_files: []const []const u8 = &.{
88-
"SDL.java",
89-
"SDLSurface.java",
90-
"SDLActivity.java",
91-
"SDLAudioManager.java",
92-
"SDLControllerManager.java",
93-
"HIDDevice.java",
94-
"HIDDeviceUSB.java",
95-
"HIDDeviceManager.java",
96-
"HIDDeviceBLESteamController.java",
97-
};
98-
const java_write_files = b.addNamedWriteFiles("sdljava");
99-
for (java_files) |java_file_basename| {
100-
_ = java_write_files.addCopyFile(java_dir.path(b, java_file_basename), java_file_basename);
101-
}
102-
103-
// https://github.com/libsdl-org/SDL/blob/release-2.30.6/Android.mk#L82C62-L82C69
104-
lib.linkSystemLibrary("dl");
105-
lib.linkSystemLibrary("GLESv1_CM");
106-
lib.linkSystemLibrary("GLESv2");
107-
lib.linkSystemLibrary("OpenSLES");
108-
lib.linkSystemLibrary("log");
109-
lib.linkSystemLibrary("android");
110-
111-
// SDLActivity.java's getMainFunction defines the entrypoint as "SDL_main"
112-
// So your main / root file will need something like this for Android
113-
//
114-
// fn android_sdl_main() callconv(.C) void {
115-
// _ = std.start.callMain();
116-
// }
117-
// comptime {
118-
// if (builtin.abi == .android) @export(android_sdl_main, .{ .name = "SDL_main", .linkage = .strong });
119-
// }
120-
121-
const use_hidapi = true;
122-
if (!use_hidapi) {
123-
lib.root_module.addCMacro("SDL_HIDAPI_DISABLED", "");
124-
} else {
125-
// NOTE(jae): 2024-09-22
126-
// Build settings taken from: src/hidapi/android/jni/Android.mk
127-
// SDLActivity.java by default expects to be able to load this library.
128-
const hidapi_lib = b.addSharedLibrary(.{
129-
.name = "hidapi",
130-
.target = target,
131-
.optimize = optimize,
132-
.link_libc = true,
133-
});
134-
hidapi_lib.addIncludePath(sdl_include_path);
135-
hidapi_lib.root_module.addCSourceFiles(.{
136-
.root = sdl_path,
137-
.files = &[_][]const u8{
138-
"src/hidapi/android/hid.cpp",
139-
},
140-
.flags = &.{"-std=c++11"},
141-
});
142-
hidapi_lib.linkSystemLibrary("log");
143-
hidapi_lib.linkLibCpp();
144-
lib.linkLibrary(hidapi_lib);
145-
b.installArtifact(hidapi_lib);
146-
}
147-
},
148-
else => {
149-
const config_header = b.addConfigHeader(.{
150-
.style = .{ .cmake = sdl_include_path.path(b, "SDL_config.h.cmake") },
151-
.include_path = "SDL/SDL_config.h",
152-
}, .{});
153-
sdl_config_header = config_header;
154-
155-
lib.addConfigHeader(config_header);
156-
lib.installConfigHeader(config_header);
157-
},
136+
lib.linkLibCpp();
137+
}
138+
} else {
139+
const config_header = b.addConfigHeader(.{
140+
.style = .{ .cmake = sdl_include_path.path(b, "SDL_config.h.cmake") },
141+
.include_path = "SDL/SDL_config.h",
142+
}, .{});
143+
sdl_config_header = config_header;
144+
145+
lib.addConfigHeader(config_header);
146+
lib.installConfigHeader(config_header);
158147
}
159148
},
160149
}
@@ -167,6 +156,8 @@ pub fn build(b: *std.Build) !void {
167156
b.installArtifact(lib);
168157

169158
var module = b.addModule("sdl", .{
159+
.target = b.graph.host,
160+
.optimize = .ReleaseFast,
170161
.root_source_file = b.path("src/sdl.zig"),
171162
});
172163
if (sdl_config_header) |config_header| {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
.sdl2 = .{
66
// NOTE(jae): 2024-06-30
77
// Using ".zip" as "tar.gz" fails on Windows for Zig 0.13.0 due to symlink issue with something in the android folders
8-
.url = "https://github.com/libsdl-org/SDL/archive/refs/tags/release-2.30.4.zip",
9-
.hash = "122086865a4d5e822c068528a4170cb7da52afad38e8232afa3e74789c4d52d27791",
8+
.url = "https://github.com/libsdl-org/SDL/archive/refs/tags/release-2.32.2.zip",
9+
.hash = "12204a4a9e9f41fc906decd762be78b9e80de65a7bdec428aa0dfdf03f46e7614d9e",
1010
},
1111
},
1212
.paths = .{

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)