-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ci] Build Android export core (#5409)
* [ci] Build & Test taichi-aot-demo & Taichi-UnityExample * comply review requirements
- Loading branch information
Showing
9 changed files
with
356 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.