Skip to content

Commit 6e69476

Browse files
authored
Merge pull request #68 from matrix-org/rav/build_docs_improvements
2 parents e49140e + 8837b51 commit 6e69476

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

README.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,21 @@ Usage :
2020

2121
## Testing locally
2222
As the package vendors a pre-built binary of the SDK, all local development is done via the SDK's repo instead of this one.
23-
You can use the build script to generate the AAR file for testing. Be sure to have checkout the matrix-rust-sdk first.
24-
25-
Usage:
23+
You can use the build script to generate the AAR file for testing. Be sure to have checked out the matrix-rust-sdk first.
2624

25+
To build the main crate (eg, for Element-X):
2726
```
28-
./scripts/build.sh -p matrix-rust-sdk-path -m sdk -t aarch64-linux-android
27+
./scripts/build.sh -p <matrix-rust-sdk-path> -m sdk -l
2928
```
3029

31-
To build just the crypto crate, use this instead:
32-
30+
To build just the crypto crate (eg, for Element Android classic), use this instead:
3331
```
34-
./scripts/build.sh -p matrix-rust-sdk-path -m crypto -t aarch64-linux-android
32+
./scripts/build.sh -p matrix-rust-sdk-path -m crypto -l
3533
```
3634

3735
Other useful flags:
3836

39-
- `-o OUTPUT_DIR`: Writes the output AAR file to the dir `OUTPUT_DIR`.
37+
- `-o OUTPUT_DIR`: Moves the generated AAR file to the dir `OUTPUT_DIR`.
4038
- `-r`: Produces a release build instead of a development one.
4139

4240
## Prerequisites
@@ -45,11 +43,7 @@ Other useful flags:
4543
* the Rust toolchain
4644
* cargo-ndk `cargo install cargo-ndk`
4745
* protoc `brew install protobuf` or downloading [here](https://github.com/protocolbuffers/protobuf/releases)
48-
* android targets (e.g. `rustup target add \
49-
aarch64-linux-android \
50-
armv7-linux-androideabi \
51-
x86_64-linux-android \
52-
i686-linux-android`)
46+
* android targets (e.g. `rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android`)
5347

5448

5549
## License

scripts/build.sh

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ helpFunction() {
88
echo -e "\t-o Optional output path with the expected name of the aar file"
99
echo -e "\t-r Flag to build in release mode"
1010
echo -e "\t-m Option to select the gradle module to build. Default is sdk"
11-
echo -e "\t-t Option to to select an android target to build against. Default will build for all targets."
11+
echo -e "\t-t Select a target architecture to build for. Default will build for all known Android targets."
12+
echo -e "\t-l Build for the local architecture. Incompatible with '-t'."
1213
exit 1
1314
}
1415

@@ -20,14 +21,16 @@ scripts_dir=$(
2021
is_release='false'
2122
gradle_module='sdk'
2223
only_target=''
24+
local_target=''
2325
output=''
2426

25-
while getopts ':rp:m:t:o:' 'opt'; do
27+
while getopts ':rp:m:t:lo:' 'opt'; do
2628
case ${opt} in
2729
'r') is_release='true' ;;
2830
'p') sdk_path="$OPTARG" ;;
2931
'm') gradle_module="$OPTARG" ;;
3032
't') only_target="$OPTARG" ;;
33+
'l') local_target='true' ;;
3134
'o') output="$OPTARG" ;;
3235
?) helpFunction ;;
3336
esac
@@ -38,6 +41,17 @@ if [ -z "$sdk_path" ]; then
3841
helpFunction
3942
fi
4043

44+
if [ -n "$local_target" ]; then
45+
if [ -n "$only_target" ]; then
46+
echo "Cannot specifiy both '-l' and '-t'." >&2
47+
exit 1
48+
fi
49+
50+
only_target="$(uname -m)-linux-android"
51+
# On ARM MacOS, `uname -m` returns arm64, but the toolchain is called aarch64
52+
only_target="${only_target/arm64/aarch64}"
53+
fi
54+
4155
if [ -z "$only_target" ]; then
4256
echo "no target provided, build for all targets"
4357
target_command=()
@@ -53,7 +67,7 @@ fi
5367

5468
if [ "$gradle_module" = "crypto" ]; then
5569
## NDK is needed for https://crates.io/crates/olm-sys
56-
if [ -z "$ANDROID_NDK" ]; then
70+
if [ -z "$ANDROID_NDK" && -z "$ANDROID_HOME" ]; then
5771
echo "please set the ANDROID_NDK environment variable to your Android NDK installation"
5872
exit 1
5973
fi
@@ -80,9 +94,10 @@ shift $((OPTIND - 1))
8094

8195
moveFunction() {
8296
if [ -z "$output" ]; then
83-
echo "No output path provided, keep the generated path"
97+
echo -e "\nSUCCESS: Output AAR file is '$1'"
8498
else
8599
mv "$1" "$output"
100+
echo -e "\nSUCCESS: Output AAR file is '$output'"
86101
fi
87102
}
88103

0 commit comments

Comments
 (0)