From 755057c9ed9a3a933a92791f74fa34184158a0c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Fri, 15 Sep 2023 14:06:18 +0200 Subject: [PATCH] tests: Move install_rust.sh from the tests repo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We'll use it as part of the refactoring we're doing in the static check tests. I can see a lot of other uses of this, but changing all of them to this one is out of the scope for this PR. Fixes: #7974 -- part 0 Signed-off-by: Fabiano FidĂȘncio (cherry picked from commit 6794d4c843e9b5bf91c1b1fdae88585cab0dd7c4) --- tests/install_rust.sh | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 tests/install_rust.sh diff --git a/tests/install_rust.sh b/tests/install_rust.sh new file mode 100755 index 0000000000..6fc62ef025 --- /dev/null +++ b/tests/install_rust.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# +# Copyright (c) 2019 Ant Financial +# +# SPDX-License-Identifier: Apache-2.0 + +set -o errexit +set -o nounset +set -o pipefail + +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +script_name="$(basename "${BASH_SOURCE[0]}")" + +source "${script_dir}/common.bash" + +rustarch=$(arch_to_rust) + +version="${1:-""}" +if [ -z "${version}" ]; then + version=$(get_from_kata_deps "languages.rust.meta.newest-version") +fi + +echo "Install rust ${version}" + +if ! command -v rustup > /dev/null; then + curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain ${version} +fi + +export PATH="${PATH}:${HOME}/.cargo/bin" + +## Still try to install the target version of toolchain, +## in case that the rustup has been installed but +## with a different version toolchain. +## Even though the target version toolchain has been installed, +## this command will not take too long to run. +rustup toolchain install ${version} +rustup default ${version} +if [ "${rustarch}" == "powerpc64le" ] || [ "${rustarch}" == "s390x" ] ; then + rustup target add ${rustarch}-unknown-linux-gnu +else + rustup target add ${rustarch}-unknown-linux-musl + $([ "$(whoami)" != "root" ] && echo sudo) ln -sf /usr/bin/g++ /bin/musl-g++ +fi +rustup component add rustfmt