| 1 |
#!/usr/bin/env bash |
| 2 |
# Install/update rust. |
| 3 |
# The first argument should be the toolchain to install. |
| 4 |
|
| 5 |
set -ex |
| 6 |
if [ -z "$1" ] |
| 7 |
then |
| 8 |
echo "First parameter must be toolchain to install." |
| 9 |
exit 1 |
| 10 |
fi |
| 11 |
TOOLCHAIN="$1" |
| 12 |
|
| 13 |
rustup set profile minimal |
| 14 |
rustup component remove --toolchain=$TOOLCHAIN rust-docs || echo "already removed" |
| 15 |
rustup update --no-self-update $TOOLCHAIN |
| 16 |
if [ -n "$2" ] |
| 17 |
then |
| 18 |
TARGET="$2" |
| 19 |
HOST=$(rustc -Vv | grep ^host: | sed -e "s/host: //g") |
| 20 |
if [ "$HOST" != "$TARGET" ] |
| 21 |
then |
| 22 |
rustup component add llvm-tools-preview --toolchain=$TOOLCHAIN |
| 23 |
rustup component add rust-std-$TARGET --toolchain=$TOOLCHAIN |
| 24 |
fi |
| 25 |
if [[ $TARGET == *"musl" ]] |
| 26 |
then |
| 27 |
# This is needed by libdbus-sys. |
| 28 |
sudo apt update -y && sudo apt install musl-dev musl-tools -y |
| 29 |
fi |
| 30 |
if [[ $TARGET == "aarch64-unknown-linux-musl" ]] |
| 31 |
then |
| 32 |
echo CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=rust-lld >> $GITHUB_ENV |
| 33 |
# This `CC` is some nonsense needed for libdbus-sys (via opener). |
| 34 |
# I don't know if this is really the right thing to do, but it seems to work. |
| 35 |
sudo apt install gcc-aarch64-linux-gnu -y |
| 36 |
echo CC=aarch64-linux-gnu-gcc >> $GITHUB_ENV |
| 37 |
fi |
| 38 |
fi |
| 39 |
|
| 40 |
rustup default $TOOLCHAIN |
| 41 |
rustup -V |
| 42 |
rustc -Vv |
| 43 |
cargo -V |