Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: support android build on ndk version equal or above 23(Android… #31521

Closed
wants to merge 7 commits into from
77 changes: 41 additions & 36 deletions android-configure
Original file line number Diff line number Diff line change
Expand Up @@ -8,72 +8,77 @@
# modules with npm. Also, don't forget to set the arch in npm config using
# 'npm config set arch=<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"
exit 1
;;
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
richardlau marked this conversation as resolved.
Show resolved Hide resolved
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
./configure \
--dest-cpu=$DEST_CPU \
--dest-os=android \
--without-snapshot \
--openssl-no-asm
--openssl-no-asm \
--cross-compiling
fi
4 changes: 4 additions & 0 deletions common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@
'defines': [ '_GLIBCXX_USE_C99_MATH' ],
'libraries': [ '-llog' ],
}],
['_toolset=="host"', {
'cflags': [ '-pthread' ],
'ldflags': [ '-pthread' ],
}],
],
}],
['OS=="mac"', {
Expand Down
2 changes: 1 addition & 1 deletion deps/cares/config/android/ares_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions deps/openssl/openssl-cl_no_asm.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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"', {
forfun414 marked this conversation as resolved.
Show resolved Hide resolved
'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"', {
Expand Down
4 changes: 4 additions & 0 deletions deps/openssl/openssl_no_asm.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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"', {
Expand Down
1 change: 1 addition & 0 deletions deps/uv/uv.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand Down
2 changes: 1 addition & 1 deletion tools/gyp/pylib/gyp/generator/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 17 additions & 27 deletions tools/v8_gypfiles/v8.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
}],
],
Expand Down