-
Notifications
You must be signed in to change notification settings - Fork 23
/
cross_build.sh
executable file
·44 lines (40 loc) · 2.15 KB
/
cross_build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
RED='\033[0;31m'
NC='\033[0m' # No Color
main() {
set -ex
# Dev+Debug is better for debugging Rust crashes, but generates much larger libraries (100's of MB)
# PROFILE="dev"
# BINARY_PROFILE="debug"
PROFILE="release"
BINARY_PROFILE="release"
WORKSPACE_MANIFEST="$(cargo locate-project --workspace --message-format=plain)"
WORKSPACE_PATH="$(dirname $WORKSPACE_MANIFEST)"
TARGET_DIR="$WORKSPACE_PATH/target"
BINDINGS_MANIFEST="$WORKSPACE_PATH/bindings_ffi/Cargo.toml"
# Go to the workspace root so that the workspace config can be found by cross
cd $WORKSPACE_PATH
if ! cross &>/dev/null; then
echo -e "${RED} `cargo-cross` not detected. install cargo-cross to continue${NC}";
exit
fi
# Uncomment to build for all targets. aarch64-linux-android is the default target for an emulator on Android Studio on an M1 mac.
cross build --manifest-path $BINDINGS_MANIFEST --target x86_64-linux-android --target-dir $TARGET_DIR --profile $PROFILE && \
cross build --manifest-path $BINDINGS_MANIFEST --target i686-linux-android --target-dir $TARGET_DIR --profile $PROFILE && \
cross build --manifest-path $BINDINGS_MANIFEST --target armv7-linux-androideabi --target-dir $TARGET_DIR --profile $PROFILE && \
cross build --manifest-path $BINDINGS_MANIFEST --target aarch64-linux-android --target-dir $TARGET_DIR --profile $PROFILE
# Move everything to jniLibs folder and rename
LIBRARY_NAME="libxmtpv3"
TARGET_NAME="libuniffi_xmtpv3"
cd $(dirname $BINDINGS_MANIFEST) # cd bindings_ffi
rm -rf jniLibs/
mkdir -p jniLibs/armeabi-v7a/ && \
cp $WORKSPACE_PATH/target/armv7-linux-androideabi/$BINARY_PROFILE/$LIBRARY_NAME.so jniLibs/armeabi-v7a/$TARGET_NAME.so && \
mkdir -p jniLibs/x86/ && \
cp $WORKSPACE_PATH/target/i686-linux-android/$BINARY_PROFILE/$LIBRARY_NAME.so jniLibs/x86/$TARGET_NAME.so && \
mkdir -p jniLibs/x86_64/ && \
cp $WORKSPACE_PATH/target/x86_64-linux-android/$BINARY_PROFILE/$LIBRARY_NAME.so jniLibs/x86_64/$TARGET_NAME.so && \
mkdir -p jniLibs/arm64-v8a/ && \
cp $WORKSPACE_PATH/target/aarch64-linux-android/$BINARY_PROFILE/$LIBRARY_NAME.so jniLibs/arm64-v8a/$TARGET_NAME.so
}
time main