@@ -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 ,
@@ -117,24 +117,34 @@ pub fn build(b: *std.Build) !void {
117117 // if (builtin.abi == .android) @export(android_sdl_main, .{ .name = "SDL_main", .linkage = .strong });
118118 // }
119119
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
129- lib .root_module .addCSourceFiles (.{
130- .root = sdl_path ,
131- .files = &[_ ][]const u8 {
132- "src/hidapi/android/hid.cpp" ,
133- },
134- .flags = &.{"-std=c++11" },
135- });
136- lib .linkLibCpp ();
137- }
120+ const hidapi_lib = b .addStaticLibrary (.{
121+ .name = "hidapi" ,
122+ .target = target ,
123+ .optimize = optimize ,
124+ .link_libc = true ,
125+ });
126+ hidapi_lib .addIncludePath (sdl_include_path );
127+
128+ // Avoid linking with linkLibCpp() as that causes issues as Zig 0.14.0 attempts to mix
129+ // its own C++ includes with those auto-included by the Zig Android SDK.
130+ //
131+ // However, not linking c++ means when loading on X86_64 systems, you get
132+ // unresolved symbol "_Unwind_Resume" when SDL2 is loaded, so to workaround that
133+ // we link the "unwind" library
134+ hidapi_lib .linkSystemLibrary ("unwind" );
135+
136+ // NOTE(jae): 2024-09-22
137+ // Build settings taken from: SDL2-2.32.2/src/hidapi/android/jni/Android.mk
138+ // SDLActivity.java by default expects to be able to load this library
139+ hidapi_lib .root_module .linkSystemLibrary ("log" , .{});
140+ hidapi_lib .root_module .addCSourceFiles (.{
141+ .root = sdl_path ,
142+ .files = &[_ ][]const u8 {
143+ "src/hidapi/android/hid.cpp" ,
144+ },
145+ .flags = &.{"-std=c++11" },
146+ });
147+ lib .linkLibrary (hidapi_lib );
138148 } else {
139149 const config_header = b .addConfigHeader (.{
140150 .style = .{ .cmake = sdl_include_path .path (b , "SDL_config.h.cmake" ) },
0 commit comments