Skip to content

Commit b98c8dc

Browse files
committed
build.sh: support -l opt to build for local arch
We might as well make it easy for people, rather than telling them to build for aarch64 which may or may not be useful. (Compare element-hq/element-x-android#4021)
1 parent dbb92ef commit b98c8dc

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

README.md

Lines changed: 6 additions & 8 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

scripts/build.sh

Lines changed: 16 additions & 2 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=()

0 commit comments

Comments
 (0)