termux-packages/scripts/build/setup/termux_setup_rust.sh

46 lines
1.3 KiB
Bash
Raw Normal View History

termux_setup_rust() {
if [ $TERMUX_ARCH = "arm" ]; then
CARGO_TARGET_NAME=armv7-linux-androideabi
else
CARGO_TARGET_NAME=$TERMUX_ARCH-linux-android
fi
export RUSTFLAGS="-C link-arg=-Wl,-rpath=$TERMUX_PREFIX/lib -C link-arg=-Wl,--enable-new-dtags"
if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then
if [ "$(dpkg-query -W -f '${db:Status-Status}\n' rust 2>/dev/null)" != "installed" ]; then
echo "Package 'rust' is not installed."
echo "You can install it with"
echo
echo " pkg install rust"
echo
echo "or build it from source with"
echo
echo " ./build-package.sh rust"
echo
echo "Note that package 'rust' is known to be problematic for building on device."
exit 1
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
curl https://sh.rustup.rs -sSf > $TERMUX_PKG_TMPDIR/rustup.sh
2019-04-24 00:39:40 +02:00
if [ -z "${TERMUX_RUST_VERSION-}" ]; then
2021-01-10 12:16:43 +01:00
TERMUX_RUST_VERSION=$(bash -c ". $TERMUX_SCRIPTDIR/packages/rust/build.sh; echo \$TERMUX_PKG_VERSION")
fi
2019-04-24 00:39:40 +02:00
2021-01-10 12:16:43 +01:00
sh $TERMUX_PKG_TMPDIR/rustup.sh -y --default-toolchain $TERMUX_RUST_VERSION
export PATH=$HOME/.cargo/bin:$PATH
rustup target add $CARGO_TARGET_NAME
}