Skip to content

Commit

Permalink
[ci] Build Android export core (#5409)
Browse files Browse the repository at this point in the history
* [ci] Build & Test taichi-aot-demo & Taichi-UnityExample

* comply review requirements
  • Loading branch information
feisuzhu authored Aug 3, 2022
1 parent c4b4a3c commit 2a19a98
Show file tree
Hide file tree
Showing 9 changed files with 356 additions and 53 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ jobs:
-e DISPLAY -e PY -e GPU_TEST registry.taichigraphics.com/taichidev-ubuntu18.04:v0.3.0 \
/home/dev/unix_test.sh
docker cp .github/workflows/scripts/unix_test.sh taichi_test:/home/dev/unix_test.sh
docker cp .github/workflows/scripts/libcommon.sh taichi_test:/home/dev/libcommon.sh
docker cp ./requirements_test.txt taichi_test:/home/dev/requirements_test.txt
docker cp shared/dist/ taichi_test:/home/dev/
docker cp shared/build/ taichi_test:/home/dev/
Expand Down Expand Up @@ -179,6 +180,7 @@ jobs:
-e PY -e GPU_TEST registry.taichigraphics.com/taichidev-manylinux2014-cuda:v0.0.0 \
/home/dev/unix_test.sh
docker cp .github/workflows/scripts/unix_test.sh taichi_test:/home/dev/unix_test.sh
docker cp .github/workflows/scripts/libcommon.sh taichi_test:/home/dev/libcommon.sh
docker cp ./requirements_test.txt taichi_test:/home/dev/requirements_test.txt
docker cp shared/dist/ taichi_test:/home/dev/
docker cp shared/build/ taichi_test:/home/dev/
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/scripts/android-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -ex

export TI_SKIP_VERSION_CHECK=ON
export TI_CI=1

. $(dirname $0)/libcommon.sh

cd taichi

export TAICHI_CMAKE_ARGS="$TAICHI_CMAKE_ARGS -DTI_WITH_LLVM=OFF -DTI_WITH_C_API:BOOL=ON"

setup-sccache-local
setup_python
setup-android-ndk-env

python setup.py clean
python setup.py build_ext
cd build
aarch64-linux-android-strip libtaichi_export_core.so
aarch64-linux-android-strip libtaichi_c_api.so

chmod -R 777 "$SCCACHE_DIR"
83 changes: 83 additions & 0 deletions .github/workflows/scripts/aot-demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash
set -ex

export TI_SKIP_VERSION_CHECK=ON
export TI_CI=1

. $(dirname $0)/libcommon.sh


function build-and-smoke-test-android-aot-demo {
pushd taichi
GIT_COMMIT=$(git rev-parse HEAD | cut -c1-7)
popd

export TAICHI_REPO_DIR=$(pwd)/taichi

git clone https://github.com/taichi-dev/taichi-aot-demo
APP_ROOT=taichi-aot-demo/implicit_fem
ANDROID_APP_ROOT=$APP_ROOT/android
JNI_PATH=$ANDROID_APP_ROOT/app/src/main/jniLibs/arm64-v8a/

mkdir -p $JNI_PATH
cp taichi/build/libtaichi_export_core.so $JNI_PATH
cd $ANDROID_APP_ROOT
sed -i "s/TaichiAOT/AOT-$GIT_COMMIT/g" app/src/main/res/values/strings.xml
./gradlew build

run-android-app \
app/build/outputs/apk/debug/app-debug.apk \
com.taichigraphics.aot_demos.implicit_fem/android.app.NativeActivity
}

function prepare-unity-build-env {
cd taichi

# Dependencies
git clone --reference-if-able /var/lib/git-cache https://github.com/taichi-dev/Taichi-UnityExample

python misc/generate_unity_language_binding.py
cp c_api/unity/*.cs Taichi-UnityExample/Assets/Taichi/Generated
cp build/libtaichi_c_api.so Taichi-UnityExample/Assets/Plugins/Android

export TAICHI_REPO_DIR=$(pwd)

setup-android-ndk-env
git clone --reference-if-able /var/lib/git-cache https://github.com/taichi-dev/taichi-unity2
mkdir tu2-build
pushd tu2-build
cmake ../taichi-unity2 -DTAICHI_C_API_INSTALL_DIR=$TAICHI_REPO_DIR/_skbuild/linux-x86_64-3.9/cmake-install/c_api $ANDROID_CMAKE_ARGS
cmake --build .
popd
cp tu2-build/bin/libtaichi_unity.so Taichi-UnityExample/Assets/Plugins/Android
}

function build-unity-demo {
cd taichi
mkdir -p Taichi-UnityExample/Assets/Editor
cp -a /UnityBuilderAction Taichi-UnityExample/Assets/Editor/
unity-editor \
-logfile /dev/stdout \
-quit \
-customBuildName Android \
-projectPath Taichi-UnityExample \
-buildTarget Android \
-customBuildTarget Android \
-customBuildPath build/Android/Android.apk \
-executeMethod UnityBuilderAction.Builder.BuildProject \
-buildVersion 1.0.0-ci \
-androidVersionCode 1000000 \
-androidKeystoreName ~/.android/debug.keystore \
-androidKeystorePass android \
-androidKeyaliasName androiddebugkey \
-androidKeyaliasPass android
}

function smoke-test-unity-demo {
run-android-app \
taichi/Taichi-UnityExample/build/Android/Android.apk \
com.TaichiGraphics.TaichiUnityExample/com.unity3d.player.UnityPlayerActivity \
6
}

$1
144 changes: 144 additions & 0 deletions .github/workflows/scripts/libcommon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#!/bin/bash

check_in_docker() {
# This is a temporary solution to detect in a docker, but it should work
if [[ $(whoami) == "dev" ]]; then
echo "true"
else
echo "false"
fi
}

setup_sccache() {
export SCCACHE_DIR=$(pwd)/sccache_cache
export SCCACHE_CACHE_SIZE="128M"
export SCCACHE_LOG=error
export SCCACHE_ERROR_LOG=$(pwd)/sccache_error.log
mkdir -p "$SCCACHE_DIR"
echo "sccache dir: $SCCACHE_DIR"
ls -la "$SCCACHE_DIR"

if [[ $OSTYPE == "linux-"* ]]; then
wget https://github.com/mozilla/sccache/releases/download/v0.2.15/sccache-v0.2.15-x86_64-unknown-linux-musl.tar.gz
tar -xzf sccache-v0.2.15-x86_64-unknown-linux-musl.tar.gz
chmod +x sccache-v0.2.15-x86_64-unknown-linux-musl/sccache
export PATH=$(pwd)/sccache-v0.2.15-x86_64-unknown-linux-musl:$PATH
elif [[ $(uname -m) == "arm64" ]]; then
wget https://github.com/mozilla/sccache/releases/download/v0.2.15/sccache-v0.2.15-aarch64-apple-darwin.tar.gz
tar -xzf sccache-v0.2.15-aarch64-apple-darwin.tar.gz
chmod +x sccache-v0.2.15-aarch64-apple-darwin/sccache
export PATH=$(pwd)/sccache-v0.2.15-aarch64-apple-darwin:$PATH
else
wget https://github.com/mozilla/sccache/releases/download/v0.2.15/sccache-v0.2.15-x86_64-apple-darwin.tar.gz
tar -xzf sccache-v0.2.15-x86_64-apple-darwin.tar.gz
chmod +x sccache-v0.2.15-x86_64-apple-darwin/sccache
export PATH=$(pwd)/sccache-v0.2.15-x86_64-apple-darwin:$PATH
fi
}

setup_python() {
if [[ "$IN_DOCKER" == "true" ]]; then
source $HOME/miniconda/etc/profile.d/conda.sh
conda activate "$PY"
fi
python3 -m pip uninstall taichi taichi-nightly -y
python3 -m pip install -r requirements_dev.txt
}

function setup-sccache-local {
if [ -z $SCCACHE_ROOT ]; then
echo "Skipping sccache setup since SCCACHE_ROOT is not set"
return
fi

mkdir -p $SCCACHE_ROOT/{bin,cache}

export SCCACHE_DIR=$SCCACHE_ROOT/cache
export SCCACHE_CACHE_SIZE="10G"
export SCCACHE_LOG=error
export SCCACHE_ERROR_LOG=$SCCACHE_ROOT/sccache_error.log

echo "SCCACHE_ROOT: $SCCACHE_ROOT"

if [ ! -x $SCCACHE_ROOT/bin/sccache ]; then
if [[ $OSTYPE == "linux-"* ]]; then
wget https://github.com/mozilla/sccache/releases/download/v0.2.15/sccache-v0.2.15-x86_64-unknown-linux-musl.tar.gz
tar -xzf sccache-v0.2.15-x86_64-unknown-linux-musl.tar.gz
mv sccache-v0.2.15-x86_64-unknown-linux-musl/* $SCCACHE_ROOT/bin
elif [[ $(uname -m) == "arm64" ]]; then
wget https://github.com/mozilla/sccache/releases/download/v0.2.15/sccache-v0.2.15-aarch64-apple-darwin.tar.gz
tar -xzf sccache-v0.2.15-aarch64-apple-darwin.tar.gz
mv sccache-v0.2.15-aarch64-apple-darwin/* $SCCACHE_ROOT/bin
else
wget https://github.com/mozilla/sccache/releases/download/v0.2.15/sccache-v0.2.15-x86_64-apple-darwin.tar.gz
tar -xzf sccache-v0.2.15-x86_64-apple-darwin.tar.gz
mv sccache-v0.2.15-x86_64-apple-darwin/* $SCCACHE_ROOT/bin
fi
chmod +x $SCCACHE_ROOT/bin/sccache
fi

export PATH=$SCCACHE_ROOT/bin:$PATH
export TAICHI_CMAKE_ARGS="$TAICHI_CMAKE_ARGS -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache"
}

function setup-android-ndk-env {
export ANDROID_NDK_ROOT=/android-sdk/ndk-bundle
export ANDROID_CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=29 -DANDROID_ABI=arm64-v8a"
export TAICHI_CMAKE_ARGS="$TAICHI_CMAKE_ARGS $ANDROID_CMAKE_ARGS"
export PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH
}

function grab-android-bot {
if [ -z "$REDIS_HOST" ]; then
echo "REDIS_HOST is not set"
exit 1
fi

export BOT_LOCK_COOKIE=$(cat /proc/sys/kernel/random/uuid)
while true; do
for bot in $(redis-cli -h $REDIS_HOST --raw lrange android-bots 0 -1); do
export BOT_LOCK_KEY="android-bot-lock:$bot"
LOCKED=$(redis-cli -h $REDIS_HOST --raw setnx $BOT_LOCK_KEY $BOT_LOCK_COOKIE)
if [ $LOCKED -eq 1 ]; then
redis-cli -h $REDIS_HOST --raw expire android-bot-lock:$bot 300 > /dev/null
break
fi
done

if [ "$LOCKED" == "1" ]; then
export BOT=$bot
break
fi

echo "No bots available, retrying..."
sleep 1
done
}

function release-android-bot {
if [ $(redis-cli -h $REDIS_HOST --raw get $BOT_LOCK_KEY) == $BOT_LOCK_COOKIE ]; then
redis-cli -h $REDIS_HOST --raw del $BOT_LOCK_KEY
fi
}

function run-android-app {
APK=$1
ACTIVITY=$2
WAIT_TIME=${3:-5}
grab-android-bot
/android-sdk/platform-tools/adb connect $BOT
/android-sdk/platform-tools/adb devices
/android-sdk/platform-tools/adb install $APK
sleep 1
/android-sdk/platform-tools/adb logcat -c
/android-sdk/platform-tools/adb shell am start $ACTIVITY
sleep $WAIT_TIME
/android-sdk/platform-tools/adb logcat -d -v time 'CRASH:E *:F' | tee logcat.log
/android-sdk/platform-tools/adb shell am force-stop $(echo $ACTIVITY | sed 's#/.*$##g')
/android-sdk/platform-tools/adb disconnect
release-android-bot
if [ -s logcat.log ]; then
echo "!!!!!!!!!!!!!! Something is wrong !!!!!!!!!!!!!!"
exit 1
fi
}
45 changes: 1 addition & 44 deletions .github/workflows/scripts/unix_build.sh
Original file line number Diff line number Diff line change
@@ -1,54 +1,11 @@
#!/bin/bash
set -ex

check_in_docker() {
# This is a temporary solution to detect in a docker, but it should work
if [[ $(whoami) == "dev" ]]; then
echo "true"
else
echo "false"
fi
}
. $(dirname $0)/libcommon.sh

IN_DOCKER=$(check_in_docker)
[[ "$IN_DOCKER" == "true" ]] && cd taichi

setup_sccache() {
export SCCACHE_DIR=$(pwd)/sccache_cache
export SCCACHE_CACHE_SIZE="128M"
export SCCACHE_LOG=error
export SCCACHE_ERROR_LOG=$(pwd)/sccache_error.log
mkdir -p "$SCCACHE_DIR"
echo "sccache dir: $SCCACHE_DIR"
ls -la "$SCCACHE_DIR"

if [[ $OSTYPE == "linux-"* ]]; then
wget https://github.com/mozilla/sccache/releases/download/v0.2.15/sccache-v0.2.15-x86_64-unknown-linux-musl.tar.gz
tar -xzf sccache-v0.2.15-x86_64-unknown-linux-musl.tar.gz
chmod +x sccache-v0.2.15-x86_64-unknown-linux-musl/sccache
export PATH=$(pwd)/sccache-v0.2.15-x86_64-unknown-linux-musl:$PATH
elif [[ $(uname -m) == "arm64" ]]; then
wget https://github.com/mozilla/sccache/releases/download/v0.2.15/sccache-v0.2.15-aarch64-apple-darwin.tar.gz
tar -xzf sccache-v0.2.15-aarch64-apple-darwin.tar.gz
chmod +x sccache-v0.2.15-aarch64-apple-darwin/sccache
export PATH=$(pwd)/sccache-v0.2.15-aarch64-apple-darwin:$PATH
else
wget https://github.com/mozilla/sccache/releases/download/v0.2.15/sccache-v0.2.15-x86_64-apple-darwin.tar.gz
tar -xzf sccache-v0.2.15-x86_64-apple-darwin.tar.gz
chmod +x sccache-v0.2.15-x86_64-apple-darwin/sccache
export PATH=$(pwd)/sccache-v0.2.15-x86_64-apple-darwin:$PATH
fi
}

setup_python() {
if [[ "$IN_DOCKER" == "true" ]]; then
source $HOME/miniconda/etc/profile.d/conda.sh
conda activate "$PY"
fi
python3 -m pip uninstall taichi taichi-nightly -y
python3 -m pip install -r requirements_dev.txt
}

build_taichi_wheel() {
git fetch origin master
PROJECT_TAGS=""
Expand Down
11 changes: 2 additions & 9 deletions .github/workflows/scripts/unix_test.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
#!/bin/bash
set -ex

export PYTHONUNBUFFERED=1
. $(dirname $0)/libcommon.sh

check_in_docker() {
# This is a temporary solution to detect in a docker, but it should work
if [[ $(whoami) == "dev" ]]; then
echo "true"
else
echo "false"
fi
}
export PYTHONUNBUFFERED=1

export TI_SKIP_VERSION_CHECK=ON
export TI_CI=1
Expand Down
Loading

0 comments on commit 2a19a98

Please sign in to comment.