-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* typo fix * adding target_triples array * adding architectures array * Anchor logic to script parent folder using BASH_SOURCE * [#103] renaming vars according to PR comments
- Loading branch information
Showing
1 changed file
with
57 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,75 @@ | ||
#!/bin/bash | ||
|
||
# to debug the script add " -x" to the shebang. Ie. "#!/bin/bash -x" | ||
|
||
# get script folder | ||
SCRIPT_FOLDER=$( cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P ) | ||
|
||
# get android main folder relative to SCRIPT_FOLDER | ||
PARENT_FOLDER="$(dirname "$SCRIPT_FOLDER")" | ||
PATH_TO_ANDROID_MAIN="$PARENT_FOLDER/core/core/src/main" | ||
echo "PATH_TO_ANDROID_MAIN is $PATH_TO_ANDROID_MAIN" | ||
|
||
# get project root | ||
PROJECT_ROOT="$(dirname "$PARENT_FOLDER")" | ||
echo "Project root folder: $PROJECT_ROOT" | ||
|
||
|
||
# Run from repo's root folder (relative to Gradle build file. TODO do this in Gradle) | ||
cd ../.. | ||
echo "Running make_rust.sh from $(pwd)" | ||
|
||
# Building ########################################################### | ||
|
||
# See https://github.com/Co-Epi/app-backend-rust/wiki/Building-library-for-Android | ||
|
||
# Order of target_triples has to match the order of arhitectures: | ||
# aarch64-linux-android --> arm64-v8a | ||
# armv7-linux-androideabi --> armeabi | ||
# x86_64-linux-android --> x86_64 | ||
# i686-linux-android --> x86 | ||
|
||
target_triples=(aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android) | ||
architectures=(arm64-v8a armeabi-v7a x86_64 x86) | ||
|
||
if [ ${#target_triples[@]} != ${#architectures[@]} ]; then | ||
echo "Number of target_triples has to match number of architectures!" | ||
exit 17 | ||
fi | ||
|
||
platform="--platform 29" | ||
release_flag="" | ||
build_type_folder=debug | ||
|
||
if [[ $* == *--release* ]]; then | ||
# release builds | ||
cargo ndk --platform 29 --target x86_64-linux-android build --release | ||
cargo ndk --platform 29 --target aarch64-linux-android build --release | ||
cargo ndk --platform 29 --target armv7-linux-androideabi build --release | ||
cargo ndk --platform 29 --target i686-linux-android build --release | ||
else | ||
# debug builds | ||
cargo ndk --platform 29 --target x86_64-linux-android build | ||
cargo ndk --platform 29 --target aarch64-linux-android build | ||
cargo ndk --platform 29 --target armv7-linux-androideabi build | ||
cargo ndk --platform 29 --target i686-linux-android build | ||
release_flag="--release" | ||
build_type_folder=release | ||
fi | ||
|
||
for target_triple in ${target_triples[@]}; do | ||
cargo ndk $platform --target $target_triple build $release_flag | ||
done | ||
|
||
# Linking ########################################################### | ||
|
||
echo "Copying .so files to Android project" | ||
|
||
PATH_TO_ANDROID_LIBRARY="./android/core" | ||
PATH_TO_ANDROID_MAIN=$PATH_TO_ANDROID_LIBRARY/core/src/main | ||
|
||
rm -fr $PATH_TO_ANDROID_MAIN/jniLibs | ||
mkdir $PATH_TO_ANDROID_MAIN/jniLibs | ||
mkdir $PATH_TO_ANDROID_MAIN/jniLibs/arm64-v8a | ||
mkdir $PATH_TO_ANDROID_MAIN/jniLibs/armeabi-v7a | ||
mkdir $PATH_TO_ANDROID_MAIN/jniLibs/x86_64 | ||
mkdir $PATH_TO_ANDROID_MAIN/jniLibs/x86 | ||
|
||
if [[ $* == *--release* ]]; then | ||
# release | ||
cp $(pwd)/target/aarch64-linux-android/release/libcoepi_core.so $PATH_TO_ANDROID_MAIN/jniLibs/arm64-v8a/libcoepi_core.so | ||
cp $(pwd)/target/x86_64-linux-android/release/libcoepi_core.so $PATH_TO_ANDROID_MAIN/jniLibs/x86_64/libcoepi_core.so | ||
cp $(pwd)/target/armv7-linux-androideabi/release/libcoepi_core.so $PATH_TO_ANDROID_MAIN/jniLibs/armeabi-v7a/libcoepi_core.so | ||
cp $(pwd)/target/i686-linux-android/release/libcoepi_core.so $PATH_TO_ANDROID_MAIN/jniLibs/x86/libcoepi_core.so | ||
else | ||
# debug | ||
cp $(pwd)/target/aarch64-linux-android/debug/libcoepi_core.so $PATH_TO_ANDROID_MAIN/jniLibs/arm64-v8a/libcoepi_core.so | ||
cp $(pwd)/target/x86_64-linux-android/debug/libcoepi_core.so $PATH_TO_ANDROID_MAIN/jniLibs/x86_64/libcoepi_core.so | ||
cp $(pwd)/target/armv7-linux-androideabi/debug/libcoepi_core.so $PATH_TO_ANDROID_MAIN/jniLibs/armeabi-v7a/libcoepi_core.so | ||
cp $(pwd)/target/i686-linux-android/debug/libcoepi_core.so $PATH_TO_ANDROID_MAIN/jniLibs/x86/libcoepi_core.so | ||
fi | ||
for arch in ${architectures[@]}; do | ||
mkdir $PATH_TO_ANDROID_MAIN/jniLibs/$arch | ||
done | ||
|
||
lib_file=libcoepi_core.so | ||
|
||
echo "Copying .so files to $PATH_TO_ANDROID_MAIN/jniLibs..." | ||
|
||
cnt=${#target_triples[@]} | ||
limit=$(($cnt - 1)) | ||
|
||
i=0 | ||
while [ "$i" -le "$limit" ]; do | ||
cp $PROJECT_ROOT/target/${target_triples[i]}/$build_type_folder/$lib_file $PATH_TO_ANDROID_MAIN/jniLibs/${architectures[i]}/$lib_file | ||
i=$(($i + 1)) | ||
done | ||
|
||
echo "Done" | ||
|