Unverified Commit ea5786c8 authored by Hanwen Cheng's avatar Hanwen Cheng Committed by GitHub
Browse files

build: use prebuild ndk toolchains instead of building standalone one (#637)

* build: use latest ndk

* use script to generate android debug keystore

* remove logs

* use api from variable script
parent 9f1fb537
Pipeline #95339 failed with stages
in 57 seconds
[target.aarch64-linux-android]
ar = "$PWD/NDK/arm64/bin/aarch64-linux-android-ar"
linker = "$PWD/NDK/arm64/bin/aarch64-linux-android-gcc"
[target.armv7-linux-androideabi]
ar = "$PWD/NDK/arm/bin/arm-linux-androideabi-ar"
linker = "$PWD/NDK/arm/bin/arm-linux-androideabi-gcc"
[target.i686-linux-android]
ar = "$PWD/NDK/x86/bin/i686-linux-android-ar"
linker = "$PWD/NDK/x86/bin/i686-linux-android-gcc"
#! /bin/bash
# based on https://github.com/kennytm/rust-ios-android
set -euo pipefail
if [ -d NDK ]; then
printf '\e[33;1mStandalone NDK already exists... Delete the NDK folder to make a new one.\e[0m\n\n'
printf '$ rm -rf NDK\n'
exit 0
fi
MAKER="$NDK_HOME/build/tools/make_standalone_toolchain.py"
if [ -x "$MAKER" ]; then
MAKER="$NDK_HOME/build/tools/make_standalone_toolchain.py"
fi
if [ -x "$MAKER" ]; then
echo 'Creating standalone NDK...'
else
printf '\e[91;1mPlease install `android-ndk`!\e[0m\n\n'
printf '$ brew cask install android-ndk\n'
exit 1
fi
mkdir NDK
cd NDK
for ARCH in arm64 arm x86; do
echo "($ARCH)..."
"$MAKER" --arch $ARCH --install-dir $ARCH
done
echo 'Updating ./rust/.cargo/config.toml...'
cd ..
mkdir -p rust/.cargo
sed 's|$PWD|'"${PWD}"'|g' cargo-config.toml.template > ./rust/.cargo/config
NDK_STANDALONE = $(shell pwd)/../../NDK
ARCHS_IOS = x86_64-apple-ios armv7-apple-ios armv7s-apple-ios aarch64-apple-ios
ARCHS_ANDROID = aarch64-linux-android armv7-linux-androideabi i686-linux-android
LIB=libsigner.a
API_LEVEL=$(shell grep API_LEVEL scripts/variables.sh |tr -c -d '[:digit:]')
OS_ARCH=$(shell uname | tr '[:upper:]' '[:lower:]')
ANDROID_PREBUILD_BIN="${NDK_HOME}/toolchains/llvm/prebuilt/${OS_ARCH}-x86_64/bin"
all: ios android
......@@ -15,21 +17,21 @@ $(ARCHS_IOS): %:
cargo build --target $@ --release --no-default-features
aarch64-linux-android:
PATH=$(PATH):$(NDK_STANDALONE)/arm64/bin \
CC=$@-gcc \
CXX=$@-g++ \
CC_aarch64_linux_android="${ANDROID_PREBUILD_BIN}/aarch64-linux-android${API_LEVEL}-clang" \
CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_PREBUILD_BIN}/aarch64-linux-android${API_LEVEL}-clang" \
AR_aarch64_linux_android="${ANDROID_PREBUILD_BIN}/aarch64-linux-android-ar" \
cargo build --target $@ --release
armv7-linux-androideabi:
PATH=$(PATH):$(NDK_STANDALONE)/arm/bin \
CC=arm-linux-androideabi-gcc \
CXX=arm-linux-androideabi-g++ \
CC_armv7_linux_androideabi="${ANDROID_PREBUILD_BIN}/armv7a-linux-androideabi${API_LEVEL}-clang" \
CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="${ANDROID_PREBUILD_BIN}/armv7a-linux-androideabi${API_LEVEL}-clang" \
AR_armv7_linux_androideabi="${ANDROID_PREBUILD_BIN}/arm-linux-androideabi-ar" \
cargo build --target $@ --release
i686-linux-android:
PATH=$(PATH):$(NDK_STANDALONE)/x86/bin \
CC=i686-linux-android-gcc \
CXX=i686-linux-android-g++ \
CC_i686_linux_android="${ANDROID_PREBUILD_BIN}/i686-linux-android${API_LEVEL}-clang" \
CARGO_TARGET_I686_LINUX_ANDROID_LINKER="${ANDROID_PREBUILD_BIN}/i686-linux-android${API_LEVEL}-clang" \
AR_i686_linux_android="${ANDROID_PREBUILD_BIN}/i686-linux-android-ar" \
cargo build --target $@ --release --lib
$(LIB): $(ARCHS_IOS)
......
#!/bin/bash
source ./scripts/variables.sh
# Build iOS
cd ./rust/signer
cargo lipo --release
cp "./target/universal/release/lib${LIB_NAME}.a" "../../ios/lib${LIB_NAME}.a"
# Build android
if [ -z ${NDK_HOME+x} ];
then
printf 'Please install android-ndk\n\n'
printf 'from https://developer.android.com/ndk/downloads or with sdkmanager'
exit 1
else
printf "Building Andriod targets...";
fi
CC_aarch64_linux_android="${ANDROID_PREBUILD_BIN}/aarch64-linux-android${API_LEVEL}-clang" \
CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_PREBUILD_BIN}/aarch64-linux-android${API_LEVEL}-clang" \
cargo build --target aarch64-linux-android --release
CC_armv7_linux_androideabi="${ANDROID_PREBUILD_BIN}/armv7a-linux-androideabi${API_LEVEL}-clang" \
CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="${ANDROID_PREBUILD_BIN}/armv7a-linux-androideabi${API_LEVEL}-clang" \
cargo build --target armv7-linux-androideabi --release
CC_i686_linux_android="${ANDROID_PREBUILD_BIN}/i686-linux-android${API_LEVEL}-clang" \
CARGO_TARGET_I686_LINUX_ANDROID_LINKER="${ANDROID_PREBUILD_BIN}/i686-linux-android${API_LEVEL}-clang" \
cargo build --target i686-linux-android --release
CC_x86_64_linux_android="${ANDROID_PREBUILD_BIN}/x86_64-linux-android${API_LEVEL}-clang" \
CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="${ANDROID_PREBUILD_BIN}/x86_64-linux-android${API_LEVEL}-clang" \
cargo build --target x86_64-linux-android --release
for i in "${!ANDROID_ARCHS[@]}";
do
mkdir -p "../android/src/main/${ANDROID_FOLDER[$i]}"
cp "./target/${ANDROID_ARCHS[$i]}/release/lib${LIB_NAME}.so" "../android/src/main/jniLibs/${ANDROID_FOLDER[$i]}/lib${LIB_NAME}.so"
done
#!/bin/bash
source ./scripts/variables.sh
cargo install cargo-lipo
case "$(uname | tr '[:upper:]' '[:lower:]')" in
darwin)
echo 'Add rust toolchains for android and ios'
for i in "${IOS_ARCHS[@]}";
do rustup target add "$i";
done
for i in "${ANDROID_ARCHS[@]}";
do rustup target add "$i" ;
done
;;
linux)
echo 'Add rust toolchains for android'
for i in "${ANDROID_ARCHS[@]}";
do rustup target add "$i" ;
done
;;
*)
echo 'Please use a Linux or Mac to build'
;;
esac
FILE=./android/app/debug.keystore
if [ -f "$FILE" ]; then
echo "$FILE exist, skip.."
else
echo "generating andriod debug keystore file.."
cd ./android/app && keytool -genkey -v -keystore debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000
fi
#!/bin/bash
# Change this name to the rust library name
LIB_NAME=signer
API_LEVEL=29
ANDROID_ARCHS=(aarch64-linux-android armv7-linux-androideabi i686-linux-android)
ANDROID_FOLDER=(arm64-v8a armeabi-v7a x86 x86_64)
ANDROID_BIN_PREFIX=(aarch64-linux-android armv7a-linux-androideabi i686-linux-android)
IOS_ARCHS=(aarch64-apple-ios x86_64-apple-ios)
OS_ARCH=$(uname | tr '[:upper:]' '[:lower:]')
ANDROID_PREBUILD_BIN=${NDK_HOME}/toolchains/llvm/prebuilt/${OS_ARCH}-x86_64/bin
#CC_aarch64_linux_android=${ANDROID_PREBUILD_BIN}/aarch64-linux-android29-clang
#CC_armv7_linux_androideabi=${ANDROID_PREBUILD_BIN}/armv7a-linux-androideabi29-clang
#CC_i686_linux_android=${ANDROID_PREBUILD_BIN}/i686-linux-android29-clang
#CC_x86_64_linux_android=${ANDROID_PREBUILD_BIN}/x86_64-linux-android29-clang
#! /bin/bash
set -e
# android
rustup target add aarch64-linux-android
rustup target add armv7-linux-androideabi
rustup target add i686-linux-android
./create-ndk-standalone.sh
yarn
#! /bin/bash
set -e
# ios
rustup target add x86_64-apple-ios
rustup target add armv7-apple-ios
rustup target add armv7s-apple-ios
rustup target add aarch64-apple-ios
# android
rustup target add aarch64-linux-android
rustup target add armv7-linux-androideabi
rustup target add i686-linux-android
./create-ndk-standalone.sh
yarn
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment