scripts: Split installing Rust to its own script

Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
Tim Crawford
2023-08-30 10:54:12 -06:00
committed by Jeremy Soller
parent 51e3e1a53a
commit b22e8dee41
4 changed files with 37 additions and 24 deletions

View File

@ -1,4 +1,5 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-3.0-only
set -eE
@ -101,22 +102,8 @@ curl -sSf https://review.coreboot.org/tools/hooks/commit-msg \
-o .git/modules/coreboot/hooks/commit-msg && \
chmod +x .git/modules/coreboot/hooks/commit-msg
RUSTUP_NEW_INSTALL=0
if which rustup &> /dev/null; then
msg "Updating rustup"
rustup self update
else
RUSTUP_NEW_INSTALL=1
msg "Installing Rust"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
| sh -s -- -y --default-toolchain stable
msg "Loading Rust environment"
source "${HOME}/.cargo/env"
fi
msg "Installing pinned Rust toolchain and components"
rustup show
msg "Installing Rust toolchain and components"
./scripts/install-rust.sh
msg "Installing EC dependencies"
pushd ec
@ -129,10 +116,5 @@ make CPUS="$(nproc)" crossgcc-i386
make CPUS="$(nproc)" crossgcc-x64
popd
if [[ $RUSTUP_NEW_INSTALL = 1 ]]; then
msg "\x1B[33m>> rustup was just installed. Ensure cargo is on the PATH with:"
echo -e " source ~/.cargo/env\n"
fi
msg "\x1B[32mSuccessfully installed dependencies"
echo "Ready to run ./scripts/build.sh [model]" >&2

31
scripts/install-rust.sh Executable file
View File

@ -0,0 +1,31 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-only
# Install Rust via rustup, along with the pinned toolchain.
# shellcheck shell=dash
# shellcheck disable=SC1091
set -Ee
RUSTUP_NEW_INSTALL=0
# NOTE: rustup is used to allow multiple toolchain installations.
if command -v rustup >/dev/null 2>&1; then
rustup self update
else
RUSTUP_NEW_INSTALL=1
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
| sh -s -- -y --default-toolchain stable
. "${HOME}/.cargo/env"
fi
# XXX: rustup has no command to install a toolchain from a TOML file.
# Rely on the fact that `show` will install the default toolchain.
rustup show
if [ "$RUSTUP_NEW_INSTALL" = "1" ]; then
printf "\e[33m>> rustup was just installed. Ensure cargo is on the PATH with:\e[0m\n"
printf " source ~/.cargo/env\n\n"
fi