opt/rust/Pkgfile

218 lines
6.5 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/
2023-03-10 11:58:29 +01:00
# Maintainer: CRUX System Team, core-ports at crux dot nu
2021-05-08 05:29:36 +02:00
# Depends on: compiler-rt
2023-10-06 14:29:02 +02:00
# Optional: ccache clang libgit2 lld polly sccache
2018-12-26 09:59:18 +01:00
name=rust
2024-02-08 18:24:45 +01:00
version=1.76.0
_date=2023-12-28
_rustc=1.75.0
2021-03-27 07:50:54 +01:00
_cargo=$_rustc
2023-10-06 14:29:02 +02:00
release=1
2022-02-05 16:00:17 +01:00
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
2022-05-21 12:20:18 +02:00
0001-bootstrap-Change-libexec-dir.patch
2023-10-06 14:29:02 +02:00
0002-compiler-Change-LLVM-targets.patch
0004-compiler-Use-wasm-ld-for-wasm-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)
2022-12-17 12:40:44 +01:00
echo "Unpacking $(get_filename $file)";
bsdtar -p -o -C ${SRC} -xf $(get_filename $file) ;;
*.tar.xz)
echo "Copying $(get_filename $file)";
mkdir -p ${SRC}/${name}c-$version-src/build/cache/${_date} || true
cp $(get_filename $file) ${SRC}/${name}c-$version-src/build/cache/${_date} ;;
*)
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"
2022-05-21 12:20:18 +02:00
patch -p1 -i $SRC/0001-bootstrap-Change-libexec-dir.patch
2021-12-04 15:16:46 +01:00
# 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
2023-11-18 23:44:00 +01:00
patch -p1 -i $SRC/0004-compiler-Use-wasm-ld-for-wasm-targets.patch
2023-09-22 19:23:20 +02:00
2018-12-26 09:59:18 +01:00
cat <<- EOF > $SRC/config.toml
2024-02-10 11:20:10 +01:00
change-id = 118703
2021-09-25 15:59:34 +02:00
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
2023-02-10 15:07:53 +01:00
backtrace-on-ice = true
jemalloc = true
remap-debuginfo = false
description = "CRUX"
2018-12-26 09:59:18 +01:00
channel = "stable"
2023-02-10 15:07:53 +01:00
parallel-compiler = false
2018-12-26 09:59:18 +01:00
rpath = false
optimize = true
@LLD@
2018-12-26 09:59:18 +01:00
[build]
2023-06-01 22:48:10 +02:00
target = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"]
2023-07-14 18:18:07 +02:00
tools = ["cargo",
"clippy",
"rustfmt",
"analysis",
"src",
"rust-demangler",
"rust-analyzer",
"rust-analyzer-proc-macro-srv",
"rustdoc"]
2019-02-15 11:00:35 +01:00
docs = false
2018-12-26 09:59:18 +01:00
extended = true
2023-06-01 22:48:10 +02:00
sanitizers = true
2020-08-29 16:17:08 +02:00
profiler = true
vendor = true
2023-02-10 15:07:53 +01:00
locked-deps = true
2020-08-29 16:17:08 +02:00
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"
2023-10-06 14:29:02 +02:00
cc = @TARGETCC@
cxx = @TARGETCXX@
ar = @TARGETAR@
ranlib = @TARGETRANLIB@
2022-09-23 07:54:51 +02:00
[target.i686-unknown-linux-gnu]
2023-05-21 10:15:13 +02:00
llvm-config = "/usr/bin/llvm-config"
llvm-filecheck = "/usr/bin/FileCheck"
2023-10-06 14:29:02 +02:00
cc = @TARGETCC@
cxx = @TARGETCXX@
ar = @TARGETAR@
ranlib = @TARGETRANLIB@
2018-12-26 09:59:18 +01:00
EOF
2020-08-29 16:17:08 +02:00
if [ -e '/usr/bin/rustc' ]; then
2023-10-06 14:29:02 +02:00
if ! /usr/bin/ldd /usr/bin/rustc | grep -q -E '.*libLLVM.*.so => not found' && \
! /usr/bin/ldd /usr/bin/cargo | grep -q -E '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
2022-01-22 09:51:50 +01:00
PATH=$(echo ${PATH} | awk -v RS=: -v ORS=: '/ccache/ {next} {print}' | sed 's/:*$//')
2021-01-02 11:52:18 +01:00
else
sed -e 's|@CCACHE@||' -i $SRC/config.toml
fi
2023-10-06 14:29:02 +02:00
if prt-get isinst clang lld; then
sed -e 's|@TARGETCC@|"clang"|g' -e 's|@TARGETCXX@|"clang++"|g' -e 's|@TARGETAR@|"llvm-ar"|g' -e 's|@TARGETRANLIB@|"llvm-ranlib"|g' -i $SRC/config.toml
else
sed -e 's|@TARGETCC@|"gcc"|g' -e 's|@TARGETCXX@|"g++"|g' -e 's|@TARGETAR@|"gcc-ar"|g' -e 's|@TARGETRANLIB@|"gcc-ranlib"|g' -i $SRC/config.toml
fi
2023-09-20 17:51:44 +02:00
prt-get isinst lld && sed -e 's|@LLD@|use-lld = true\nlld = 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
2023-11-18 23:44:00 +01:00
## sccache currently leads to errors
#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`
export RUSTFLAGS+=' -A dead_code'
2021-12-05 04:05:24 +01:00
2023-09-22 19:23:20 +02:00
{ [ ! -e /usr/include/libssh2.h ] ||
export LIBSSH2_SYS_USE_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
2023-08-05 13:54:10 +02:00
prt-get isinst bash-completion || rm -r $PKG/etc/bash_completion.d/
2023-07-14 18:18:07 +02:00
prt-get isinst zsh || rm -r $PKG/usr/share/zsh
install -d $PKG/etc/revdep.d
echo "/usr/lib/rustlib/i686-unknown-linux-gnu/lib" > $PKG/etc/revdep.d/$name
# cleanup
2023-08-05 13:54:10 +02:00
rm -r $PKG/usr/share/doc
2018-12-26 09:59:18 +01:00
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)
2023-09-22 19:23:20 +02:00
find $PKG/usr -name "*.old" -delete
2023-07-14 18:18:07 +02:00
rm $PKG/usr/lib/rustlib/{install.log,manifest-*}
2018-12-26 09:59:18 +01:00
}