1
0
Fork 0
mirror of https://gitlab.alpinelinux.org/alpine/aports.git synced 2025-07-21 10:15:12 +03:00
aports/community/rust/APKBUILD
psykose dab4d2320f community/rust: merge -stdlib
there's no point to split this because it's useless without the main
compiler

the only thing that this is maybe useful for is clippy, but the majority
of the download size is in the stdlib
2023-03-09 19:00:34 +01:00

413 lines
14 KiB
Text

# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Contributor: Shiz <hi@shiz.me>
# Contributor: Jeizsm <jeizsm@gmail.com>
# Contributor: Ariadne Conill <ariadne@dereferenced.org>
# Maintainer: psykose <alice@ayaya.dev>
pkgname=rust
pkgver=1.68.0
_llvmver=15
_bootver=1.67.0
pkgrel=0
pkgdesc="The Rust Programming Language"
url="https://www.rust-lang.org/"
arch="all"
license="Apache-2.0 AND MIT"
# 'cc' is needed at runtime just for linking. Someday rustc might invoke
# the linker directly, and then we'll only need 'ld'.
# See: https://github.com/rust-lang/rust/issues/11937
depends="gcc musl-dev"
# * Rust is self-hosted, so you need rustc (and cargo) to build rustc...
# The last revision of this abuild that does not depend on itself (uses
# prebuilt rustc and cargo) is 2e6769eb39eaff3029d8298fc02856623c563cd8.
# * Don't add libgit2-dev into make dependencies. There's no compatibility
# guarantees between libgit2-sys and arbitrary system libgit2 versions;
# when system libgit2 is upgraded to a new minor version, it may break
# cargo and since we need cargo to rebuild cargo... this already happened
# several times. For this reason we build cargo with vendored libgit2.
makedepends_build="
!libgit2-dev
cargo-bootstrap=>$_bootver
coreutils
curl-dev
file
libssh2-dev
llvm$_llvmver-dev
llvm$_llvmver-test-utils
openssl-dev>3
python3
rust-bootstrap=>$_bootver
tar
wasi-libc
xz-dev
zlib-dev
"
makedepends_host="
curl-dev
libssh2-dev
llvm$_llvmver-dev
openssl-dev>3
zlib-dev
"
# XXX: This is a hack to allow this abuild to depend on itself. Adding "rust"
# to makedepends would not work, because abuild implicitly removes $pkgname
# and $subpackages from the abuild's dependencies.
provides="rust-bootstrap=$pkgver-r$pkgrel"
# This is needed for -src that contains some testing binaries.
options="!archcheck"
case "$CARCH" in
armhf|armv7|riscv64)
# +crt-static still broken here.
options="$options !check"
;;
*)
;;
esac
subpackages="
$pkgname-dbg
$pkgname-wasm
$pkgname-analysis
$pkgname-gdb::noarch
$pkgname-lldb::noarch
$pkgname-clippy
$pkgname-doc
$pkgname-src::noarch
cargo
cargo-bash-completions:_cargo_bashcomp:noarch
cargo-zsh-completion:_cargo_zshcomp:noarch
cargo-doc:_cargo_doc:noarch
rustfmt
"
source="https://static.rust-lang.org/dist/rustc-$pkgver-src.tar.xz
alpine-move-py-scripts-to-share.patch
alpine-target.patch
do-not-install-libunwind-source.patch
gcc-eh-libunwind.patch
install-template-shebang.patch
musl-fix-linux_musl_base.patch
need-rpath.patch
need-ssp_nonshared.patch
no-export-ld-library-path.patch
system-wasm-ld.patch
check-rustc
"
builddir="$srcdir/rustc-$pkgver-src"
# secfixes:
# 1.66.1-r0:
# - CVE-2022-46176
# 1.56.1-r0:
# - CVE-2021-42574
# 1.52.1-r1:
# - CVE-2021-29922
# 1.51.0-r2:
# - CVE-2020-36323
# - CVE-2021-31162
# 1.34.2-r0:
# - CVE-2019-12083
# 1.26.0-r0:
# - CVE-2019-16760
# We have to add new arches in multiple steps:
# 1. Compile with the upstream triplets, compiling alpine's triplets in
# 2. Compile again, now with our triplets selected as build/target, now that
# rustc knows about them
_build="$CBUILD"
_target="$CTARGET"
_rlibdir="usr/lib/rustlib/$_target/lib"
_sharedir="usr/share/rust"
ldpath="/$_rlibdir"
export OPENSSL_NO_VENDOR=1
export RUST_BACKTRACE=1
# rust checksums files in vendor/, but we have to patch a few files...
_clear_vendor_checksums() {
sed -i 's/\("files":{\)[^}]*/\1/' vendor/$1/.cargo-checksum.json
}
build() {
if [ "$_build" != "$_target" ]; then
export PKG_CONFIG_ALLOW_CROSS=1
fi
# absolutely do not set these here, rust "knows" what it's doing
unset CARGO_PROFILE_RELEASE_LTO
unset CARGO_PROFILE_RELEASE_OPT_LEVEL
unset CARGO_PROFILE_RELEASE_PANIC
unset CARGO_PROFILE_RELEASE_CODEGEN_UNITS
export CFLAGS="$CFLAGS -O2"
export CXXFLAGS="$CXXFLAGS -O2"
# todo: try enable lto:
# --set="rust.lto=thin"
# this fails when using the stage2 compiler with:
# thread 'main' panicked at 'range start index 1 out of range for slice of length 0', compiler/rustc_driver/src/lib.rs:988:17
# on a rustc -vV invocation. the slice is
# pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
# // Throw away the first argument, the name of the binary
# let args = &args[1..];
# which should not be null with -vV?
./configure \
--build="$_build" \
--host="$_target" \
--target="$_target,wasm32-wasi,wasm32-unknown-unknown" \
--prefix="/usr" \
--release-channel="stable" \
--enable-local-rust \
--local-rust-root="/usr" \
--llvm-root="/usr/lib/llvm$_llvmver" \
--disable-docs \
--enable-extended \
--tools="analysis,cargo,clippy,src,rustfmt" \
--enable-llvm-link-shared \
--enable-option-checking \
--enable-locked-deps \
--enable-profiler \
--enable-vendor \
--dist-compression-formats=gz \
--python="python3" \
--set="rust.musl-root=/usr" \
--set="rust.codegen-units=1" \
--set="rust.codegen-units-std=1" \
--set="rust.parallel-compiler=false" \
--set="rust.description=Alpine Linux" \
--set="target.$_target.llvm-config=/usr/lib/llvm$_llvmver/bin/llvm-config" \
--set="target.$_target.musl-root=/usr" \
--set="target.$_target.crt-static=false" \
--set="target.$_target.cc=${CROSS_COMPILE}cc" \
--set="target.$_target.cxx=${CROSS_COMPILE}c++" \
--set="target.$_target.ar=${CROSS_COMPILE}ar" \
--set="target.$_target.linker=${CROSS_COMPILE}cc" \
--set="target.$_build.musl-root=/usr" \
--set="target.$_build.crt-static=false" \
--set="target.$_build.cc=cc" \
--set="target.$_build.cxx=c++" \
--set="target.$_build.ar=ar" \
--set="target.$_build.linker=cc" \
--set="target.wasm32-unknown-unknown.sanitizers=false" \
--set="target.wasm32-unknown-unknown.profiler=false" \
--set="target.wasm32-unknown-unknown.linker=lld" \
--set="target.wasm32-wasi.sanitizers=false" \
--set="target.wasm32-wasi.profiler=false" \
--set="target.wasm32-wasi.wasi-root=/usr/share/wasi-sysroot"
# Allow warnings instead of just aborting the build
sed 's/#deny-warnings = .*/deny-warnings = false/' -i config.toml
sed 's|deny(warnings,|deny(|' -i src/bootstrap/lib.rs
python3 ./x.py dist --jobs ${JOBS:-2}
}
check() {
# At this moment lib/rustlib/$CTARGET/lib does not contain a complete
# copy of the .so libs from lib (they will be copied there during
# 'x.py install'). Thus we must set LD_LIBRARY_PATH for tests to work.
# This is related to change-rpath-to-rustlib.patch.
msg "Setting up test env..."
mkdir -p "$builddir/test-rustc"
tar xf "$builddir"/build/dist/rustc-$pkgver-$_target.tar.gz \
-C "$builddir/test-rustc" --strip-components=2 --exclude=manifest.in --no-same-owner
tar xf "$builddir"/build/dist/rust-std-$pkgver-$_target.tar.gz \
-C "$builddir/test-rustc" --strip-components=2 --exclude=manifest.in --no-same-owner
export LD_LIBRARY_PATH="$builddir/test-rustc/lib/rustlib/$CTARGET/lib"
msg "Sanity checks..."
"$srcdir"/check-rustc "$builddir"/test-rustc/bin/rustc
# XXX: There's some problem with these tests, we will figure it out later.
# make check \
# LD_LIBRARY_PATH="$_stage0dir/lib" \
# VERBOSE=1
# these rebuild the whole compiler which takes a long time
# msg "Running tests for cargo..."
# CFG_DISABLE_CROSS_TESTS=1 python3 ./x.py test --no-fail-fast src/tools/cargo
unset LD_LIBRARY_PATH
}
package() {
# merged into main package
provides="rust-stdlib=$pkgver-r$pkgrel"
replaces="rust-stdlib"
mkdir -p "$pkgdir/usr"
cd "$pkgdir"
tar xf "$builddir"/build/dist/rustc-$pkgver-$_target.tar.gz \
-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner
tar xf "$builddir"/build/dist/rust-std-$pkgver-$_target.tar.gz \
-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner
tar xf "$builddir"/build/dist/rustc-dev-$pkgver-$_target.tar.gz \
-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner
tar xf "$builddir"/build/dist/rust-analysis-$pkgver-$_target.tar.gz \
-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner
tar xf "$builddir"/build/dist/rust-src-$pkgver.tar.gz \
-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner
tar xf "$builddir"/build/dist/cargo-$pkgver-$_target.tar.gz \
-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner
tar xf "$builddir"/build/dist/clippy-$pkgver-$_target.tar.gz \
-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner
tar xf "$builddir"/build/dist/rustfmt-$pkgver-$_target.tar.gz \
-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner
tar xf "$builddir"/build/dist/rust-std-$pkgver-wasm32-unknown-unknown.tar.gz \
-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner
tar xf "$builddir"/build/dist/rust-std-$pkgver-wasm32-wasi.tar.gz \
-C "$pkgdir/usr" --strip-components=2 --exclude=manifest.in --no-same-owner
# We don't want to include stuff like rust-llvm-* tools, as we will use the
# system tools.
rm -f usr/lib/rustlib/"$_target"/bin/rust-llvm-*
# Python scripts are noarch, so move them to /usr/share.
# Requires move-py-scripts-to-share.patch to be applied.
_mv usr/lib/rustlib/etc/*.py $_sharedir/etc/
rmdir -p usr/lib/rustlib/etc 2>/dev/null || true
_mv usr/etc/bash_completion.d/cargo usr/share/bash-completion/completions/
rmdir -p usr/etc/bash_completion.d 2>/dev/null || true
_mv usr/lib/rustlib/src/rust usr/src/
ln -s ../../../src/rust usr/lib/rustlib/src/rust
# Remove some clutter.
cd "$pkgdir"/usr/lib/rustlib
rm -f components install.log manifest-* rust-installer-version uninstall.sh
if [ "$_build" != "$_target" ]; then
rm -rf "$pkgdir"/usr/lib/rustlib/$_build
fi
# for some reason the tar archive gets some root-only files for rlibs
find "$pkgdir"/usr/lib/rustlib -type f -perm -600 -exec chmod 644 {} \;
find "$pkgdir"/usr/lib/rustlib -type f -perm -700 -exec chmod 755 {} \;
}
wasm() {
pkgdesc="WebAssembly targets for rust"
depends="rust=$pkgver-r$pkgrel lld wasi-sdk"
amove usr/lib/rustlib/wasm32-*
}
analysis() {
pkgdesc="Compiler analysis data for the Rust standard library"
depends="$pkgname=$pkgver-r$pkgrel"
amove $_rlibdir/../analysis
}
gdb() {
pkgdesc="GDB pretty printers for Rust"
depends="$pkgname=$pkgver-r$pkgrel gdb"
amove usr/bin/rust-gdb*
amove $_sharedir/etc/gdb_*.py
}
lldb() {
pkgdesc="LLDB pretty printers for Rust"
depends="$pkgname=$pkgver-r$pkgrel lldb py3-lldb"
amove usr/bin/rust-lldb
amove $_sharedir/etc/lldb_*.py
}
clippy() {
pkgdesc="Lints to catch common mistakes and improve your Rust code"
depends="$pkgname=$pkgver-r$pkgrel"
amove usr/bin/cargo-clippy
amove usr/bin/clippy-driver
}
src() {
pkgdesc="$pkgdesc (source code)"
depends="$pkgname=$pkgver-r$pkgrel"
license="$license OFL-1.1 GPL-3.0-or-later GPL-3.0-with-GCC-exception CC-BY-SA-3.0 LGPL-3.0"
amove usr/src
amove usr/lib/rustlib/src
}
cargo() {
pkgdesc="The Rust package manager"
license="Apache-2.0 MIT UNLICENSE"
depends="$pkgname=$pkgver-r$pkgrel"
# XXX: See comment on top-level provides=.
provides="cargo-bootstrap=$pkgver-r$pkgrel"
amove usr/bin/cargo
amove usr/libexec/cargo-credential-1password
}
rustfmt() {
pkgdesc="Rust Code Formatter"
license="Apache-2.0"
depends="cargo=$pkgver-r$pkgrel"
amove usr/bin/rustfmt
amove usr/bin/cargo-fmt
}
_cargo_bashcomp() {
pkgdesc="Bash completions for cargo"
license="Apache-2.0 MIT"
depends=""
install_if="cargo=$pkgver-r$pkgrel bash-completion"
amove usr/share/bash-completion
}
_cargo_zshcomp() {
pkgdesc="ZSH completions for cargo"
license="Apache-2.0 MIT"
depends=""
install_if="cargo=$pkgver-r$pkgrel zsh"
amove usr/share/zsh/site-functions/_cargo
}
_cargo_doc() {
pkgdesc="The Rust package manager (documentation)"
license="Apache-2.0 MIT"
install_if="docs cargo=$pkgver-r$pkgrel"
# XXX: This is hackish!
cd "$pkgdir"/../$pkgname-doc
_mv usr/share/man/man1/cargo* "$subpkgdir"/usr/share/man/man1/
}
_mv() {
local dest; for dest; do true; done # get last argument
mkdir -p "$dest"
mv "$@"
}
sha512sums="
f6cc5c06488080f2d7ce8c4f5adf7ca8ae8b10caea627b57876b051593af1201a48823d0abf5fcbcd344b46606b53957569db9844d647a5fdc4abca06e260f3a rustc-1.68.0-src.tar.xz
03a179e31c95f88a98fb1ba6b2fd0baaf9fe1a74ade76d3096fe45ddc5e453c25109355e667783d9be1bcc585445d07b7270cb3e6e403de971049714f2c6f91a alpine-move-py-scripts-to-share.patch
f87b12c6c3ccf8abc3a21d40631ed753efe313c601c5fdd5200cea16aa65878621700b6ca6b22c4f2334a8540dc7d23ef0ff9087fc65177433d56a700e56bb8c alpine-target.patch
7af23c34096f7a03c5a1b40aa07e00dd6193743c872881018a9baa900f240c6e44918e481ab5ed7787a70ef361e4aeec2a7719bcd695f52988262e23271b44e5 do-not-install-libunwind-source.patch
92916225c21742941aaf415d75d330fe2baf77a8226c076e862f4413068d5dee7b08c4b3182f69957ea9a51a0dcde145031565289015b6e3c31894fb396e4eb1 gcc-eh-libunwind.patch
7d59258d4462eba0207739a5c0c8baf1f19d9a396e5547bb4d59d700eb94d50ba6add2e523f3e94e29e993821018594625ea4ac86304fb58f7f8c82622a26ab0 install-template-shebang.patch
416ac00f70645ca3afc6eb40b3c06ac4e6c13bf8d04109616c8170093aab3c1ddb19ace5252a37895f81d4bc6669918804dfd84eb0c5fa07c9e810dbffe39354 musl-fix-linux_musl_base.patch
2d401a01d2c2db92624d672018342907a41aa4a3842708c0a2ab694af0396d568aca4835d1075f244d77c0a4c45e67f893fd175fd97cd7f758090eba9972eba6 need-rpath.patch
b722bc2787748e208abdc50a496d6b155b2d786bb28cbd5726535534e322a87c191db161d94e06154e126eaf81ca3634f10b364b7212f0f3154e5cca859980bd need-ssp_nonshared.patch
cbdb38a2701e079d362e76ff16a2549230f80bcb4dfd3561d240df331fb21d202cb720e18b97fe9b166db1f79b46fab949ce5de5e37af2ed78a10c7fe1dfcfc9 no-export-ld-library-path.patch
4ea59b28fa238b8bb0cb24847e5884b65beec5168e55fe41a1ff50e272f1cf49186ffaa71d133cebfdcb70901ea18b477d7618a1dd330ff6c08bed5af0e2bb78 system-wasm-ld.patch
c31fdfe8a9b3411576c75da46645cf0465b9053000a2ab49cf9b2f2733f679d6d33acbf236d67a20e14935d094a685453b7f1840180249f39d610fd0902c3125 check-rustc
"