Skip to content

Commit 5eef8a0

Browse files
committed
build: separate Android host and target compilers
Signed-off-by: luoqianlin <qianlinluo@foxmail.com>
1 parent f860538 commit 5eef8a0

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

android_configure.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import platform
22
import sys
33
import os
4+
import shutil
5+
import subprocess
46

57
# TODO: In next version, it will be a JSON file listing all the patches, and then it will iterate through to apply them.
68
def patch_android():
@@ -18,8 +20,8 @@ def patch_android():
1820
patch_android()
1921
sys.exit(0)
2022

21-
if len(sys.argv) != 4:
22-
print("Usage: ./android-configure [patch] <path to the Android NDK> <Android SDK version> <target architecture>")
23+
if len(sys.argv) < 4:
24+
print("Usage: ./android-configure [patch] <path to the Android NDK> <Android SDK version> <target architecture> [configure options...]")
2325
sys.exit(1)
2426

2527
if not os.path.exists(sys.argv[1]) or not os.listdir(sys.argv[1]):
@@ -33,6 +35,7 @@ def patch_android():
3335
android_ndk_path = sys.argv[1]
3436
android_sdk_version = sys.argv[2]
3537
arch = sys.argv[3]
38+
configure_options = sys.argv[4:]
3639

3740
if arch == "arm":
3841
DEST_CPU = "arm"
@@ -63,8 +66,26 @@ def patch_android():
6366
toolchain_path = android_ndk_path + "/toolchains/llvm/prebuilt/linux-x86_64"
6467

6568
os.environ['PATH'] += os.pathsep + toolchain_path + "/bin"
66-
os.environ['CC'] = toolchain_path + "/bin/" + TOOLCHAIN_PREFIX + android_sdk_version + "-" + "clang"
67-
os.environ['CXX'] = toolchain_path + "/bin/" + TOOLCHAIN_PREFIX + android_sdk_version + "-" + "clang++"
69+
target_cc = os.path.join(toolchain_path, "bin",
70+
TOOLCHAIN_PREFIX + android_sdk_version + "-clang")
71+
target_cxx = os.path.join(toolchain_path, "bin",
72+
TOOLCHAIN_PREFIX + android_sdk_version + "-clang++")
73+
74+
# configure.py uses CC/CXX for compiler detection, while GYP uses the
75+
# toolset-specific variables when generating host and target rules.
76+
os.environ['CC_target'] = (os.environ.get('CC_target') or
77+
os.environ.get('CC') or target_cc)
78+
os.environ['CXX_target'] = (os.environ.get('CXX_target') or
79+
os.environ.get('CXX') or target_cxx)
80+
os.environ['CC'] = os.environ['CC_target']
81+
os.environ['CXX'] = os.environ['CXX_target']
82+
83+
host_cc_name = 'cc' if platform.system() == "Darwin" else 'gcc'
84+
host_cxx_name = 'c++' if platform.system() == "Darwin" else 'g++'
85+
os.environ['CC_host'] = (os.environ.get('CC_host') or
86+
shutil.which(host_cc_name) or host_cc_name)
87+
os.environ['CXX_host'] = (os.environ.get('CXX_host') or
88+
shutil.which(host_cxx_name) or host_cxx_name)
6889

6990
GYP_DEFINES = "target_arch=" + arch
7091
GYP_DEFINES += " v8_target_arch=" + arch
@@ -74,4 +95,11 @@ def patch_android():
7495
os.environ['GYP_DEFINES'] = GYP_DEFINES
7596

7697
if os.path.exists("./configure"):
77-
os.system("./configure --dest-cpu=" + DEST_CPU + " --dest-os=android --openssl-no-asm --cross-compiling")
98+
command = [
99+
"./configure",
100+
"--dest-cpu=" + DEST_CPU,
101+
"--dest-os=android",
102+
"--openssl-no-asm",
103+
"--cross-compiling",
104+
] + configure_options
105+
subprocess.run(command, check=True)

0 commit comments

Comments
 (0)