From 2981fb416839b143cb413de194583125ecebc77b Mon Sep 17 00:00:00 2001 From: forfun414 Date: Sun, 26 Jan 2020 20:29:10 +0800 Subject: [PATCH 1/7] build: support android build on ndk version equal or above 23(Android 6.0) change scripts and sources for android build, don't need standalone toolchain a\ fter ndk 19, and use clang as default android target compiler. --- android-configure | 77 +++++++++++++------------ common.gypi | 4 ++ deps/cares/config/android/ares_config.h | 2 +- deps/openssl/openssl-cl_no_asm.gypi | 4 ++ deps/openssl/openssl_no_asm.gypi | 4 ++ deps/uv/uv.gyp | 1 + tools/gyp/pylib/gyp/generator/make.py | 2 +- tools/v8_gypfiles/v8.gyp | 44 ++++++-------- 8 files changed, 73 insertions(+), 65 deletions(-) diff --git a/android-configure b/android-configure index 59f0a40c1ac214..384dfb91f6c6c2 100755 --- a/android-configure +++ b/android-configure @@ -8,29 +8,38 @@ # modules with npm. Also, don't forget to set the arch in npm config using # 'npm config set arch=' +if [ $# -ne 3 ]; then + echo "$0 should have 3 parameters: ndk_path, target_arch and sdk_version" + exit 1 +fi + +NDK_PATH=$1 +ARCH="$2" +ANDROID_SDK_VERSION=$3 -if [ -z "$2" ]; then - ARCH=arm -else - ARCH="$2" +if [ $ANDROID_SDK_VERSION -lt 23 ]; then + echo "$ANDROID_SDK_VERSION should equal or later than 23(Android 6.0)" fi CC_VER="4.9" + case $ARCH in arm) - DEST_CPU="$ARCH" - SUFFIX="$ARCH-linux-androideabi" - TOOLCHAIN_NAME="$SUFFIX" + DEST_CPU="arm" + TOOLCHAIN_NAME="armv7-linux-androideabi" ;; x86) DEST_CPU="ia32" - SUFFIX="i686-linux-android" - TOOLCHAIN_NAME="$ARCH" + TOOLCHAIN_NAME="i686-linux-android" ;; x86_64) - DEST_CPU="ia32" - SUFFIX="$ARCH-linux-android" - TOOLCHAIN_NAME="$ARCH" + DEST_CPU="x64" + TOOLCHAIN_NAME="x86_64-linux-android" + ARCH="x64" + ;; + arm64|aarch64) + DEST_CPU="arm64" + TOOLCHAIN_NAME="aarch64-linux-android" ;; *) echo "Unsupported architecture provided: $ARCH" @@ -38,36 +47,31 @@ case $ARCH in ;; esac -NDK_PATH=$1 -function make_toolchain { - $NDK_PATH/build/tools/make-standalone-toolchain.sh \ - --toolchain=$TOOLCHAIN_NAME-$CC_VER \ - --arch=$ARCH \ - --install-dir=$TOOLCHAIN \ - --platform=android-21 -} +HOST_OS="linux" +HOST_ARCH="x86_64" +export CC_host=$(which gcc) +export CXX_host=$(which g++) -export TOOLCHAIN=$PWD/android-toolchain -if [ -d "$TOOLCHAIN" ]; then - read -r -p "NDK toolchain already exists. Replace it? [y/N]" response - case "$response" in - [Yy]) - rm -rf "$TOOLCHAIN" - make_toolchain - esac -else - make_toolchain +host_gcc_version=$($CC_host --version | grep gcc | awk '{print $NF}') +major=$(echo $host_gcc_version | awk -F . '{print $1}') +minor=$(echo $host_gcc_version | awk -F . '{print $2}') +if [ -z $major ] || [ -z $minor ] || [ $major -lt 6 ] || [ $minor -lt 3 ]; then + echo "host gcc $host_gcc_version is too old, need gcc 6.3.0" + exit 1 fi + +SUFFIX="$TOOLCHAIN_NAME$ANDROID_SDK_VERSION" +TOOLCHAIN=$NDK_PATH/toolchains/llvm/prebuilt/$HOST_OS-$HOST_ARCH + export PATH=$TOOLCHAIN/bin:$PATH -export AR=$TOOLCHAIN/bin/$SUFFIX-ar -export CC=$TOOLCHAIN/bin/$SUFFIX-gcc -export CXX=$TOOLCHAIN/bin/$SUFFIX-g++ -export LINK=$TOOLCHAIN/bin/$SUFFIX-g++ +export CC=$TOOLCHAIN/bin/$SUFFIX-clang +export CXX=$TOOLCHAIN/bin/$SUFFIX-clang++ + GYP_DEFINES="target_arch=$ARCH" GYP_DEFINES+=" v8_target_arch=$ARCH" GYP_DEFINES+=" android_target_arch=$ARCH" -GYP_DEFINES+=" host_os=linux OS=android" +GYP_DEFINES+=" host_os=$HOST_OS OS=android" export GYP_DEFINES if [ -f "configure" ]; then @@ -75,5 +79,6 @@ if [ -f "configure" ]; then --dest-cpu=$DEST_CPU \ --dest-os=android \ --without-snapshot \ - --openssl-no-asm + --openssl-no-asm \ + --cross-compiling fi diff --git a/common.gypi b/common.gypi index 7d150b4f46423b..d4e8a0ccfb0be1 100644 --- a/common.gypi +++ b/common.gypi @@ -411,6 +411,10 @@ 'defines': [ '_GLIBCXX_USE_C99_MATH' ], 'libraries': [ '-llog' ], }], + ['_toolset=="host"', { + 'cflags': [ '-pthread' ], + 'ldflags': [ '-pthread' ], + }], ], }], ['OS=="mac"', { diff --git a/deps/cares/config/android/ares_config.h b/deps/cares/config/android/ares_config.h index 1a5265a5098d3c..601f97d883421f 100644 --- a/deps/cares/config/android/ares_config.h +++ b/deps/cares/config/android/ares_config.h @@ -128,7 +128,7 @@ #define HAVE_GETNAMEINFO 1 /* Define to 1 if you have the getservbyport_r function. */ -#define HAVE_GETSERVBYPORT_R 1 +//#define HAVE_GETSERVBYPORT_R 1 /* Define to 1 if you have the `gettimeofday' function. */ #define HAVE_GETTIMEOFDAY 1 diff --git a/deps/openssl/openssl-cl_no_asm.gypi b/deps/openssl/openssl-cl_no_asm.gypi index bb9e55de91e3f2..7f75e9bda74df6 100644 --- a/deps/openssl/openssl-cl_no_asm.gypi +++ b/deps/openssl/openssl-cl_no_asm.gypi @@ -16,6 +16,10 @@ 'includes': ['config/archs/linux-armv4/no-asm/openssl-cl.gypi'], }, 'target_arch=="arm64" and OS=="linux"', { 'includes': ['config/archs/linux-aarch64/no-asm/openssl-cl.gypi'], + }, 'target_arch=="arm" and OS=="android"', { + 'includes': ['config/archs/linux-armv4/no-asm/openssl-cl.gypi'], + }, 'target_arch=="arm64" and OS=="android"', { + 'includes': ['config/archs/linux-aarch64/no-asm/openssl-cl.gypi'], }, 'target_arch=="arm64" and OS=="win"', { 'includes': ['config/archs/VC-WIN64-ARM/no-asm/openssl-cl.gypi'], }, 'target_arch=="ia32" and OS=="freebsd"', { diff --git a/deps/openssl/openssl_no_asm.gypi b/deps/openssl/openssl_no_asm.gypi index 8eb61d970380c3..faeba9a764827c 100644 --- a/deps/openssl/openssl_no_asm.gypi +++ b/deps/openssl/openssl_no_asm.gypi @@ -17,6 +17,10 @@ 'includes': ['config/archs/linux-armv4/no-asm/openssl.gypi'], }, 'target_arch=="arm64" and OS=="linux"', { 'includes': ['config/archs/linux-aarch64/no-asm/openssl.gypi'], + }, 'target_arch=="arm" and OS=="android"', { + 'includes': ['config/archs/linux-armv4/no-asm/openssl.gypi'], + }, 'target_arch=="arm64" and OS=="android"', { + 'includes': ['config/archs/linux-aarch64/no-asm/openssl.gypi'], }, 'target_arch=="ia32" and OS=="freebsd"', { 'includes': ['config/archs/BSD-x86/no-asm/openssl.gypi'], }, 'target_arch=="ia32" and OS=="linux"', { diff --git a/deps/uv/uv.gyp b/deps/uv/uv.gyp index 116b7537195618..fa0a001527d790 100644 --- a/deps/uv/uv.gyp +++ b/deps/uv/uv.gyp @@ -261,6 +261,7 @@ 'src/unix/android-ifaddrs.c', 'src/unix/procfs-exepath.c', 'src/unix/random-getrandom.c', + 'src/unix/random-getentropy.c', 'src/unix/random-sysctl-linux.c', 'src/unix/sysinfo-loadavg.c', ], diff --git a/tools/gyp/pylib/gyp/generator/make.py b/tools/gyp/pylib/gyp/generator/make.py index 91a119c5a57694..eb39e0d2f9ed0e 100644 --- a/tools/gyp/pylib/gyp/generator/make.py +++ b/tools/gyp/pylib/gyp/generator/make.py @@ -201,7 +201,7 @@ def CalculateGeneratorInputInfo(params): quiet_cmd_link = LINK($(TOOLSET)) $@ quiet_cmd_link_host = LINK($(TOOLSET)) $@ cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS) -cmd_link_host = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS) +cmd_link_host = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS) # Other shared-object link notes: # - Set SONAME to the library filename so our binaries don't reference diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp index 2e5477b0eb4e49..d247a6718a2b85 100644 --- a/tools/v8_gypfiles/v8.gyp +++ b/tools/v8_gypfiles/v8.gyp @@ -952,41 +952,31 @@ }], ['is_android', { 'sources': [ - '<(V8_ROOT)/src/base/debug/stack_trace_android.cc', '<(V8_ROOT)/src/base/platform/platform-posix.cc', '<(V8_ROOT)/src/base/platform/platform-posix.h', '<(V8_ROOT)/src/base/platform/platform-posix-time.cc', '<(V8_ROOT)/src/base/platform/platform-posix-time.h', ], - 'conditions': [ - ['_toolset=="host"', { - 'link_settings': { + 'link_settings': { + 'target_conditions': [ + ['_toolset=="host" and host_os=="linux"', { 'libraries': [ '-ldl', '-lrt' - ] - }, - 'conditions': [ - ['_toolset=="host"', { - 'conditions': [ - ['host_os == "mac"', { - 'sources': [ - '<(V8_ROOT)/src/base/debug/stack_trace_posix.cc' - '<(V8_ROOT)/src/base/platform/platform-macos.cc' - ] - }, { - 'sources': [ - '<(V8_ROOT)/src/base/debug/stack_trace_posix.cc' - '<(V8_ROOT)/src/base/platform/platform-linux.cc' - ] - }], - ], - }, { - 'sources': [ - '<(V8_ROOT)/src/base/debug/stack_trace_android.cc' - '<(V8_ROOT)/src/base/platform/platform-linux.cc' - ] - }], + ], + }], + ], + }, + 'target_conditions': [ + ['_toolset=="host"', { + 'sources': [ + '<(V8_ROOT)/src/base/debug/stack_trace_posix.cc', + '<(V8_ROOT)/src/base/platform/platform-linux.cc', + ], + }, { + 'sources: [ + '<(V8_ROOT)/src/base/debug/stack_trace_android.cc', + '<(V8_ROOT)/src/base/platform/platform-linux.cc', ], }], ], From 0a185c7927c9910a0308e3577925e0c7c19167e1 Mon Sep 17 00:00:00 2001 From: forfun414 Date: Mon, 27 Jan 2020 00:06:11 +0800 Subject: [PATCH 2/7] build: support android build on ndk version equal or above 23(Android 6.0) --- tools/v8_gypfiles/v8.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp index d247a6718a2b85..cc4ac3ddba6749 100644 --- a/tools/v8_gypfiles/v8.gyp +++ b/tools/v8_gypfiles/v8.gyp @@ -974,7 +974,7 @@ '<(V8_ROOT)/src/base/platform/platform-linux.cc', ], }, { - 'sources: [ + 'sources': [ '<(V8_ROOT)/src/base/debug/stack_trace_android.cc', '<(V8_ROOT)/src/base/platform/platform-linux.cc', ], From eebc6bc2695526640cc509cbf95b160f1b362e89 Mon Sep 17 00:00:00 2001 From: forfun414 Date: Mon, 27 Jan 2020 14:41:50 +0800 Subject: [PATCH 3/7] build: support android build on ndk version equal or above 23(Android 6.0) change comment style --- deps/cares/config/android/ares_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cares/config/android/ares_config.h b/deps/cares/config/android/ares_config.h index 601f97d883421f..50c8114396b0fd 100644 --- a/deps/cares/config/android/ares_config.h +++ b/deps/cares/config/android/ares_config.h @@ -128,7 +128,7 @@ #define HAVE_GETNAMEINFO 1 /* Define to 1 if you have the getservbyport_r function. */ -//#define HAVE_GETSERVBYPORT_R 1 +/* #undef HAVE_GETSERVBYPORT_R */ /* Define to 1 if you have the `gettimeofday' function. */ #define HAVE_GETTIMEOFDAY 1 From 93d6de1318ae36b2c227053b1c06e644e552d21f Mon Sep 17 00:00:00 2001 From: forfun414 Date: Wed, 29 Jan 2020 11:16:00 +0800 Subject: [PATCH 4/7] build: support android build on ndk version equal or above 23(Android 6.0) merge linux and android into one conditon --- deps/openssl/openssl-cl_no_asm.gypi | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/deps/openssl/openssl-cl_no_asm.gypi b/deps/openssl/openssl-cl_no_asm.gypi index 7f75e9bda74df6..89bae67554ed7b 100644 --- a/deps/openssl/openssl-cl_no_asm.gypi +++ b/deps/openssl/openssl-cl_no_asm.gypi @@ -12,13 +12,9 @@ 'includes': ['config/archs/linux-ppc64/no-asm/openssl-cl.gypi'], }, 'target_arch=="s390x" and OS=="linux"', { 'includes': ['config/archs/linux64-s390x/no-asm/openssl-cl.gypi'], - }, 'target_arch=="arm" and OS=="linux"', { + }, 'target_arch=="arm" and OS in "linux android"', { 'includes': ['config/archs/linux-armv4/no-asm/openssl-cl.gypi'], - }, 'target_arch=="arm64" and OS=="linux"', { - 'includes': ['config/archs/linux-aarch64/no-asm/openssl-cl.gypi'], - }, 'target_arch=="arm" and OS=="android"', { - 'includes': ['config/archs/linux-armv4/no-asm/openssl-cl.gypi'], - }, 'target_arch=="arm64" and OS=="android"', { + }, 'target_arch=="arm64" and OS in "linux android"', { 'includes': ['config/archs/linux-aarch64/no-asm/openssl-cl.gypi'], }, 'target_arch=="arm64" and OS=="win"', { 'includes': ['config/archs/VC-WIN64-ARM/no-asm/openssl-cl.gypi'], From 0dac2343302f7efff5b02135671db0be2f83297e Mon Sep 17 00:00:00 2001 From: forfun414 Date: Wed, 29 Jan 2020 12:48:37 +0800 Subject: [PATCH 5/7] build: support android build on ndk version equal or above 23(Android 6.0) merge linux and android into one conditon and support arch aarch64 compile --- android-configure | 1 + deps/openssl/openssl_no_asm.gypi | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/android-configure b/android-configure index 384dfb91f6c6c2..906d52d05958c4 100755 --- a/android-configure +++ b/android-configure @@ -40,6 +40,7 @@ case $ARCH in arm64|aarch64) DEST_CPU="arm64" TOOLCHAIN_NAME="aarch64-linux-android" + ARCH="arm64" ;; *) echo "Unsupported architecture provided: $ARCH" diff --git a/deps/openssl/openssl_no_asm.gypi b/deps/openssl/openssl_no_asm.gypi index faeba9a764827c..68bf544edec4d2 100644 --- a/deps/openssl/openssl_no_asm.gypi +++ b/deps/openssl/openssl_no_asm.gypi @@ -13,13 +13,9 @@ 'includes': ['config/archs/linux-ppc64/no-asm/openssl.gypi'], }, 'target_arch=="s390x" and OS=="linux"', { 'includes': ['config/archs/linux64-s390x/no-asm/openssl.gypi'], - }, 'target_arch=="arm" and OS=="linux"', { + }, 'target_arch=="arm" and OS in "linux android"', { 'includes': ['config/archs/linux-armv4/no-asm/openssl.gypi'], - }, 'target_arch=="arm64" and OS=="linux"', { - 'includes': ['config/archs/linux-aarch64/no-asm/openssl.gypi'], - }, 'target_arch=="arm" and OS=="android"', { - 'includes': ['config/archs/linux-armv4/no-asm/openssl.gypi'], - }, 'target_arch=="arm64" and OS=="android"', { + }, 'target_arch=="arm64" and OS in "linux android"', { 'includes': ['config/archs/linux-aarch64/no-asm/openssl.gypi'], }, 'target_arch=="ia32" and OS=="freebsd"', { 'includes': ['config/archs/BSD-x86/no-asm/openssl.gypi'], From fdd4cfc2540e276e4192f46095fccfee3f502daa Mon Sep 17 00:00:00 2001 From: forfun414 Date: Wed, 29 Jan 2020 14:12:33 +0800 Subject: [PATCH 6/7] build: support android build on ndk version equal or above 23(Android 6.0) fix gcc version checking failed conditons, like gcc 8.1 --- android-configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android-configure b/android-configure index 906d52d05958c4..a7cb2b9c8b4a78 100755 --- a/android-configure +++ b/android-configure @@ -56,7 +56,7 @@ export CXX_host=$(which g++) host_gcc_version=$($CC_host --version | grep gcc | awk '{print $NF}') major=$(echo $host_gcc_version | awk -F . '{print $1}') minor=$(echo $host_gcc_version | awk -F . '{print $2}') -if [ -z $major ] || [ -z $minor ] || [ $major -lt 6 ] || [ $minor -lt 3 ]; then +if [ -z $major ] || [ -z $minor ] || [ $major -lt 6 ] || [ $major -eq 6 -a $minor -lt 3 ]; then echo "host gcc $host_gcc_version is too old, need gcc 6.3.0" exit 1 fi From a4aedd439714321f69221d81a489d0d3d492a328 Mon Sep 17 00:00:00 2001 From: forfun414 Date: Tue, 10 Mar 2020 22:27:21 +0800 Subject: [PATCH 7/7] build: support android build on ndk version equal or above 23(Android 6.0) change syntax for android and linux case --- deps/openssl/openssl-cl_no_asm.gypi | 4 ++-- deps/openssl/openssl_no_asm.gypi | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/deps/openssl/openssl-cl_no_asm.gypi b/deps/openssl/openssl-cl_no_asm.gypi index 89bae67554ed7b..2e12816aa3ebfd 100644 --- a/deps/openssl/openssl-cl_no_asm.gypi +++ b/deps/openssl/openssl-cl_no_asm.gypi @@ -12,9 +12,9 @@ 'includes': ['config/archs/linux-ppc64/no-asm/openssl-cl.gypi'], }, 'target_arch=="s390x" and OS=="linux"', { 'includes': ['config/archs/linux64-s390x/no-asm/openssl-cl.gypi'], - }, 'target_arch=="arm" and OS in "linux android"', { + }, 'target_arch=="arm" and OS in ("linux", "android")', { 'includes': ['config/archs/linux-armv4/no-asm/openssl-cl.gypi'], - }, 'target_arch=="arm64" and OS in "linux android"', { + }, 'target_arch=="arm64" and OS in ("linux", "android")', { 'includes': ['config/archs/linux-aarch64/no-asm/openssl-cl.gypi'], }, 'target_arch=="arm64" and OS=="win"', { 'includes': ['config/archs/VC-WIN64-ARM/no-asm/openssl-cl.gypi'], diff --git a/deps/openssl/openssl_no_asm.gypi b/deps/openssl/openssl_no_asm.gypi index 68bf544edec4d2..858c7d895eaee8 100644 --- a/deps/openssl/openssl_no_asm.gypi +++ b/deps/openssl/openssl_no_asm.gypi @@ -13,9 +13,9 @@ 'includes': ['config/archs/linux-ppc64/no-asm/openssl.gypi'], }, 'target_arch=="s390x" and OS=="linux"', { 'includes': ['config/archs/linux64-s390x/no-asm/openssl.gypi'], - }, 'target_arch=="arm" and OS in "linux android"', { + }, 'target_arch=="arm" and OS in ("linux", "android")', { 'includes': ['config/archs/linux-armv4/no-asm/openssl.gypi'], - }, 'target_arch=="arm64" and OS in "linux android"', { + }, 'target_arch=="arm64" and OS in ("linux", "android")', { 'includes': ['config/archs/linux-aarch64/no-asm/openssl.gypi'], }, 'target_arch=="ia32" and OS=="freebsd"', { 'includes': ['config/archs/BSD-x86/no-asm/openssl.gypi'],