Skip to content

Commit 50317c3

Browse files
forfun414addaleax
authored andcommitted
build: support android build on ndk version equal or above 23
change scripts and sources for android build, don't need standalone toolchain after ndk 19, and use clang as default android target compiler. PR-URL: nodejs#31521 Reviewed-By: Christian Clauss <[email protected]>
1 parent b6da55f commit 50317c3

File tree

8 files changed

+70
-69
lines changed

8 files changed

+70
-69
lines changed

android-configure

+42-36
Original file line numberDiff line numberDiff line change
@@ -8,72 +8,78 @@
88
# modules with npm. Also, don't forget to set the arch in npm config using
99
# 'npm config set arch=<arch>'
1010

11+
if [ $# -ne 3 ]; then
12+
echo "$0 should have 3 parameters: ndk_path, target_arch and sdk_version"
13+
exit 1
14+
fi
15+
16+
NDK_PATH=$1
17+
ARCH="$2"
18+
ANDROID_SDK_VERSION=$3
1119

12-
if [ -z "$2" ]; then
13-
ARCH=arm
14-
else
15-
ARCH="$2"
20+
if [ $ANDROID_SDK_VERSION -lt 23 ]; then
21+
echo "$ANDROID_SDK_VERSION should equal or later than 23(Android 6.0)"
1622
fi
1723

1824
CC_VER="4.9"
25+
1926
case $ARCH in
2027
arm)
21-
DEST_CPU="$ARCH"
22-
SUFFIX="$ARCH-linux-androideabi"
23-
TOOLCHAIN_NAME="$SUFFIX"
28+
DEST_CPU="arm"
29+
TOOLCHAIN_NAME="armv7-linux-androideabi"
2430
;;
2531
x86)
2632
DEST_CPU="ia32"
27-
SUFFIX="i686-linux-android"
28-
TOOLCHAIN_NAME="$ARCH"
33+
TOOLCHAIN_NAME="i686-linux-android"
2934
;;
3035
x86_64)
31-
DEST_CPU="ia32"
32-
SUFFIX="$ARCH-linux-android"
33-
TOOLCHAIN_NAME="$ARCH"
36+
DEST_CPU="x64"
37+
TOOLCHAIN_NAME="x86_64-linux-android"
38+
ARCH="x64"
39+
;;
40+
arm64|aarch64)
41+
DEST_CPU="arm64"
42+
TOOLCHAIN_NAME="aarch64-linux-android"
43+
ARCH="arm64"
3444
;;
3545
*)
3646
echo "Unsupported architecture provided: $ARCH"
3747
exit 1
3848
;;
3949
esac
4050

41-
NDK_PATH=$1
42-
function make_toolchain {
43-
$NDK_PATH/build/tools/make-standalone-toolchain.sh \
44-
--toolchain=$TOOLCHAIN_NAME-$CC_VER \
45-
--arch=$ARCH \
46-
--install-dir=$TOOLCHAIN \
47-
--platform=android-21
48-
}
51+
HOST_OS="linux"
52+
HOST_ARCH="x86_64"
53+
export CC_host=$(which gcc)
54+
export CXX_host=$(which g++)
4955

50-
export TOOLCHAIN=$PWD/android-toolchain
51-
if [ -d "$TOOLCHAIN" ]; then
52-
read -r -p "NDK toolchain already exists. Replace it? [y/N]" response
53-
case "$response" in
54-
[Yy])
55-
rm -rf "$TOOLCHAIN"
56-
make_toolchain
57-
esac
58-
else
59-
make_toolchain
56+
host_gcc_version=$($CC_host --version | grep gcc | awk '{print $NF}')
57+
major=$(echo $host_gcc_version | awk -F . '{print $1}')
58+
minor=$(echo $host_gcc_version | awk -F . '{print $2}')
59+
if [ -z $major ] || [ -z $minor ] || [ $major -lt 6 ] || [ $major -eq 6 -a $minor -lt 3 ]; then
60+
echo "host gcc $host_gcc_version is too old, need gcc 6.3.0"
61+
exit 1
6062
fi
63+
64+
SUFFIX="$TOOLCHAIN_NAME$ANDROID_SDK_VERSION"
65+
TOOLCHAIN=$NDK_PATH/toolchains/llvm/prebuilt/$HOST_OS-$HOST_ARCH
66+
6167
export PATH=$TOOLCHAIN/bin:$PATH
62-
export AR=$TOOLCHAIN/bin/$SUFFIX-ar
63-
export CC=$TOOLCHAIN/bin/$SUFFIX-gcc
64-
export CXX=$TOOLCHAIN/bin/$SUFFIX-g++
65-
export LINK=$TOOLCHAIN/bin/$SUFFIX-g++
68+
export CC=$TOOLCHAIN/bin/$SUFFIX-clang
69+
export CXX=$TOOLCHAIN/bin/$SUFFIX-clang++
70+
6671

6772
GYP_DEFINES="target_arch=$ARCH"
6873
GYP_DEFINES+=" v8_target_arch=$ARCH"
6974
GYP_DEFINES+=" android_target_arch=$ARCH"
70-
GYP_DEFINES+=" host_os=linux OS=android"
75+
GYP_DEFINES+=" host_os=$HOST_OS OS=android"
7176
export GYP_DEFINES
7277

7378
if [ -f "configure" ]; then
7479
./configure \
7580
--dest-cpu=$DEST_CPU \
7681
--dest-os=android \
7782
--without-snapshot \
78-
--openssl-no-asm
83+
--openssl-no-asm \
84+
--cross-compiling
7985
fi

common.gypi

+4
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,10 @@
417417
'defines': [ '_GLIBCXX_USE_C99_MATH' ],
418418
'libraries': [ '-llog' ],
419419
}],
420+
['_toolset=="host"', {
421+
'cflags': [ '-pthread' ],
422+
'ldflags': [ '-pthread' ],
423+
}],
420424
],
421425
}],
422426
['OS=="mac"', {

deps/cares/config/android/ares_config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
#define HAVE_GETNAMEINFO 1
129129

130130
/* Define to 1 if you have the getservbyport_r function. */
131-
#define HAVE_GETSERVBYPORT_R 1
131+
/* #undef HAVE_GETSERVBYPORT_R */
132132

133133
/* Define to 1 if you have the `gettimeofday' function. */
134134
#define HAVE_GETTIMEOFDAY 1

deps/openssl/openssl-cl_no_asm.gypi

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
'includes': ['config/archs/linux-ppc64/no-asm/openssl-cl.gypi'],
1313
}, 'target_arch=="s390x" and OS=="linux"', {
1414
'includes': ['config/archs/linux64-s390x/no-asm/openssl-cl.gypi'],
15-
}, 'target_arch=="arm" and OS=="linux"', {
15+
}, 'target_arch=="arm" and OS in ("linux", "android")', {
1616
'includes': ['config/archs/linux-armv4/no-asm/openssl-cl.gypi'],
17-
}, 'target_arch=="arm64" and OS=="linux"', {
17+
}, 'target_arch=="arm64" and OS in ("linux", "android")', {
1818
'includes': ['config/archs/linux-aarch64/no-asm/openssl-cl.gypi'],
1919
}, 'target_arch=="arm64" and OS=="win"', {
2020
'includes': ['config/archs/VC-WIN64-ARM/no-asm/openssl-cl.gypi'],

deps/openssl/openssl_no_asm.gypi

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
'includes': ['config/archs/linux-ppc64/no-asm/openssl.gypi'],
1414
}, 'target_arch=="s390x" and OS=="linux"', {
1515
'includes': ['config/archs/linux64-s390x/no-asm/openssl.gypi'],
16-
}, 'target_arch=="arm" and OS=="linux"', {
16+
}, 'target_arch=="arm" and OS in ("linux", "android")', {
1717
'includes': ['config/archs/linux-armv4/no-asm/openssl.gypi'],
18-
}, 'target_arch=="arm64" and OS=="linux"', {
18+
}, 'target_arch=="arm64" and OS in ("linux", "android")', {
1919
'includes': ['config/archs/linux-aarch64/no-asm/openssl.gypi'],
2020
}, 'target_arch=="ia32" and OS=="freebsd"', {
2121
'includes': ['config/archs/BSD-x86/no-asm/openssl.gypi'],

deps/uv/uv.gyp

+1
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@
261261
'src/unix/android-ifaddrs.c',
262262
'src/unix/procfs-exepath.c',
263263
'src/unix/random-getrandom.c',
264+
'src/unix/random-getentropy.c',
264265
'src/unix/random-sysctl-linux.c',
265266
'src/unix/sysinfo-loadavg.c',
266267
],

tools/gyp/pylib/gyp/generator/make.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def CalculateGeneratorInputInfo(params):
201201
quiet_cmd_link = LINK($(TOOLSET)) $@
202202
quiet_cmd_link_host = LINK($(TOOLSET)) $@
203203
cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS)
204-
cmd_link_host = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS)
204+
cmd_link_host = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS)
205205
206206
# Other shared-object link notes:
207207
# - Set SONAME to the library filename so our binaries don't reference

tools/v8_gypfiles/v8.gyp

+17-27
Original file line numberDiff line numberDiff line change
@@ -952,41 +952,31 @@
952952
}],
953953
['is_android', {
954954
'sources': [
955-
'<(V8_ROOT)/src/base/debug/stack_trace_android.cc',
956955
'<(V8_ROOT)/src/base/platform/platform-posix.cc',
957956
'<(V8_ROOT)/src/base/platform/platform-posix.h',
958957
'<(V8_ROOT)/src/base/platform/platform-posix-time.cc',
959958
'<(V8_ROOT)/src/base/platform/platform-posix-time.h',
960959
],
961-
'conditions': [
962-
['_toolset=="host"', {
963-
'link_settings': {
960+
'link_settings': {
961+
'target_conditions': [
962+
['_toolset=="host" and host_os=="linux"', {
964963
'libraries': [
965964
'-ldl',
966965
'-lrt'
967-
]
968-
},
969-
'conditions': [
970-
['_toolset=="host"', {
971-
'conditions': [
972-
['host_os == "mac"', {
973-
'sources': [
974-
'<(V8_ROOT)/src/base/debug/stack_trace_posix.cc'
975-
'<(V8_ROOT)/src/base/platform/platform-macos.cc'
976-
]
977-
}, {
978-
'sources': [
979-
'<(V8_ROOT)/src/base/debug/stack_trace_posix.cc'
980-
'<(V8_ROOT)/src/base/platform/platform-linux.cc'
981-
]
982-
}],
983-
],
984-
}, {
985-
'sources': [
986-
'<(V8_ROOT)/src/base/debug/stack_trace_android.cc'
987-
'<(V8_ROOT)/src/base/platform/platform-linux.cc'
988-
]
989-
}],
966+
],
967+
}],
968+
],
969+
},
970+
'target_conditions': [
971+
['_toolset=="host"', {
972+
'sources': [
973+
'<(V8_ROOT)/src/base/debug/stack_trace_posix.cc',
974+
'<(V8_ROOT)/src/base/platform/platform-linux.cc',
975+
],
976+
}, {
977+
'sources': [
978+
'<(V8_ROOT)/src/base/debug/stack_trace_android.cc',
979+
'<(V8_ROOT)/src/base/platform/platform-linux.cc',
990980
],
991981
}],
992982
],

0 commit comments

Comments
 (0)