Files
termux-packages/scripts/build/setup/termux_setup_rust.sh
termux-pacman-bot 9860616e2a Update repo
2023-10-07 00:03:25 +00:00

59 lines
1.7 KiB
Bash

# shellcheck shell=bash disable=SC1091 disable=SC2086 disable=SC2155
termux_setup_rust() {
export CARGO_TARGET_NAME="${TERMUX_ARCH}-linux-android"
if [[ "${TERMUX_ARCH}" == "arm" ]]; then
CARGO_TARGET_NAME="armv7-linux-androideabi"
fi
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
or build it from source with
./build-package.sh rust
Note that package 'rust' is known to be problematic for building on device.
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
local ENV_NAME=CARGO_TARGET_${CARGO_TARGET_NAME^^}_LINKER
ENV_NAME=${ENV_NAME//-/_}
export $ENV_NAME="${CC}"
export TARGET_CFLAGS="${CFLAGS-} ${CPPFLAGS}"
# This was getting applied for the host build of Rust macros or whatever, so
# unset it.
unset CFLAGS
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 -sSf > "${TERMUX_PKG_TMPDIR}"/rustup.sh
sh "${TERMUX_PKG_TMPDIR}"/rustup.sh -y --default-toolchain "${TERMUX_RUST_VERSION}"
export PATH="${HOME}/.cargo/bin:${PATH}"
rustup target add "${CARGO_TARGET_NAME}"
}