Skip to content

Commit

Permalink
add GitHubActions to build for android
Browse files Browse the repository at this point in the history
Signed-off-by: leleliu008 <leleliu008@gmail.com>
  • Loading branch information
leleliu008 committed Jan 4, 2022
1 parent 70704c7 commit 5d66b54
Showing 1 changed file with 115 additions and 0 deletions.
115 changes: 115 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: cross compile with android-ndk

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
cross-compile-for-android:
strategy:
fail-fast: false
matrix:
os: [ubuntu-18.04, ubuntu-20.04, macos-10.15, macos-11]
target-abi: [armeabi-v7a, arm64-v8a, x86, x86_64]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2

- run: brew install tree file

- run: tree --version
- run: file --version
- run: make --version

- run: echo "ANDROID_NDK_HOME=${ANDROID_NDK_LATEST_HOME}" >> "$GITHUB_ENV"

- run: |
env | sed -n '/^ANDROID_/p'
- run: cat "$ANDROID_NDK_HOME/source.properties"

- name: install runtime dependencies
run: |
for item in tbb-2021.5.0-bin xxhash-0.8.1-bin openssl-1.1.1g-bin
do
curl -LO https://github.com/leleliu008/test/releases/download/20220103-1623/${item}.tar.xz
tar vxf ${item}.tar.xz
printf '%s\n' "$item" >> runtime-dependencies
done
- name: build for ${{ matrix.target-abi }}
run: |
COLOR_GREEN='\033[0;32m' # Green
COLOR_PURPLE='\033[0;35m' # Purple
COLOR_OFF='\033[0m' # Reset
run() {
printf '%b\n' "$COLOR_PURPLE==>$COLOR_OFF $COLOR_GREEN$*$COLOR_OFF"
eval "$*"
}
BUILD_MACHINE_OS_TYPE=$(uname | tr A-Z a-z)
BUILD_MACHINE_OS_ARCH=$(uname -m)
ANDROID_NDK_BASE=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$BUILD_MACHINE_OS_TYPE-$BUILD_MACHINE_OS_ARCH
ANDROID_NDK_BIND=$ANDROID_NDK_BASE/bin
SYSROOT=$ANDROID_NDK_BASE/sysroot
export PATH="$ANDROID_NDK_BIND:$PATH"
export CPPFLAGS="--sysroot $SYSROOT"
export CXXFLAGS="--sysroot $SYSROOT"
export CFLAGS="--sysroot $SYSROOT"
export LDFLAGS="--sysroot $SYSROOT"
for item in $(cat runtime-dependencies)
do
export CPPFLAGS="$CPPFLAGS -I$PWD/${item}/${{ matrix.target-abi }}/include"
export LDFLAGS="$LDFLAGS -L$PWD/${item}/${{ matrix.target-abi }}/lib"
done
case ${{ matrix.target-abi }} in
armeabi-v7a) export CC=armv7a-linux-androideabi21-clang ;;
arm64-v8a) export CC=aarch64-linux-android21-clang ;;
x86) export CC=i686-linux-android21-clang ;;
x86_64) export CC=x86_64-linux-android21-clang ;;
esac
export CXX=${CC}++
export AR=llvm-ar
export STRIP=llvm-strip
printf '%b\n' "$COLOR_PURPLE==>$COLOR_OFF ${COLOR_GREEN}show PATH$COLOR_OFF"
printf '%s\n' "$PATH" | tr ':' '\n'
printf '%s\n'
# avoid link against librt
printf 'INPUT(-lc)\n' > librt.a
export LDFLAGS="$LDFLAGS -L$PWD"
run make clean
run make install PREFIX=$PWD/install.d OS=Linux LTO=1 SYSTEM_TBB=1 SYSTEM_XXHASH=1
- run: tree install.d

- run: |
file install.d/lib/mold/mold-wrapper.so
case ${{ matrix.target-abi }} in
armeabi-v7a) file install.d/lib/mold/mold-wrapper.so | grep 'ELF 32-bit LSB shared object, ARM, EABI5' ;;
arm64-v8a) file install.d/lib/mold/mold-wrapper.so | grep 'ELF 64-bit LSB shared object, ARM aarch64,' ;;
x86) file install.d/lib/mold/mold-wrapper.so | grep 'ELF 32-bit LSB shared object, Intel 80386,' ;;
x86_64) file install.d/lib/mold/mold-wrapper.so | grep 'ELF 64-bit LSB shared object, x86-64,' ;;
esac
- run: |
file install.d/bin/mold
case ${{ matrix.target-abi }} in
armeabi-v7a) file install.d/bin/mold | grep 'ELF 32-bit LSB pie executable, ARM, EABI5' ;;
arm64-v8a) file install.d/bin/mold | grep 'ELF 64-bit LSB pie executable, ARM aarch64,' ;;
x86) file install.d/bin/mold | grep 'ELF 32-bit LSB pie executable, Intel 80386,' ;;
x86_64) file install.d/bin/mold | grep 'ELF 64-bit LSB pie executable, x86-64,' ;;
esac

0 comments on commit 5d66b54

Please sign in to comment.