diff options
author | Jack Lloyd <[email protected]> | 2019-07-04 05:44:18 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2019-07-04 06:30:05 -0400 |
commit | 9541d8f4c053f55edfc6b97fbf6c8e14d434364c (patch) | |
tree | d1522411d4fe873762a86180724c765f9685cfd4 /src/scripts | |
parent | 61787c0dee73cad59912d15e151bc720095e7ee1 (diff) |
Build Android via NDK
Diffstat (limited to 'src/scripts')
-rwxr-xr-x | src/scripts/ci/setup_travis.sh | 4 | ||||
-rw-r--r-- | src/scripts/ci/travis.yml | 16 | ||||
-rwxr-xr-x | src/scripts/ci_build.py | 35 |
3 files changed, 55 insertions, 0 deletions
diff --git a/src/scripts/ci/setup_travis.sh b/src/scripts/ci/setup_travis.sh index fd13417c5..0ef505480 100755 --- a/src/scripts/ci/setup_travis.sh +++ b/src/scripts/ci/setup_travis.sh @@ -47,6 +47,10 @@ if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get -qq update sudo apt-get install qemu-user g++-mips64-linux-gnuabi64 + elif [ "$BUILD_MODE" = "cross-android-arm32" -o "$BUILD_MODE" = "cross-android-arm64" ]; then + wget -nv https://dl.google.com/android/repository/"$ANDROID_NDK"-linux-x86_64.zip + unzip -qq "$ANDROID_NDK"-linux-x86_64.zip + elif [ "$BUILD_MODE" = "lint" ]; then sudo apt-get -qq update sudo apt-get install pylint diff --git a/src/scripts/ci/travis.yml b/src/scripts/ci/travis.yml index 83e642748..b14ef34a3 100644 --- a/src/scripts/ci/travis.yml +++ b/src/scripts/ci/travis.yml @@ -14,6 +14,7 @@ compiler: env: global: - CCACHE_MAXSIZE=800M + - ANDROID_NDK=android-ndk-r20 matrix: - BUILD_MODE="shared" @@ -27,6 +28,8 @@ env: - BUILD_MODE="cross-arm64" - BUILD_MODE="cross-mips64" - BUILD_MODE="cross-win64" + - BUILD_MODE="cross-android-arm32" + - BUILD_MODE="cross-android-arm64" - BUILD_MODE="gcc4.8" - BUILD_MODE="static" - BUILD_MODE="mini-shared" @@ -62,6 +65,7 @@ matrix: env: BUILD_MODE="docs" - compiler: clang env: BUILD_MODE="coverage" + - compiler: clang env: BUILD_MODE="fuzzers" - compiler: clang @@ -89,6 +93,18 @@ matrix: compiler: clang env: BUILD_MODE="cross-arm64" + # Android NDK is Linux only + - os: osx + env: BUILD_MODE="cross-android-arm32" + - os: osx + env: BUILD_MODE="cross-android-arm64" + - os: linux + compiler: gcc + env: BUILD_MODE="cross-android-arm32" + - os: linux + compiler: gcc + env: BUILD_MODE="cross-android-arm64" + install: - ./src/scripts/ci/setup_travis.sh diff --git a/src/scripts/ci_build.py b/src/scripts/ci_build.py index 91d9d39a3..5eadc6b88 100755 --- a/src/scripts/ci_build.py +++ b/src/scripts/ci_build.py @@ -43,6 +43,8 @@ def determine_flags(target, target_os, target_cpu, target_cc, cc_bin, ccache, ro target_os = 'ios' elif target == 'cross-win64': target_os = 'mingw' + elif target in ['cross-android-arm32', 'cross-android-arm64']: + target_os = 'android' make_prefix = [] test_prefix = [] @@ -141,6 +143,34 @@ def determine_flags(target, target_os, target_cpu, target_cc, cc_bin, ccache, ro flags += ['--cpu=arm64', '--cc-abi-flags=-arch arm64 -stdlib=libc++'] else: raise Exception("Unknown cross target '%s' for iOS" % (target)) + elif target_os == 'android': + + if os.getenv('ANDROID_NDK') is None: + raise Exception('Android CI build requires ANDROID_NDK env variable be set') + + if os.getenv('ANDROID_API_LEVEL') is None: + # If not set arbitrarily choose API 16 (Android 4.1) for ARMv7 and 28 (Android 9) for AArch64 + api_lvl = 16 if target == 'cross-android-arm32' else 28 + else: + api_lvl = int(os.getenv('ANDROID_API_LEVEL')) + + ndk = os.getenv('ANDROID_NDK') + + toolchain_dir = os.path.join(ndk, 'toolchains/llvm/prebuilt/linux-x86_64/bin') + test_cmd = None + + if target == 'cross-android-arm32': + cc_bin = os.path.join(toolchain_dir, 'armv7a-linux-androideabi%d-clang++' % (api_lvl)) + flags += ['--cpu=armv7', + '--ar-command=%s' % (os.path.join(toolchain_dir, 'arm-linux-androideabi-ar'))] + + if api_lvl < 18: + flags += ['--without-os-features=getauxval'] + elif target == 'cross-android-arm64': + cc_bin = os.path.join(toolchain_dir, 'aarch64-linux-android%d-clang++' % (api_lvl)) + flags += ['--cpu=arm64', + '--ar-command=%s' % (os.path.join(toolchain_dir, 'aarch64-linux-android-ar'))] + elif target == 'cross-i386': flags += ['--cpu=x86_32'] @@ -255,6 +285,11 @@ def run_cmd(cmd, root_dir): if len(cmd) > 1 and cmd[0].startswith('indir:'): cwd = cmd[0][6:] cmd = cmd[1:] + while len(cmd) > 1 and cmd[0].startswith('env:') and cmd[0].find('=') > 0: + env_key, env_val = cmd[0][4:].split('=') + sub_env[env_key] = env_val + cmd = cmd[1:] + proc = subprocess.Popen(cmd, cwd=cwd, close_fds=True, env=sub_env, stdout=redirect_stdout) proc.communicate() |