Skip to content

Commit 37e0951

Browse files
committed
fix ARM build failing for SDL2
1 parent 52d2b87 commit 37e0951

File tree

5 files changed

+37
-25
lines changed

5 files changed

+37
-25
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@ jobs:
3636
- name: Setup Android SDK
3737
uses: android-actions/setup-android@v3
3838
with:
39-
packages: 'tools platform-tools platforms;android-35 build-tools;35.0.0 ndk;27.0.12077973'
39+
packages: 'tools platform-tools platforms;android-35 build-tools;35.0.0 ndk;29.0.13113456'
4040

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

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

53-
- name: Build SDL2 Example (Zig 0.13.0)
53+
- name: Build SDL2 Example (Zig Nightly)
5454
run: zig build -Dandroid=true --verbose
5555
working-directory: examples/sdl2
5656

@@ -64,11 +64,5 @@ jobs:
6464
working-directory: examples/minimal
6565

6666
- name: Build SDL2 Example (Zig Nightly)
67-
# "zig build -Dandroid=true" fails for 0.14.0-dev.1632
68-
#
69-
# android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/android/hardware_buffer.h:322:42:
70-
# error: expression is not an integral constant expression
71-
#
72-
# See: https://github.com/silbinarywolf/zig-android-sdk/actions/runs/10979711793/job/30484520174?pr=5#step:10:30
73-
run: zig build -Dtarget=x86_64-linux-android --verbose
67+
run: zig build -Dandroid=true --verbose
7468
working-directory: examples/sdl2

examples/minimal/build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn build(b: *std.Build) void {
2222
const android_tools = android.Tools.create(b, .{
2323
.api_level = .android15,
2424
.build_tools_version = "35.0.0",
25-
.ndk_version = "27.0.12077973",
25+
.ndk_version = "29.0.13113456",
2626
});
2727
const apk = android.APK.create(b, android_tools);
2828

examples/sdl2/build.zig

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@ pub fn build(b: *std.Build) void {
2121
const android_tools = android.Tools.create(b, .{
2222
.api_level = .android15,
2323
.build_tools_version = "35.0.0",
24-
.ndk_version = "27.0.12077973",
24+
.ndk_version = "29.0.13113456",
25+
// NOTE(jae): 2025-03-09
26+
// Previously this example used 'ndk' "27.0.12077973".
27+
//
28+
// However that has issues with the latest SDL2 version when including 'hardware_buffer.h'
29+
// for 32-bit builds.
30+
//
31+
// - AHARDWAREBUFFER_USAGE_FRONT_BUFFER = 1UL << 32
32+
// - ndk/27.0.12077973/toolchains/llvm/prebuilt/{OS}-x86_64/sysroot/usr/include/android/hardware_buffer.h:322:42:
33+
// - error: expression is not an integral constant expression
2534
});
2635
const apk = android.APK.create(b, android_tools);
2736

src/androidbuild/androidbuild.zig

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,11 @@ const supported_android_targets = [_]AndroidTargetQuery{
151151
.cpu_arch = .aarch64,
152152
.cpu_features_add = Target.aarch64.featureSet(&.{.v8a}),
153153
},
154-
// TODO(jae): 2024-09-08
155-
// This doesn't work for compiling C code like SDL2 or OpenXR due to "__ARM_ARCH" not being "7"
156-
// or similar. I might be messing something up here but not sure.
157-
//
158-
// TODO(jae): 2025-03-08
159-
// Look into fixing: src/cpuinfo/SDL_cpuinfo.c:93:10: error: 'cpu-features.h' file not found
160-
// .{
161-
// // arm-linux-androideabi
162-
// .cpu_arch = .arm,
163-
// .cpu_features_add = Target.arm.featureSet(&.{.v7a}),
164-
// },
154+
// NOTE(jae): 2024-09-08
155+
// '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"
156+
.{
157+
// arm-linux-androideabi
158+
.cpu_arch = .arm,
159+
.cpu_features_add = Target.arm.featureSet(&.{.v7a}),
160+
},
165161
};

src/androidbuild/apk.zig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ pub const APK = struct {
129129
// - "java.lang.UnsatisfiedLinkError: dlopen failed: TLS symbol "_ZZN8gwp_asan15getThreadLocalsEvE6Locals" in dlopened"
130130
const android_api_version: u32 = @intFromEnum(apk.tools.api_level);
131131

132+
// NOTE(jae): 2025-03-09
133+
// Resolve issue where building SDL2 gets the following error for 'arm-linux-androideabi'
134+
// SDL2-2.32.2/src/cpuinfo/SDL_cpuinfo.c:93:10: error: 'cpu-features.h' file not found
135+
//
136+
// This include is specifically needed for: #if defined(__ANDROID__) && defined(__arm__) && !defined(HAVE_GETAUXVAL)
137+
//
138+
// ie. $ANDROID_HOME/ndk/{ndk_version}/sources/android/cpufeatures
139+
if (module.resolved_target) |resolved_target| {
140+
if (resolved_target.result.cpu.arch == .arm) {
141+
module.addIncludePath(.{ .cwd_relative = b.fmt("{s}/ndk/{s}/sources/android/cpufeatures", .{ apk.tools.android_sdk_path, apk.tools.ndk_version }) });
142+
}
143+
}
144+
132145
// ie. $ANDROID_HOME/ndk/{ndk_version}/toolchains/llvm/prebuilt/{host_os_and_arch}/sysroot ++ usr/lib/aarch64-linux-android/35
133146
module.addLibraryPath(.{ .cwd_relative = b.fmt("{s}/usr/lib/{s}/{d}", .{ android_ndk_sysroot, system_target, android_api_version }) });
134147
// ie. $ANDROID_HOME/ndk/{ndk_version}/toolchains/llvm/prebuilt/{host_os_and_arch}/sysroot ++ /usr/lib/aarch64-linux-android

0 commit comments

Comments
 (0)