0
0
mirror of https://github.com/termux/termux-packages.git synced 2025-03-04 08:18:54 +00:00
termux-packages/scripts/build/setup/termux_setup_rust.sh
Jia Yuan Lo be443fa11e scripts(termux_setup_rust): move rust variables to termux_setup_toolchain file
Remove RUSTFLAGS which is incorrectly used
Use CARGO_TARGET_*_RUSTFLAGS instead

Remove global unset CFLAGS after call termux_setup_rust
Should be done per package if neccessary
2024-12-07 02:39:26 +08:00

42 lines
1.2 KiB
Bash

# shellcheck shell=bash disable=SC1091 disable=SC2086 disable=SC2155
termux_setup_rust() {
if [[ "${TERMUX_ON_DEVICE_BUILD}" == "true" ]]; then
if [[ -z "$(command -v rustc)" ]]; then
cat <<- EOL
Package 'rust' is not installed.
You can install it with
pkg install rust
pacman -S rust
EOL
exit 1
fi
local RUSTC_VERSION=$(rustc --version | awk '{ print $2 }')
if [[ -n "${TERMUX_RUST_VERSION-}" && "${TERMUX_RUST_VERSION-}" != "${RUSTC_VERSION}" ]]; then
cat <<- EOL >&2
WARN: On device build with old rust version is not possible!
TERMUX_RUST_VERSION = ${TERMUX_RUST_VERSION}
RUSTC_VERSION = ${RUSTC_VERSION}
EOL
fi
return
fi
if [[ -z "${TERMUX_RUST_VERSION-}" ]]; then
TERMUX_RUST_VERSION=$(. "${TERMUX_SCRIPTDIR}"/packages/rust/build.sh; echo ${TERMUX_PKG_VERSION})
fi
if [[ "${TERMUX_RUST_VERSION}" == *"~beta"* ]]; then
TERMUX_RUST_VERSION="beta"
fi
curl https://sh.rustup.rs -sSfo "${TERMUX_PKG_TMPDIR}"/rustup.sh
sh "${TERMUX_PKG_TMPDIR}"/rustup.sh -y --default-toolchain "${TERMUX_RUST_VERSION}"
export PATH="${HOME}/.cargo/bin:${PATH}"
if [[ -n "${CARGO_TARGET_NAME-}" ]]; then
rustup target add "${CARGO_TARGET_NAME}"
fi
}