From b746d01522814ac9af7912af1b66bd10b1216c07 Mon Sep 17 00:00:00 2001 From: tobtoht Date: Mon, 26 Aug 2024 12:12:42 +0200 Subject: [PATCH] depends: android_ndk: update to 27 (latest LTS) --- contrib/depends/hosts/android.mk | 22 ++++++++++---- contrib/depends/packages/android_ndk.mk | 24 ++++----------- contrib/depends/packages/openssl.mk | 9 +++--- .../patches/android_ndk/api_definition.patch | 15 ---------- .../depends/patches/android_ndk/fix_env.patch | 30 ------------------- .../depends/patches/openssl/fix-android.patch | 27 +++++++++++++++++ contrib/depends/toolchain.cmake.in | 19 +++--------- 7 files changed, 57 insertions(+), 89 deletions(-) delete mode 100644 contrib/depends/patches/android_ndk/api_definition.patch delete mode 100644 contrib/depends/patches/android_ndk/fix_env.patch create mode 100644 contrib/depends/patches/openssl/fix-android.patch diff --git a/contrib/depends/hosts/android.mk b/contrib/depends/hosts/android.mk index b08126e86..a7989100a 100644 --- a/contrib/depends/hosts/android.mk +++ b/contrib/depends/hosts/android.mk @@ -1,12 +1,20 @@ ANDROID_API=21 ifeq ($(host_arch),arm) -host_toolchain=arm-linux-androideabi- +host_toolchain=armv7a-linux-androideabi$(ANDROID_API)- +else ifeq ($(host_arch),aarch64) +host_toolchain=aarch64-linux-android$(ANDROID_API)- endif -android_CC=$(host_toolchain)clang -android_CXX=$(host_toolchain)clang++ -android_RANLIB=: +clear_guix_env=env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH \ + -u OBJC_INCLUDE_PATH -u OBJCPLUS_INCLUDE_PATH -u CPATH \ + -u LIBRARY_PATH + +android_CC=$(clear_guix_env) $(build_prefix)/bin/$(host_toolchain)clang +android_CXX=$(clear_guix_env) $(build_prefix)/bin/$(host_toolchain)clang++ + +android_AR=llvm-ar +android_RANLIB=llvm-ranlib android_CFLAGS=-pipe android_CXXFLAGS=$(android_CFLAGS) @@ -20,4 +28,8 @@ android_debug_CXXFLAGS=$(android_debug_CFLAGS) android_native_toolchain=android_ndk -android_cmake_system=Android +# CMake 3.24 fails to detect API level for Android, even if set explicitly in +# toolchain.cmake. It also tries to manually construct paths to clang(++), but we +# want it to always use the options defined here. It's easier to just pretend +# we're a generic Linux target, than to hack around it. +android_cmake_system=Linux diff --git a/contrib/depends/packages/android_ndk.mk b/contrib/depends/packages/android_ndk.mk index e32e47739..2ba828939 100644 --- a/contrib/depends/packages/android_ndk.mk +++ b/contrib/depends/packages/android_ndk.mk @@ -1,29 +1,15 @@ package=android_ndk -$(package)_version=18b +$(package)_version=27c $(package)_download_path=https://dl.google.com/android/repository/ -$(package)_file_name=android-ndk-r$($(package)_version)-linux-x86_64.zip -$(package)_sha256_hash=4f61cbe4bbf6406aa5ef2ae871def78010eed6271af72de83f8bd0b07a9fd3fd -$(package)_patches=api_definition.patch fix_env.patch - -define $(package)_set_vars -$(package)_config_opts_arm=--arch arm -$(package)_config_opts_aarch64=--arch arm64 -endef +$(package)_file_name=android-ndk-r$($(package)_version)-linux.zip +$(package)_sha256_hash=59c2f6dc96743b5daf5d1626684640b20a6bd2b1d85b13156b90333741bad5cc define $(package)_extract_cmds echo $($(package)_sha256_hash) $($(1)_source_dir)/$($(package)_file_name) | sha256sum -c &&\ unzip -q $($(1)_source_dir)/$($(package)_file_name) endef -define $(package)_preprocess_cmds - cd android-ndk-r$($(package)_version) && \ - patch -p1 < $($(package)_patch_dir)/api_definition.patch && \ - patch -p1 < $($(package)_patch_dir)/fix_env.patch -endef - define $(package)_stage_cmds - python3 android-ndk-r$($(package)_version)/build/tools/make_standalone_toolchain.py --api 21 \ - --install-dir $(build_prefix) --stl=libc++ $($(package)_config_opts) &&\ - mv $(build_prefix) $($(package)_staging_dir)/$(host_prefix) + mkdir -p $($(package)_staging_prefix_dir) && \ + mv android-ndk-r$($(package)_version)/toolchains/llvm/prebuilt/linux-x86_64/* $($(package)_staging_prefix_dir) endef - diff --git a/contrib/depends/packages/openssl.mk b/contrib/depends/packages/openssl.mk index 8c9727fa7..e4780036f 100644 --- a/contrib/depends/packages/openssl.mk +++ b/contrib/depends/packages/openssl.mk @@ -3,13 +3,11 @@ $(package)_version=3.0.13 $(package)_download_path=https://www.openssl.org/source $(package)_file_name=$(package)-$($(package)_version).tar.gz $(package)_sha256_hash=88525753f79d3bec27d2fa7c66aa0b92b3aa9498dafd93d7cfa4b3780cdae313 - -# The bundled ranlib in Android NDK 18b inserts timestamps by default. -# To prevent reproducibility issues, we must enable [D]eterministic mode. +$(package)_patches=fix-android.patch define $(package)_set_vars $(package)_config_env=AR="$($(package)_ar)" RANLIB="$($(package)_ranlib)" CC="$($(package)_cc)" -$(package)_config_env_android=ANDROID_NDK_ROOT="$(host_prefix)/native" PATH="$(host_prefix)/native/bin" CC=clang AR=ar RANLIB="ranlib -D" +$(package)_config_env_android=ANDROID_NDK_ROOT="$(host_prefix)/native" PATH="$(host_prefix)/native/bin" $(package)_build_env_android=ANDROID_NDK_ROOT="$(host_prefix)/native" $(package)_config_opts=--prefix=$(host_prefix) --openssldir=$(host_prefix)/etc/openssl --libdir=$(host_prefix)/lib $(package)_config_opts+=no-capieng @@ -52,7 +50,8 @@ $(package)_config_opts_x86_64_freebsd=BSD-x86_64 endef define $(package)_preprocess_cmds - sed -i.old 's|crypto ssl apps util tools fuzz providers doc|crypto ssl util tools providers|' build.info + sed -i.old 's|crypto ssl apps util tools fuzz providers doc|crypto ssl util tools providers|' build.info && \ + patch -p1 < $($(package)_patch_dir)/fix-android.patch endef define $(package)_config_cmds diff --git a/contrib/depends/patches/android_ndk/api_definition.patch b/contrib/depends/patches/android_ndk/api_definition.patch deleted file mode 100644 index 82ef9bad3..000000000 --- a/contrib/depends/patches/android_ndk/api_definition.patch +++ /dev/null @@ -1,15 +0,0 @@ -CMake 3.10.2 compatibility, see: -https://github.com/Kitware/CMake/blob/c1e087a9d3af74299d7681c9f9de59e5977a1539/Modules/Platform/Android-Determine.cmake#L105 - -diff --git a/build/tools/make_standalone_toolchain.py b/build/tools/make_standalone_toolchain.py -index b8172b2..1984595 100755 ---- a/build/tools/make_standalone_toolchain.py -+++ b/build/tools/make_standalone_toolchain.py -@@ -208,6 +208,7 @@ def make_clang_scripts(install_dir, triple, api, windows): - - target = '-'.join([arch, 'none', os_name, env]) - common_flags = '-target {}{}'.format(target, api) -+ common_flags += ' -D__ANDROID_API__={}'.format(api) - - # We only need mstackrealign to fix issues on 32-bit x86 pre-24. After 24, - # this consumes an extra register unnecessarily, which can cause issues for diff --git a/contrib/depends/patches/android_ndk/fix_env.patch b/contrib/depends/patches/android_ndk/fix_env.patch deleted file mode 100644 index 01928dd48..000000000 --- a/contrib/depends/patches/android_ndk/fix_env.patch +++ /dev/null @@ -1,30 +0,0 @@ -diff --git a/build/tools/make_standalone_toolchain.py b/build/tools/make_standalone_toolchain.py -index b8172b2..19c0ad6 100755 ---- a/build/tools/make_standalone_toolchain.py -+++ b/build/tools/make_standalone_toolchain.py -@@ -224,10 +224,10 @@ def make_clang_scripts(install_dir, triple, api, windows): - clang.write(textwrap.dedent("""\ - #!/bin/bash - if [ "$1" != "-cc1" ]; then -- `dirname $0`/clang{version} {flags} "$@" -+ env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH -u OBJC_INCLUDE_PATH -u OBJCPLUS_INCLUDE_PATH -u CPATH -u LIBRARY_PATH `dirname $0`/clang{version} {flags} "$@" - else - # target/triple already spelled out. -- `dirname $0`/clang{version} "$@" -+ env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH -u OBJC_INCLUDE_PATH -u OBJCPLUS_INCLUDE_PATH -u CPATH -u LIBRARY_PATH `dirname $0`/clang{version} "$@" - fi - """.format(version=version_number, flags=unix_flags))) - -@@ -239,10 +239,10 @@ def make_clang_scripts(install_dir, triple, api, windows): - clangpp.write(textwrap.dedent("""\ - #!/bin/bash - if [ "$1" != "-cc1" ]; then -- `dirname $0`/clang{version}++ {flags} "$@" -+ env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH -u OBJC_INCLUDE_PATH -u OBJCPLUS_INCLUDE_PATH -u CPATH -u LIBRARY_PATH `dirname $0`/clang{version}++ {flags} "$@" - else - # target/triple already spelled out. -- `dirname $0`/clang{version}++ "$@" -+ env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH -u OBJC_INCLUDE_PATH -u OBJCPLUS_INCLUDE_PATH -u CPATH -u LIBRARY_PATH `dirname $0`/clang{version}++ "$@" - fi - """.format(version=version_number, flags=unix_flags))) - diff --git a/contrib/depends/patches/openssl/fix-android.patch b/contrib/depends/patches/openssl/fix-android.patch new file mode 100644 index 000000000..aa6649e4e --- /dev/null +++ b/contrib/depends/patches/openssl/fix-android.patch @@ -0,0 +1,27 @@ +OpenSSL's build system tries to be helpful by constructing the compiler name +for us. This doesn't work with our setup. Instead, we want it to use +$($(package)_cc), to ensure certain environment flags are unset. + +diff --git a/Configurations/15-android.conf b/Configurations/15-android.conf +index 41ad9223e0..ea27a3bbba 100644 +--- a/Configurations/15-android.conf ++++ b/Configurations/15-android.conf +@@ -124,17 +124,7 @@ + $user{RANLIB} = ":"; + } + } elsif ($is_standalone_toolchain) { +- my $cc = $user{CC} // "clang"; +- # One can probably argue that both clang and gcc should be +- # probed, but support for "standalone toolchain" was added +- # *after* announcement that gcc is being phased out, so +- # favouring clang is considered adequate. Those who insist +- # have option to enforce test for gcc with CC=gcc. +- if (which("$triarch-$cc") !~ m|^$ndk|) { +- die "no NDK $triarch-$cc on \$PATH"; +- } +- $user{CC} = $cc; +- $user{CROSS_COMPILE} = "$triarch-"; ++ + } elsif ($user{CC} eq "clang") { + die "no NDK clang on \$PATH"; + } else { diff --git a/contrib/depends/toolchain.cmake.in b/contrib/depends/toolchain.cmake.in index eb0da1877..ae32a540d 100644 --- a/contrib/depends/toolchain.cmake.in +++ b/contrib/depends/toolchain.cmake.in @@ -43,6 +43,7 @@ SET(Boost_USE_STATIC_RUNTIME ON) SET(OPENSSL_ROOT_DIR @prefix@) SET(ARCHITECTURE @arch@) +SET(TARGET_OS @host_os@) # for libraries and headers in the target directories set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # Find programs on host @@ -84,22 +85,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") SET(CMAKE_CXX_STANDARD 17) SET(LLVM_ENABLE_PIC OFF) SET(LLVM_ENABLE_PIE OFF) -elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") +elseif(TARGET_OS STREQUAL "android") SET(ANDROID TRUE) - if(ARCHITECTURE STREQUAL "arm") - SET(CMAKE_ANDROID_ARCH_ABI "armeabi-v7a") - SET(CMAKE_SYSTEM_PROCESSOR "armv7-a") - SET(CMAKE_ANDROID_ARM_MODE ON) - SET(CMAKE_C_COMPILER_TARGET arm-linux-androideabi) - SET(CMAKE_CXX_COMPILER_TARGET arm-linux-androideabi) - SET(_CMAKE_TOOLCHAIN_PREFIX arm-linux-androideabi-) - elseif(ARCHITECTURE STREQUAL "aarch64") - SET(CMAKE_ANDROID_ARCH_ABI "arm64-v8a") - SET(CMAKE_SYSTEM_PROCESSOR "aarch64") - endif() - SET(CMAKE_ANDROID_STANDALONE_TOOLCHAIN @prefix@/native) - SET(CMAKE_C_COMPILER "${_CMAKE_TOOLCHAIN_PREFIX}clang") - SET(CMAKE_CXX_COMPILER "${_CMAKE_TOOLCHAIN_PREFIX}clang++") + SET(CMAKE_C_COMPILER @CC@) + SET(CMAKE_CXX_COMPILER @CXX@) else() if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") SET(CMAKE_ASM_COMPILER clang)