From 60ea133357f9f187c9338ef2f1b27b3c0d413fd8 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 11 Dec 2024 18:03:09 +0000 Subject: [PATCH 1/2] Build SDK for the local hardware It's likely that you want to build the SDK to run on the emulator on your machine, so let's default to that, rather than aarch64. --- docs/_developer_onboarding.md | 4 ++-- tools/sdk/build_rust_sdk.sh | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/_developer_onboarding.md b/docs/_developer_onboarding.md index e234275af6..857bc6f44b 100644 --- a/docs/_developer_onboarding.md +++ b/docs/_developer_onboarding.md @@ -130,9 +130,9 @@ Prerequisites: ``` cargo install cargo-ndk ``` -* Install the Android Rust toolchain: +* Install the Android Rust toolchain for your machine's hardware: ``` - rustup target add aarch64-linux-android + rustup target add `uname -m`-linux-android ``` * Depending on the location of the Android SDK, you may need to set `ANDROID_HOME`: diff --git a/tools/sdk/build_rust_sdk.sh b/tools/sdk/build_rust_sdk.sh index f0c0378333..be4745a909 100755 --- a/tools/sdk/build_rust_sdk.sh +++ b/tools/sdk/build_rust_sdk.sh @@ -59,6 +59,10 @@ buildApp=${buildApp:-no} cd "${elementPwd}" +default_arch="$(uname -m)-linux-android" +read -p "Enter the architecture you want to build for (default '$default_arch'): " target_arch +target_arch="${target_arch:-${default_arch}}" + # If folder ../matrix-rust-components-kotlin does not exist, clone the repo if [ ! -d "../matrix-rust-components-kotlin" ]; then printf "\nFolder ../matrix-rust-components-kotlin does not exist. Cloning the repository into ../matrix-rust-components-kotlin.\n\n" @@ -71,8 +75,8 @@ git reset --hard git checkout main git pull -printf "\nBuilding the SDK for aarch64-linux-android...\n\n" -./scripts/build.sh -p "${rustSdkPath}" -m sdk -t aarch64-linux-android -o "${elementPwd}/libraries/rustsdk" +printf "\nBuilding the SDK for ${target_arch}...\n\n" +./scripts/build.sh -p "${rustSdkPath}" -m sdk -t "${target_arch}" -o "${elementPwd}/libraries/rustsdk" cd "${elementPwd}" mv ./libraries/rustsdk/sdk-android-debug.aar ./libraries/rustsdk/matrix-rust-sdk.aar From 5a2c1ae0001c84e3aa878d28cda4e1ffcb29b3e4 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 11 Dec 2024 22:29:35 +0000 Subject: [PATCH 2/2] Handle `uname -m` returning arm64 --- docs/_developer_onboarding.md | 2 +- tools/sdk/build_rust_sdk.sh | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/_developer_onboarding.md b/docs/_developer_onboarding.md index 857bc6f44b..738bd12430 100644 --- a/docs/_developer_onboarding.md +++ b/docs/_developer_onboarding.md @@ -132,7 +132,7 @@ Prerequisites: ``` * Install the Android Rust toolchain for your machine's hardware: ``` - rustup target add `uname -m`-linux-android + rustup target add aarch64-linux-android x86_64-linux-android ``` * Depending on the location of the Android SDK, you may need to set `ANDROID_HOME`: diff --git a/tools/sdk/build_rust_sdk.sh b/tools/sdk/build_rust_sdk.sh index be4745a909..7c65604167 100755 --- a/tools/sdk/build_rust_sdk.sh +++ b/tools/sdk/build_rust_sdk.sh @@ -60,6 +60,9 @@ buildApp=${buildApp:-no} cd "${elementPwd}" default_arch="$(uname -m)-linux-android" +# On ARM MacOS, `uname -m` returns arm64, but the toolchain is called aarch64 +default_arch="${default_arch/arm64/aarch64}" + read -p "Enter the architecture you want to build for (default '$default_arch'): " target_arch target_arch="${target_arch:-${default_arch}}"