From cc2664c519d570c59afc981b81d1b7aa2c5f160f Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 16 Oct 2023 13:31:02 +0200 Subject: [PATCH 1/3] Use local SDK if the file exist --- docs/_developer_onboarding.md | 13 ++++--------- libraries/matrix/impl/build.gradle.kts | 8 ++++++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/docs/_developer_onboarding.md b/docs/_developer_onboarding.md index 7af9207365..a100a2beba 100644 --- a/docs/_developer_onboarding.md +++ b/docs/_developer_onboarding.md @@ -117,6 +117,10 @@ You can also have access to the aars through the [release](https://github.com/ma #### Build the SDK locally +Easiest way: run the script [./tools/sdk/build_rust_sdk.sh](./tools/sdk/build_rust_sdk.sh) and just answer the questions. + +Legacy way: + If you need to locally build the sdk-android you can use the [build](https://github.com/matrix-org/matrix-rust-components-kotlin/blob/main/scripts/build.sh) script. @@ -147,15 +151,6 @@ Troubleshooting: - If you get the error `thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', .cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-ndk-2.11.0/src/cli.rs:345:18` try updating your Cargo NDK version. In this case, 2.11.0 is too old so `cargo install cargo-ndk` to install a newer version. - If you get the error `Unsupported class file major version 64` try changing your JVM version. In this case, Java 20 is not supported in Gradle yet, so downgrade to an earlier version (Java 17 worked in this case). -Finally let the `matrix/impl` module use this aar by changing the dependencies from `libs.matrix.sdk` to `projects.libraries.rustsdk`: - -```groovy -dependencies { - api(projects.libraries.rustsdk) // <- use the local version of the sdk. Uncomment this line. - //implementation(libs.matrix.sdk) // <- use the released version. Comment this line. -} -``` - You are good to test your local rust development now! ### The Android project diff --git a/libraries/matrix/impl/build.gradle.kts b/libraries/matrix/impl/build.gradle.kts index a2b616f989..ff65a2768d 100644 --- a/libraries/matrix/impl/build.gradle.kts +++ b/libraries/matrix/impl/build.gradle.kts @@ -29,8 +29,12 @@ anvil { } dependencies { - // implementation(projects.libraries.rustsdk) - implementation(libs.matrix.sdk) + if (file("${rootDir.path}/libraries/rustsdk/matrix-rust-sdk.aar").exists()) { + println("\nNote: Using local binary of the Rust SDK.\n") + implementation(projects.libraries.rustsdk) + } else { + implementation(libs.matrix.sdk) + } implementation(projects.libraries.di) implementation(projects.libraries.androidutils) implementation(projects.libraries.network) From 9d0cfd903d1800f8becb071bb5fb0ae5d2a98d58 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 16 Oct 2023 11:11:45 +0200 Subject: [PATCH 2/3] Add script to build the rustSdk --- tools/sdk/build_rust_sdk.sh | 80 +++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 tools/sdk/build_rust_sdk.sh diff --git a/tools/sdk/build_rust_sdk.sh b/tools/sdk/build_rust_sdk.sh new file mode 100755 index 0000000000..2a6b7b72d0 --- /dev/null +++ b/tools/sdk/build_rust_sdk.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash + +# Exit on error +set -e + +# Ask to build from local source or to clone the repository +read -p "Do you want to build the Rust SDK from local source (yes/no) default to yes? " buildLocal +buildLocal=${buildLocal:-yes} + +date=$(gdate +%Y%m%d%H%M%S) + +# Ask for the Rust SDK local source path +# if folder rustSdk/ exists, use it as default +if [ ${buildLocal} == "yes" ]; then + read -p "Please enter the path to the Rust SDK local source, default to ../matrix-rust-sdk" rustSdkPath + rustSdkPath=${rustSdkPath:-../matrix-rust-sdk/} + if [ ! -d "${rustSdkPath}" ]; then + printf "\nFolder ${rustSdkPath} does not exist. Please clone the matrix-rust-sdk repository in the folder ../matrix-rust-sdk.\n\n" + exit 0 + fi +else + read -p "Please enter the Rust SDK repository url, default to https://github.com/matrix-org/matrix-rust-sdk.git " rustSdkUrl + rustSdkUrl=${rustSdkUrl:-https://github.com/matrix-org/matrix-rust-sdk.git} + read -p "Please enter the Rust SDK branch, default to main " rustSdkBranch + rustSdkBranch=${rustSdkBranch:-main} + cd .. + git clone ${rustSdkUrl} matrix-rust-sdk-$date + cd matrix-rust-sdk-$date + git checkout ${rustSdkBranch} + rustSdkPath=$(pwd) + cd ../element-x-android +fi + + +cd ${rustSdkPath} +git status + +read -p "Will build with this version of the Rust SDK ^. Is it correct (yes/no) default to yes? " sdkCorrect +sdkCorrect=${sdkCorrect:-yes} + +if [ ${sdkCorrect} != "yes" ]; then + exit 0 +fi + +# Ask if the user wants to build the app after +read -p "Do you want to build the app after (yes/no) default to yes? " buildApp +buildApp=${buildApp:-yes} + +# If folder ../matrix-rust-components-kotlin does not exist, close 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" + git clone https://github.com/matrix-org/matrix-rust-components-kotlin.git ../matrix-rust-components-kotlin +fi + +printf "\nResetting matrix-rust-components-kotlin to the latest main branch...\n\n" +cd ../matrix-rust-components-kotlin +git reset --hard +git checkout main +git pull + +printf "\nBuilding the SDK...\n\n" +./scripts/build.sh -p ${rustSdkPath} -m sdk -t aarch64-linux-android -o ../element-x-android/libraries/rustsdk + +cd ../element-x-android +mv ./libraries/rustsdk/sdk-android-debug.aar ./libraries/rustsdk/matrix-rust-sdk.aar +mkdir -p ./libraries/rustsdk/sdks +cp ./libraries/rustsdk/matrix-rust-sdk.aar ./libraries/rustsdk/matrix-rust-sdk-${date}.aar + + +if [ ${buildApp} != "yes" ]; then + printf "\nBuilding the application...\n\n" + ./gradlew assembleDebug +fi + +if [ ${buildLocal} == "no" ]; then + printf "\nCleaning up...\n\n" + rm -rf ../matrix-rust-sdk-$date +fi + +printf "\nDone!\n" From 21e24990c44dceab38eae537ad101fbb0e1778be Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 16 Oct 2023 18:29:25 +0200 Subject: [PATCH 3/3] Improve and fix build_rust_sdk.sh after PR review --- libraries/matrix/impl/build.gradle.kts | 5 +++-- tools/sdk/build_rust_sdk.sh | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libraries/matrix/impl/build.gradle.kts b/libraries/matrix/impl/build.gradle.kts index ff65a2768d..23a428c38f 100644 --- a/libraries/matrix/impl/build.gradle.kts +++ b/libraries/matrix/impl/build.gradle.kts @@ -29,11 +29,12 @@ anvil { } dependencies { + releaseImplementation(libs.matrix.sdk) if (file("${rootDir.path}/libraries/rustsdk/matrix-rust-sdk.aar").exists()) { println("\nNote: Using local binary of the Rust SDK.\n") - implementation(projects.libraries.rustsdk) + debugImplementation(projects.libraries.rustsdk) } else { - implementation(libs.matrix.sdk) + debugImplementation(libs.matrix.sdk) } implementation(projects.libraries.di) implementation(projects.libraries.androidutils) diff --git a/tools/sdk/build_rust_sdk.sh b/tools/sdk/build_rust_sdk.sh index 2a6b7b72d0..6853642218 100755 --- a/tools/sdk/build_rust_sdk.sh +++ b/tools/sdk/build_rust_sdk.sh @@ -46,7 +46,7 @@ fi read -p "Do you want to build the app after (yes/no) default to yes? " buildApp buildApp=${buildApp:-yes} -# If folder ../matrix-rust-components-kotlin does not exist, close the repo +# 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" git clone https://github.com/matrix-org/matrix-rust-components-kotlin.git ../matrix-rust-components-kotlin @@ -58,7 +58,7 @@ git reset --hard git checkout main git pull -printf "\nBuilding the SDK...\n\n" +printf "\nBuilding the SDK for aarch64-linux-android...\n\n" ./scripts/build.sh -p ${rustSdkPath} -m sdk -t aarch64-linux-android -o ../element-x-android/libraries/rustsdk cd ../element-x-android @@ -67,7 +67,7 @@ mkdir -p ./libraries/rustsdk/sdks cp ./libraries/rustsdk/matrix-rust-sdk.aar ./libraries/rustsdk/matrix-rust-sdk-${date}.aar -if [ ${buildApp} != "yes" ]; then +if [ ${buildApp} == "yes" ]; then printf "\nBuilding the application...\n\n" ./gradlew assembleDebug fi