opt/rust/Pkgfile

181 lines
5.4 KiB
Plaintext
Raw Normal View History

2018-12-26 09:59:18 +01:00
# Description: The Rust language with Cargo included.
# URL: https://www.rust-lang.org/
2018-12-26 09:59:18 +01:00
# Maintainer: Danny Rawlins, crux at romster dot me
2021-05-08 05:29:36 +02:00
# Depends on: compiler-rt
# Optional: sccache ccache libgit2 lld polly
2018-12-26 09:59:18 +01:00
name=rust
2021-12-04 15:16:46 +01:00
version=1.57.0
_date=2021-11-01
_rustc=1.56.1
2021-03-27 07:50:54 +01:00
_cargo=$_rustc
release=1
2021-01-02 11:52:18 +01:00
source=(https://static.rust-lang.org/dist/${name}c-$version-src.tar.xz
https://static.rust-lang.org/dist/$_date/rust-std-$_rustc-x86_64-unknown-linux-gnu.tar.xz
https://static.rust-lang.org/dist/$_date/rustc-$_rustc-x86_64-unknown-linux-gnu.tar.xz
2021-03-27 07:50:54 +01:00
https://static.rust-lang.org/dist/$_date/cargo-$_cargo-x86_64-unknown-linux-gnu.tar.xz
2021-06-18 14:47:56 +02:00
libexec.patch
2021-08-30 13:00:09 +02:00
0002-compiler-Change-LLVM-targets.patch)
unpack_source() {
for file in ${source[@]}; do
case ${file##*/} in
2021-05-08 05:29:36 +02:00
rustc-${version}-src.tar.xz)
echo "Unpacking $(get_filename $file)";
2020-08-29 16:17:08 +02:00
bsdtar -p -o -C ${SRC} -xf $(get_filename $file) ;;
*.tar.xz)
echo "Copying $(get_filename $file)";
2020-08-29 16:17:08 +02:00
mkdir -p ${SRC}/${name}c-$version-src/build/cache/${_date} || true
cp $(get_filename $file) ${SRC}/${name}c-$version-src/build/cache/${_date} ;;
*)
2020-08-29 16:17:08 +02:00
cp $(get_filename $file) ${SRC} ;;
esac
done
}
2021-12-04 15:16:46 +01:00
_check_version() {
local ERROR
local DATE="$(awk '/^.*"date": / {gsub(/"|,/, "", $2); print $2 }' $SRC/${name}c-$version-src/src/stage0.json)"
local RUSTC="$(awk '/^.*"version": / {gsub(/"|,/, "", $2); print $2 }' $SRC/${name}c-$version-src/src/stage0.json)"
2018-12-26 09:59:18 +01:00
2021-12-04 15:16:46 +01:00
printf '\033[0;32m%s\033[0m\n' "Checking versions for bootstrap compiler.."
printf '\033[0;32m%s\033[0m\n' "Got _date = $_date && _rustc = $_rustc"
2021-02-13 14:28:47 +01:00
2019-10-11 11:37:45 +02:00
if [ "$DATE" != "$_date" ]; then
2021-12-04 15:16:46 +01:00
printf '\e[1;31m%-6s\e[m\n' "Error: _date $_date != $DATE"
2019-10-11 11:37:45 +02:00
ERROR=1
fi
if [ "$RUSTC" != "$_rustc" ]; then
2021-12-04 15:16:46 +01:00
printf '\e[1;31m%-6s\e[m\n' "Error: _rustc $_rustc != $RUSTC"
2019-10-11 11:37:45 +02:00
ERROR=1
fi
2021-12-04 15:16:46 +01:00
2019-10-11 11:37:45 +02:00
[ $ERROR ] && exit 1
2021-12-04 15:16:46 +01:00
printf '\033[0;32m%s\033[0m\n' "Versions check out! Proceeding.."
2021-01-02 11:52:18 +01:00
unset DATE RUSTC ERROR
2021-12-04 15:16:46 +01:00
}
build() {
_check_version
cd "${name}c-$version-src"
# Patch cargo so credential helpers are in /usr/lib instead of /usr/libexec
patch -p1 -i $SRC/libexec.patch
# Use our *-pc-linux-gnu targets, making LTO with clang simpler
patch -p1 -i $SRC/0002-compiler-Change-LLVM-targets.patch
2019-10-11 11:37:45 +02:00
2018-12-26 09:59:18 +01:00
cat <<- EOF > $SRC/config.toml
2021-09-25 15:59:34 +02:00
changelog-seen = 2
2018-12-26 09:59:18 +01:00
[llvm]
2019-02-15 11:00:35 +01:00
ninja = true
2019-04-16 17:24:08 +02:00
link-shared = true
@POLLY@
2021-01-02 11:52:18 +01:00
@CCACHE@
2018-12-26 09:59:18 +01:00
[install]
prefix = "/usr"
[rust]
2021-08-30 13:00:09 +02:00
# LLVM crashes when passing an object through ThinLTO twice. This is triggered
# when using rust code in cross-language LTO if libstd was built using ThinLTO.
# http://blog.llvm.org/2019/09/closing-gap-cross-language-lto-between.html
# https://github.com/rust-lang/rust/issues/54872
codegen-units-std = 1
debuginfo-level-std = 2
codegen-tests = false
description = "CRUX"
2018-12-26 09:59:18 +01:00
channel = "stable"
2021-09-25 15:59:34 +02:00
parallel-compiler = true
2018-12-26 09:59:18 +01:00
rpath = false
optimize = true
@LLD@
2018-12-26 09:59:18 +01:00
[build]
2020-08-29 16:17:08 +02:00
target = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"]
tools = ["cargo", "rls", "clippy", "rustfmt", "analysis", "src", "rust-demangler"]
2019-02-15 11:00:35 +01:00
docs = false
2018-12-26 09:59:18 +01:00
extended = true
sanitizers = true
2020-08-29 16:17:08 +02:00
profiler = true
vendor = true
python = "/usr/bin/python3"
@CARGO@
@RUST@
2021-08-30 13:00:09 +02:00
@RUSTFMT@
2020-08-29 16:17:08 +02:00
[target.x86_64-unknown-linux-gnu]
llvm-config = "/usr/bin/llvm-config"
2021-08-30 13:00:09 +02:00
llvm-filecheck = "/usr/bin/FileCheck"
2018-12-26 09:59:18 +01:00
EOF
2020-08-29 16:17:08 +02:00
if [ -e '/usr/bin/rustc' ]; then
if [[ -z "$(/usr/bin/ldd /usr/bin/rustc | egrep '.*libLLVM.*.so => not found')" && \
-z "$(/usr/bin/ldd /usr/bin/cargo | egrep 'libgit2.so.* => not found')" ]]; then
2020-08-29 16:17:08 +02:00
sed -e 's|@CARGO@|cargo = "/usr/bin/cargo"|' \
-e 's|@RUST@|rustc = "/usr/bin/rustc"|' \
2021-08-30 13:00:09 +02:00
-e 's|@RUSTFMT@|rustfmt = "/usr/bin/rustfmt"|' \
2020-08-29 16:17:08 +02:00
-i $SRC/config.toml
2019-06-03 16:20:39 +02:00
else
2021-08-30 13:00:09 +02:00
sed -e 's|@CARGO@||' -e 's|@RUST@||' -e 's|@RUSTFMT@||' -i $SRC/config.toml
printf "\e[031mShared library missing, not using system rust to bootstrap.\033[0m\n"
2019-06-03 16:20:39 +02:00
fi
2020-08-29 16:17:08 +02:00
else
2021-08-30 13:00:09 +02:00
sed -e 's|@CARGO@||' -e 's|@RUST@||' -e 's|@RUSTFMT@||' -i $SRC/config.toml
2018-12-26 09:59:18 +01:00
fi
2021-01-02 11:52:18 +01:00
if [ -e '/usr/bin/ccache' ]; then
sed -e 's|@CCACHE@|ccache = "/usr/bin/ccache"|' -i $SRC/config.toml
else
sed -e 's|@CCACHE@||' -i $SRC/config.toml
fi
prt-get isinst lld && sed -e 's|@LLD@|use-lld = true|' -i $SRC/config.toml || sed -e 's|@LLD@||' -i $SRC/config.toml
prt-get isinst polly && sed -e 's|@POLLY@|polly = true|' -i $SRC/config.toml || sed -e 's|@POLLY@||' -i $SRC/config.toml
2018-12-26 09:59:18 +01:00
cat $SRC/config.toml
2019-05-18 13:19:04 +02:00
mkdir "$PKGMK_SOURCE_DIR/rust" || true
export CARGO_HOME="$PKGMK_SOURCE_DIR/rust"
2018-12-26 09:59:18 +01:00
if [ -e '/usr/bin/sccache' ]; then
export RUSTC_WRAPPER='/usr/bin/sccache'
export SCCACHE_IDLE_TIMEOUT='1500'
fi
2019-02-15 11:00:35 +01:00
2021-12-05 04:05:24 +01:00
#error: field is never read: `id`
# --> src/bootstrap/lib.rs:280:5
# = note: `-D dead-code` implied by `-D warnings`
RUSTFLAGS+=' -A dead_code'
export LIBGIT2_NO_PKG_CONFIG=1
2021-06-18 14:47:56 +02:00
export RUST_BACKTRACE=full
2021-05-08 05:29:36 +02:00
/usr/bin/python3 ./x.py build --config="${SRC}"/config.toml -j ${JOBS-1}
2018-12-26 09:59:18 +01:00
DESTDIR=$PKG /usr/bin/python3 ./x.py --config="${SRC}"/config.toml install
[ -e '/usr/bin/zsh' ] || rm -r $PKG/usr/share/zsh
# cleanup
2018-12-26 09:59:18 +01:00
rm -r $PKG/usr/share/doc
rm -r $PKG/etc
rm $PKG/usr/lib/rustlib/{components,manifest-rustc,rust-installer-version,uninstall.sh}
2020-06-20 09:33:25 +02:00
# Remove analysis data for libs that weren't installed
local file lib
while read -rd '' file; do
lib="${file%.json}.rlib"
lib="${lib/\/analysis\///lib/}"
if [[ ! -e $lib ]]; then
echo "missing '$lib'"
rm -v "$file"
fi
done < <(find "$PKG/usr/lib/rustlib" -path '*/analysis/*.json' -print0)
install -d $PKG/etc/revdep.d
2021-01-02 11:52:18 +01:00
echo "/usr/lib/rustlib/i686-unknown-linux-gnu/lib" > $PKG/etc/revdep.d/$name
2018-12-26 09:59:18 +01:00
}