From a465f14c90769fd5592b01583c4cb18f5a46d32c Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Thu, 16 Sep 2021 21:51:29 +0200 Subject: [PATCH] Update to use android-ndk r23 --- ndk-patches/linux-fcntl.h.patch | 16 ------- ndk-patches/paths.h.patch | 6 +-- ndk-patches/stdio.h.patch | 16 +++---- ndk-patches/stdlib.h.patch | 7 ++- ndk-patches/sys-cdefs.h.patch | 6 +-- ndk-patches/unistd.h.patch | 8 ++-- ndk-patches/utmp.h.patch | 6 +-- scripts/build/termux_step_setup_toolchain.sh | 45 +++++++------------- scripts/build/termux_step_start_build.sh | 2 +- scripts/properties.sh | 4 +- scripts/setup-android-sdk.sh | 17 +++++--- 11 files changed, 52 insertions(+), 81 deletions(-) delete mode 100644 ndk-patches/linux-fcntl.h.patch diff --git a/ndk-patches/linux-fcntl.h.patch b/ndk-patches/linux-fcntl.h.patch deleted file mode 100644 index a3472b35d..000000000 --- a/ndk-patches/linux-fcntl.h.patch +++ /dev/null @@ -1,16 +0,0 @@ -diff -uNr sysroot.orig/usr/include/linux/fcntl.h sysroot/usr/include/linux/fcntl.h ---- sysroot.orig/usr/include/linux/fcntl.h 2019-02-12 16:12:24.000000000 +0000 -+++ sysroot/usr/include/linux/fcntl.h 2019-03-20 13:22:32.823142545 +0000 -@@ -51,6 +51,12 @@ - #define DN_ATTRIB 0x00000020 - #define DN_MULTISHOT 0x80000000 - #define AT_FDCWD - 100 -+/* Termux patch: This flag is not supported on Android 6.0+, and should not -+ be needed since there are not setuid binaries. Define AT_EACCESS to 0 to -+ avoid packages defining their own AT_EACCESS (which e.g. coreutil does) -+ since that will only result in errors. See: -+ https://android.googlesource.com/platform/bionic/+/3577825%5E!/ */ -+#define AT_EACCESS 0 - #define AT_SYMLINK_NOFOLLOW 0x100 - #define AT_REMOVEDIR 0x200 - #define AT_SYMLINK_FOLLOW 0x400 diff --git a/ndk-patches/paths.h.patch b/ndk-patches/paths.h.patch index f6fb17b92..b5c2684da 100644 --- a/ndk-patches/paths.h.patch +++ b/ndk-patches/paths.h.patch @@ -1,5 +1,5 @@ ---- ./usr/include/paths.h.orig 2020-07-10 21:50:03.778299300 +0000 -+++ ./usr/include/paths.h 2020-07-10 21:51:03.127602196 +0000 +--- ./usr/include/paths.h.orig 2021-08-16 11:55:04.492150066 +0200 ++++ ./usr/include/paths.h 2021-08-16 11:55:42.498804733 +0200 @@ -40,14 +40,14 @@ #ifndef _PATH_BSHELL @@ -12,7 +12,7 @@ #define _PATH_CONSOLE "/dev/console" /** Default shell search path. */ --#define _PATH_DEFPATH "/product/bin:/apex/com.android.runtime/bin:/apex/com.android.art/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin" +-#define _PATH_DEFPATH "/product/bin:/apex/com.android.runtime/bin:/apex/com.android.art/bin:/system_ext/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin" +#define _PATH_DEFPATH "@TERMUX_PREFIX@/bin" /** Path to the directory containing device files. */ diff --git a/ndk-patches/stdio.h.patch b/ndk-patches/stdio.h.patch index 64a267a41..ee509b8d8 100644 --- a/ndk-patches/stdio.h.patch +++ b/ndk-patches/stdio.h.patch @@ -1,7 +1,6 @@ -diff -uNr ./usr.old/include/stdio.h ./usr/include/stdio.h ---- ./usr.old/include/stdio.h 2019-05-22 12:49:28.000000000 +0300 -+++ ./usr/include/stdio.h 2019-12-13 21:50:02.765565736 +0200 -@@ -44,11 +44,12 @@ +--- ./usr/include/stdio.h.orig 2021-08-16 11:48:44.308954400 +0200 ++++ ./usr/include/stdio.h 2021-08-16 11:50:00.438924014 +0200 +@@ -44,6 +44,9 @@ #include #include @@ -10,16 +9,11 @@ diff -uNr ./usr.old/include/stdio.h ./usr/include/stdio.h + #include --#if __ANDROID_API__ < __ANDROID_API_N__ - #include --#endif - - __BEGIN_DECLS - + #if __ANDROID_API__ < 24 @@ -165,7 +166,7 @@ __printflike(2, 0) __warnattr_strict("vsprintf is often misused; please use vsnprintf"); char* tmpnam(char* __s) - __warnattr("tempnam is unsafe, use mkstemp or tmpfile instead"); + __warnattr("tmpnam is unsafe, use mkstemp or tmpfile instead"); -#define P_tmpdir "/tmp/" /* deprecated */ +#define P_tmpdir "@TERMUX_PREFIX@/tmp/" /* deprecated */ char* tempnam(const char* __dir, const char* __prefix) diff --git a/ndk-patches/stdlib.h.patch b/ndk-patches/stdlib.h.patch index 9ef1371c2..bb16db856 100644 --- a/ndk-patches/stdlib.h.patch +++ b/ndk-patches/stdlib.h.patch @@ -1,6 +1,5 @@ -diff -uNr sysroot.orig/usr/include/stdlib.h sysroot/usr/include/stdlib.h ---- sysroot.orig/usr/include/stdlib.h 2019-02-12 16:12:24.000000000 +0000 -+++ sysroot/usr/include/stdlib.h 2019-03-20 13:23:48.870108924 +0000 +--- ./usr/include/stdlib.h.orig 2021-08-16 11:50:47.432239182 +0200 ++++ ./usr/include/stdlib.h 2021-08-16 11:51:31.102222894 +0200 @@ -33,6 +33,7 @@ #include #include @@ -12,7 +11,7 @@ diff -uNr sysroot.orig/usr/include/stdlib.h sysroot/usr/include/stdlib.h @@ -224,8 +225,7 @@ size_t wcstombs(char* __dst, const wchar_t* __src, size_t __n); - #if __ANDROID_API__ >= __ANDROID_API_L__ + #if __ANDROID_API__ >= 21 -size_t __ctype_get_mb_cur_max(void) __INTRODUCED_IN(21); -#define MB_CUR_MAX __ctype_get_mb_cur_max() +#define MB_CUR_MAX 4 diff --git a/ndk-patches/sys-cdefs.h.patch b/ndk-patches/sys-cdefs.h.patch index f4e558f42..35508ca44 100644 --- a/ndk-patches/sys-cdefs.h.patch +++ b/ndk-patches/sys-cdefs.h.patch @@ -1,6 +1,6 @@ ---- ./usr/include/sys/cdefs.h.orig 2020-01-18 00:06:05.760188085 +0000 -+++ ./usr/include/sys/cdefs.h 2020-01-18 00:09:52.363968728 +0000 -@@ -358,3 +358,6 @@ +--- ./usr/include/sys/cdefs.h.orig 2021-08-16 11:52:08.128876161 +0200 ++++ ./usr/include/sys/cdefs.h 2021-08-16 11:52:08.555542676 +0200 +@@ -372,3 +372,6 @@ #if __has_include() #include #endif diff --git a/ndk-patches/unistd.h.patch b/ndk-patches/unistd.h.patch index 4b7a4ce56..37ea0a2fe 100644 --- a/ndk-patches/unistd.h.patch +++ b/ndk-patches/unistd.h.patch @@ -1,6 +1,6 @@ ---- sysroot/usr/include/unistd.h 2018-04-30 19:24:22.000000000 +0000 -+++ usr/include/unistd.h 2018-08-16 10:42:51.158596753 +0000 -@@ -377,4 +377,72 @@ +--- ./usr/include/unistd.h.orig 2021-08-16 11:52:08.095542840 +0200 ++++ ./usr/include/unistd.h 2021-08-16 11:52:08.565542673 +0200 +@@ -375,6 +375,74 @@ #undef _UNISTD_H_ #endif @@ -73,3 +73,5 @@ +#endif + __END_DECLS + + #include diff --git a/ndk-patches/utmp.h.patch b/ndk-patches/utmp.h.patch index 45cc642e2..51932dd25 100644 --- a/ndk-patches/utmp.h.patch +++ b/ndk-patches/utmp.h.patch @@ -1,6 +1,6 @@ ---- sysroot/usr/include/utmp.h 2021-05-07 05:45:33.518467959 +0000 -+++ usr/include/utmp.h 2021-05-07 05:46:25.195022662 +0000 -@@ -32,9 +32,9 @@ +--- ./usr/include/utmp.h.orig 2021-08-16 11:52:08.095542840 +0200 ++++ ./usr/include/utmp.h 2021-08-16 11:52:08.565542673 +0200 +@@ -37,9 +37,9 @@ #include #include diff --git a/scripts/build/termux_step_setup_toolchain.sh b/scripts/build/termux_step_setup_toolchain.sh index b729df1e9..dec2e0627 100644 --- a/scripts/build/termux_step_setup_toolchain.sh +++ b/scripts/build/termux_step_setup_toolchain.sh @@ -8,14 +8,14 @@ termux_step_setup_toolchain() { export AS=$TERMUX_HOST_PLATFORM-clang export CC=$TERMUX_HOST_PLATFORM-clang export CXX=$TERMUX_HOST_PLATFORM-clang++ - export AR=$TERMUX_HOST_PLATFORM-ar + export AR=llvm-ar export CPP=$TERMUX_HOST_PLATFORM-cpp - export LD=$TERMUX_HOST_PLATFORM-ld - export OBJCOPY=$TERMUX_HOST_PLATFORM-objcopy - export OBJDUMP=$TERMUX_HOST_PLATFORM-objdump - export RANLIB=$TERMUX_HOST_PLATFORM-ranlib - export READELF=$TERMUX_HOST_PLATFORM-readelf - export STRIP=$TERMUX_HOST_PLATFORM-strip + export LD=ld.lld + export OBJCOPY=llvm-objcopy + export OBJDUMP=llvm-objdump + export RANLIB=llvm-ranlib + export READELF=llvm-readelf + export STRIP=llvm-strip if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then export PATH=$TERMUX_STANDALONE_TOOLCHAIN/bin:$PATH @@ -146,26 +146,6 @@ termux_setup_standalone_toolchain() { # Remove android-support header wrapping not needed on android-21: rm -Rf $_TERMUX_TOOLCHAIN_TMPDIR/sysroot/usr/local - # Use gold by default to work around https://github.com/android-ndk/ndk/issues/148 - cp $_TERMUX_TOOLCHAIN_TMPDIR/bin/aarch64-linux-android-ld.gold \ - $_TERMUX_TOOLCHAIN_TMPDIR/bin/aarch64-linux-android-ld - cp $_TERMUX_TOOLCHAIN_TMPDIR/aarch64-linux-android/bin/ld.gold \ - $_TERMUX_TOOLCHAIN_TMPDIR/aarch64-linux-android/bin/ld - - # Linker wrapper script to add '--exclude-libs libgcc.a', see - # https://github.com/android-ndk/ndk/issues/379 - # https://android-review.googlesource.com/#/c/389852/ - local linker - for linker in ld ld.bfd ld.gold; do - local wrap_linker=$_TERMUX_TOOLCHAIN_TMPDIR/arm-linux-androideabi/bin/$linker - local real_linker=$_TERMUX_TOOLCHAIN_TMPDIR/arm-linux-androideabi/bin/$linker.real - cp $wrap_linker $real_linker - echo '#!/bin/bash' > $wrap_linker - echo -n '$(dirname $0)/' >> $wrap_linker - echo -n $linker.real >> $wrap_linker - echo ' --exclude-libs libunwind.a --exclude-libs libgcc_real.a "$@"' >> $wrap_linker - done - for HOST_PLAT in aarch64-linux-android armv7a-linux-androideabi i686-linux-android x86_64-linux-android; do cp $_TERMUX_TOOLCHAIN_TMPDIR/bin/$HOST_PLAT$TERMUX_PKG_API_LEVEL-clang \ $_TERMUX_TOOLCHAIN_TMPDIR/bin/$HOST_PLAT-clang @@ -206,13 +186,20 @@ termux_setup_standalone_toolchain() { # Remove as we currently provide it from libandroid-glob. # Remove as it's provided by libiconv. # Remove as it's only for future (later than android-27). - # Remove and as we build our own zlib - rm usr/include/sys/{capability.h,shm.h,sem.h} usr/include/{glob.h,iconv.h,spawn.h,zlib.h,zconf.h} + # Remove and as we build our own zlib. + # Remove unicode headers provided by libicu. + rm usr/include/{sys/{capability,shm,sem},{glob,iconv,spawn,zlib,zconf}}.h + rm usr/include/unicode/{char16ptr,platform,ptypes,putil,stringoptions,ubidi,ubrk,uchar,uconfig,ucpmap,udisplaycontext,uenum,uldnames,ulocdata,uloc,umachine,unorm2,urename,uscript,ustring,utext,utf16,utf8,utf,utf_old,utypes,uvernum,uversion}.h sed -i "s/define __ANDROID_API__ __ANDROID_API_FUTURE__/define __ANDROID_API__ $TERMUX_PKG_API_LEVEL/" \ usr/include/android/api-level.h $TERMUX_ELF_CLEANER usr/lib/*/*/*.so + for dir in usr/lib/*; do + # This seem to be needed when building rust + # packages + echo 'INPUT(-lunwind)' > $dir/libgcc.a + done grep -lrw $_TERMUX_TOOLCHAIN_TMPDIR/sysroot/usr/include/c++/v1 -e '' | xargs -n 1 sed -i 's//\"version\"/g' mv $_TERMUX_TOOLCHAIN_TMPDIR $TERMUX_STANDALONE_TOOLCHAIN diff --git a/scripts/build/termux_step_start_build.sh b/scripts/build/termux_step_start_build.sh index 7580cd6bd..a34cbbd5c 100644 --- a/scripts/build/termux_step_start_build.sh +++ b/scripts/build/termux_step_start_build.sh @@ -2,7 +2,7 @@ termux_step_start_build() { TERMUX_STANDALONE_TOOLCHAIN="$TERMUX_COMMON_CACHEDIR/android-r${TERMUX_NDK_VERSION}-api-${TERMUX_PKG_API_LEVEL}" # Bump the below version if a change is made in toolchain setup to ensure # that everyone gets an updated toolchain: - TERMUX_STANDALONE_TOOLCHAIN+="-v5" + TERMUX_STANDALONE_TOOLCHAIN+="-v0" # shellcheck source=/dev/null source "$TERMUX_PKG_BUILDER_SCRIPT" diff --git a/scripts/properties.sh b/scripts/properties.sh index 01e321170..54ed345a7 100644 --- a/scripts/properties.sh +++ b/scripts/properties.sh @@ -1,6 +1,6 @@ TERMUX_ANDROID_BUILD_TOOLS_VERSION=30.0.3 -TERMUX_NDK_VERSION_NUM=21 -TERMUX_NDK_REVISION="d" +TERMUX_NDK_VERSION_NUM=23 +TERMUX_NDK_REVISION="" TERMUX_NDK_VERSION=$TERMUX_NDK_VERSION_NUM$TERMUX_NDK_REVISION export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 diff --git a/scripts/setup-android-sdk.sh b/scripts/setup-android-sdk.sh index dce0085ef..584f891a6 100755 --- a/scripts/setup-android-sdk.sh +++ b/scripts/setup-android-sdk.sh @@ -4,10 +4,10 @@ set -e -u # Install desired parts of the Android SDK: . $(cd "$(dirname "$0")"; pwd)/properties.sh -ANDROID_SDK_FILE=sdk-tools-linux-4333796.zip -ANDROID_SDK_SHA256=92ffee5a1d98d856634e8b71132e8a95d96c83a63fde1099be3d86df3106def9 -ANDROID_NDK_FILE=android-ndk-r${TERMUX_NDK_VERSION}-Linux-x86_64.zip -ANDROID_NDK_SHA256=dd6dc090b6e2580206c64bcee499bc16509a5d017c6952dcd2bed9072af67cbd +ANDROID_SDK_FILE=commandlinetools-linux-7583922_latest.zip +ANDROID_SDK_SHA256=124f2d5115eee365df6cf3228ffbca6fc3911d16f8025bebd5b1c6e2fcfa7faf +ANDROID_NDK_FILE=android-ndk-r${TERMUX_NDK_VERSION}-linux.zip +ANDROID_NDK_SHA256=e3eacf80016b91d4cd2c8ca9f34eebd32df912bb799c859cc5450b6b19277b4f if [ ! -d $ANDROID_HOME ]; then mkdir -p $ANDROID_HOME cd $ANDROID_HOME/.. @@ -39,7 +39,12 @@ if [ ! -d $NDK ]; then rm ndk.zip fi -yes | $ANDROID_HOME/tools/bin/sdkmanager --licenses +yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME --licenses # The android platforms are used in the ecj and apksigner packages: -yes | $ANDROID_HOME/tools/bin/sdkmanager "platform-tools" "build-tools;${TERMUX_ANDROID_BUILD_TOOLS_VERSION}" "platforms;android-28" "platforms;android-24" "platforms;android-21" +yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME \ + "platform-tools" \ + "build-tools;${TERMUX_ANDROID_BUILD_TOOLS_VERSION}" \ + "platforms;android-28" \ + "platforms;android-24" \ + "platforms;android-21"