wernerd / ZRTPCPP

C++ Implementation of ZRTP protocol - GNU ZRTP C++
Other
116 stars 50 forks source link

question: how to set botan build ANDROID_ARCH? #49

Closed juha-h closed 2 years ago

juha-h commented 2 years ago

I tried to build develop branch and it failed like this:

'python' '/usr/src/libbaresip-android/ZRTPCPP/build/_deps/botan-src/amalLibs/../configure.py' '--minimized-build' '--amalgamation' '--cc=clang' '--enable-modules=sha2_32,sha2_64,sha1,twofish,aes,skein,hmac,pubkey,curve25519,cfb,cbc,ec_group,ecdh,dh,dl_group'
CMake Error at build/_deps/botan-src/amalLibs/CMakeLists.txt:84 (MESSAGE):
  botan amalgamation failed: error code: 1, error out: standard out: INFO:
  /usr/src/libbaresip-android/ZRTPCPP/build/_deps/botan-src/amalLibs/../configure.py
  invoked with options "--minimized-build --amalgamation --cc=clang
  --enable-modules=sha2_32,sha2_64,sha1,twofish,aes,skein,hmac,pubkey,curve25519,cfb,cbc,ec_group,ecdh,dh,dl_group"
     INFO: Configuring to build Botan 2.17.3 (revision git:16fabba96f79c6bbf5d28120e393babb3f11e4ec)
     INFO: Running under 2.7.18 (default, Jul 14 2021, 08:11:37) [GCC 10.2.1 20210110]
     INFO: CXX environment variable is set which will override compiler path
     INFO: Implicit --cc-bin=/opt/Android/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang++ due to environment variable CXX
     INFO: Autodetected platform information: OS="Linux" machine="x86_64" proc=""
     INFO: Guessing target OS is linux (use --os to set)
     INFO: Guessing target processor is a x86_64 (use --cpu to set)
     INFO: Using /etc/ssl/certs/ca-certificates.crt as system certificate store
     INFO: Auto-detected compiler version 12.0
     INFO: Auto-detected compiler arch arm64
    ERROR: Configured target is x86_64 but compiler probe indicates arm64

From build dir I found this:

./build/_deps/botan-src/src/scripts/Dockerfile.android:RUN ./configure.py --prefix=android/arm --os=android --cpu=${ANDROID_ARCH} --cc=clang --cc-bin=${ANDROID_ARCH}${ANDROID_ARCH_SUF}-linux-android${ANDROID_TOOLCHAIN_SUF}${ANDROID_SDK_VER}-clang++ --ar-command=${ANDROID_ARCH}${ANDROID_ARCH_SUF}-linux-android${ANDROID_TOOLCHAIN_SUF}-ar

How can I set ANDROID_ARCH? I have tried -DANDROID_ARCH=aarch64-linux-android cmake flag, but it didn't help.

wernerd commented 2 years ago

The develop branch was currently tested with some specific Android and iOS build. For Android build the gradle build file sets up the necessary variables such as the Android CPU. Code snippet of the gradle build file that we use:

        externalNativeBuild {

            // For ndk-build, instead use the ndkBuild block.
            cmake {
                // Passes optional arguments to CMake. Make sure it is a list, not just a string :-) .
                arguments += listOf(
                "-DANDROID_STL=c++_shared",
                "-DANDROID=true",
                "-DSQLCIPHER=true",
                                ...
                               )
                ...

If you call the ZRTP cmake without the gradle Android build then you need to set (select one of the architectures):

-DANDROID -DANDROID_ABI=x86_64|x86|armeabi-v7a|arm64-v8a 

This should work. We have not yet fully tested the develop branch for standalone builds. Also do not enable SIDH. This algorithm is broken and we are currently removing it from the code.

juha-h commented 2 years ago

Thanks for your reply. I'm currently using master branch (core lib only) and the lib works fine with my baresip based open source Android app. I just thought to give try to develop branch, since master has not been updated for a while.

The error came, with this kind of cmake call:

CMAKE_ANDROID_FLAGS := \
    -DANDROID=ON \
    -DCMAKE_SYSTEM_NAME=Android \
    -DCMAKE_SYSTEM_VERSION=$(API_LEVEL) \
    -DCMAKE_TOOLCHAIN_FILE=$(CMAKE_TOOLCHAIN_FILE) \
    -DANDROID_ABI=${ANDROID_TARGET_ARCH} \
    -DCMAKE_ANDROID_ARCH_ABI=$(ANDROID_TARGET_ARCH) \
    -DCMAKE_SKIP_INSTALL_RPATH=ON \
    -DCMAKE_C_COMPILER=$(CC) \
    -DCMAKE_CXX_COMPILER=$(CXX) \
    -DCMAKE_POSITION_INDEPENDENT_CODE=ON

cmake .. $(CMAKE_ANDROID_FLAGS)

where $(ANDROID_TARGET_ARCH) has value arm64-v8a.

I'll keep on trying.

juha-h commented 2 years ago

When cmake starts, it prints:

-- Android: Targeting API '21' with architecture 'arm64', ABI 'arm64-v8a', and processor 'aarch64'

but these values don't reach botan build, because it prints:

INFO: CXX environment variable is set which will override compiler path
     INFO: Implicit --cc-bin=/opt/Android/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang++ due to environment variable CXX
     INFO: Autodetected platform information: OS="Linux" machine="x86_64" proc=""
     INFO: Guessing target OS is linux (use --os to set)
     INFO: Guessing target processor is a x86_64 (use --cpu to set)

Only environment variable CXX is detected.

wernerd commented 2 years ago

Thanks for the feedback, I'll check this.

Regarding the master branch: there were no changes with regard to ZRTP protocol or alike. The current develop branch will be a large change with some new build system stuff, removing old code, cleanup etc. However, the interface to the application will have some small/minor changes only, mainly how ZrtpConfigure is used and some extensions to the ZrtpCache code.