2024-05-10 22:56:00 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# env needed:
|
|
|
|
# - TARGET
|
|
|
|
# - GUI_TARGET
|
|
|
|
# - OS
|
|
|
|
|
|
|
|
# dependencies are only needed on ubuntu as that's the only place where
|
|
|
|
# we make cross-compilation
|
|
|
|
if [[ $OS =~ ^ubuntu.*$ ]]; then
|
2024-07-08 23:18:10 +08:00
|
|
|
sudo apt-get update && sudo apt-get install -qq crossbuild-essential-arm64 crossbuild-essential-armhf musl-tools libappindicator3-dev
|
2024-05-10 22:56:00 +08:00
|
|
|
# for easytier-gui
|
2024-07-08 23:18:10 +08:00
|
|
|
if [[ $GUI_TARGET != '' && $GUI_TARGET =~ ^x86_64.*$ ]]; then
|
|
|
|
sudo apt install -qq libwebkit2gtk-4.1-dev \
|
2024-05-10 22:56:00 +08:00
|
|
|
build-essential \
|
|
|
|
curl \
|
|
|
|
wget \
|
|
|
|
file \
|
|
|
|
libgtk-3-dev \
|
|
|
|
librsvg2-dev \
|
2024-07-08 23:18:10 +08:00
|
|
|
libxdo-dev \
|
|
|
|
libssl-dev \
|
2024-05-10 22:56:00 +08:00
|
|
|
patchelf
|
|
|
|
fi
|
|
|
|
# curl -s musl.cc | grep mipsel
|
|
|
|
case $TARGET in
|
|
|
|
mipsel-unknown-linux-musl)
|
|
|
|
MUSL_URI=mipsel-linux-muslsf
|
|
|
|
;;
|
2024-06-03 23:07:44 +08:00
|
|
|
mips-unknown-linux-musl)
|
|
|
|
MUSL_URI=mips-linux-muslsf
|
|
|
|
;;
|
2024-05-10 22:56:00 +08:00
|
|
|
aarch64-unknown-linux-musl)
|
|
|
|
MUSL_URI=aarch64-linux-musl
|
|
|
|
;;
|
|
|
|
armv7-unknown-linux-musleabihf)
|
|
|
|
MUSL_URI=armv7l-linux-musleabihf
|
|
|
|
;;
|
2024-06-03 23:07:44 +08:00
|
|
|
armv7-unknown-linux-musleabi)
|
|
|
|
MUSL_URI=armv7m-linux-musleabi
|
|
|
|
;;
|
2024-05-10 22:56:00 +08:00
|
|
|
arm-unknown-linux-musleabihf)
|
|
|
|
MUSL_URI=arm-linux-musleabihf
|
|
|
|
;;
|
2024-06-03 23:07:44 +08:00
|
|
|
arm-unknown-linux-musleabi)
|
|
|
|
MUSL_URI=arm-linux-musleabi
|
2024-05-10 22:56:00 +08:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ -n "$MUSL_URI" ]; then
|
|
|
|
mkdir -p ./musl_gcc
|
|
|
|
wget -c https://musl.cc/${MUSL_URI}-cross.tgz -P ./musl_gcc/
|
|
|
|
tar zxf ./musl_gcc/${MUSL_URI}-cross.tgz -C ./musl_gcc/
|
|
|
|
sudo ln -s $(pwd)/musl_gcc/${MUSL_URI}-cross/bin/*gcc /usr/bin/
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# see https://github.com/rust-lang/rustup/issues/3709
|
|
|
|
rustup set auto-self-update disable
|
2024-08-04 09:46:24 +08:00
|
|
|
rustup install 1.77
|
|
|
|
rustup default 1.77
|
2024-05-10 22:56:00 +08:00
|
|
|
|
|
|
|
# mips/mipsel cannot add target from rustup, need compile by ourselves
|
|
|
|
if [[ $OS =~ ^ubuntu.*$ && $TARGET =~ ^mips.*$ ]]; then
|
|
|
|
cd "$PWD/musl_gcc/${MUSL_URI}-cross/lib/gcc/${MUSL_URI}/11.2.1" || exit 255
|
|
|
|
# for panic-abort
|
|
|
|
cp libgcc_eh.a libunwind.a
|
|
|
|
|
|
|
|
# for mimalloc
|
|
|
|
ar x libgcc.a _ctzsi2.o _clz.o _bswapsi2.o
|
|
|
|
ar rcs libctz.a _ctzsi2.o _clz.o _bswapsi2.o
|
|
|
|
|
|
|
|
rustup toolchain install nightly-x86_64-unknown-linux-gnu
|
|
|
|
rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu
|
2024-08-08 20:07:22 +08:00
|
|
|
|
|
|
|
# https://github.com/rust-lang/rust/issues/128808
|
|
|
|
# remove it after Cargo or rustc fix this.
|
|
|
|
RUST_LIB_SRC=$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/
|
|
|
|
if [[ -f $RUST_LIB_SRC/library/Cargo.lock && ! -f $RUST_LIB_SRC/Cargo.lock ]]; then
|
|
|
|
cp -f $RUST_LIB_SRC/library/Cargo.lock $RUST_LIB_SRC/Cargo.lock
|
|
|
|
fi
|
2024-05-10 22:56:00 +08:00
|
|
|
else
|
|
|
|
rustup target add $TARGET
|
|
|
|
if [[ $GUI_TARGET != '' ]]; then
|
|
|
|
rustup target add $GUI_TARGET
|
|
|
|
fi
|
|
|
|
fi
|