rust-lang / libz-sys

Rust crate package to link to a system libz (zlib)
Apache License 2.0
110 stars 73 forks source link

[libz-ng-sys] build for aarch64-linux-android #149

Closed secext2022 closed 10 months ago

secext2022 commented 10 months ago

We need to modify build.rs to build libz-ng-sys for aarch64-linux-android:

diff '--color=auto' -ru -x Cargo.lock workdir-1/libz-ng-sys-1.1.12/build_zng.rs workdir/libz-ng-sys-1.1.12/build_zng.rs
--- workdir-1/libz-ng-sys-1.1.12/build_zng.rs   2023-08-21 15:28:56.175241480 +0800
+++ workdir/libz-ng-sys-1.1.12/build_zng.rs 2023-08-21 18:15:47.439786414 +0800
@@ -17,6 +17,10 @@
     if target == "i686-pc-windows-msvc" {
         cmake.define("CMAKE_GENERATOR_PLATFORM", "Win32");
     }
+    // Android
+    if target.contains("android") {
+        cmake.define("CMAKE_ANDROID_NDK", env::var("ANDROID_NDK_HOME").unwrap());
+    }

     let install_dir = cmake.build();
Byron commented 10 months ago

Thank you. Could you submit this as PR? Then a CI can run against it, and maybe it's also possible to setup CI to test on android then.

secext2022 commented 10 months ago

Sorry, this is not a BUG of libz-ng-sys, it is my mistake.

Because I only set environment variable ANDROID_NDK_HOME, but not set ANDROID_NDK, so cmake can not find NDK. And will get this error:

[libz-ng-sys 1.1.12] -- Using CMake version 3.27.1
[libz-ng-sys 1.1.12] -- ZLIB_HEADER_VERSION: 1.2.13
[libz-ng-sys 1.1.12] -- ZLIBNG_HEADER_VERSION: 2.1.3
[libz-ng-sys 1.1.12] CMake Error at /usr/share/cmake/Modules/Platform/Android-Determine.cmake:217 (message):
[libz-ng-sys 1.1.12]   Android: Neither the NDK or a standalone toolchain was found.
[libz-ng-sys 1.1.12] Call Stack (most recent call first):
[libz-ng-sys 1.1.12]   /usr/share/cmake/Modules/CMakeDetermineSystem.cmake:190 (include)
[libz-ng-sys 1.1.12]   CMakeLists.txt:35 (project)
[libz-ng-sys 1.1.12] 
[libz-ng-sys 1.1.12] 
[libz-ng-sys 1.1.12] CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
[libz-ng-sys 1.1.12] -- Configuring incomplete, errors occurred!
[libz-ng-sys 1.1.12] thread 'main' panicked at '
[libz-ng-sys 1.1.12] command did not execute successfully, got: exit status: 1

Just set ANDROID_NDK to the same value as ANDROID_NDK_HOME will fix this error.

Sorry for my mistake.