void-packages/srcpkgs/rust/template
2021-07-05 00:02:20 +02:00

379 lines
11 KiB
Bash

# Template file for 'rust'
# partially adapted from Alpine/Adélie's Rust APKBUILD
#
# Permission to use rust and cargo trademark is granted.
# See: https://github.com/rust-lang/core-team/issues/4
#
# Always make sure custom distfiles used for bootstrap are
# uploaded to https://alpha.de.repo.voidlinux.org/distfiles/
#
pkgname=rust
version=1.53.0
revision=1
_rust_dist_version=1.53.0
wrksrc="rustc-${version}-src"
hostmakedepends="cmake curl pkg-config python3 tar"
makedepends="libffi-devel ncurses-devel libxml2-devel zlib-devel llvm12"
depends="rust-std"
short_desc="Safe, concurrent, practical systems language"
maintainer="Enno Boland <gottox@voidlinux.org>"
license="MIT, Apache-2.0"
homepage="https://www.rust-lang.org/"
distfiles="https://static.rust-lang.org/dist/rustc-${version}-src.tar.gz"
checksum=5cf7ca39a10f6bf4e0b0bd15e3b9a61ce721f301e12d148262e5ba968ab825b9
lib32disabled=yes
build_options="bindist"
desc_option_bindist="Generate tarballs for bootstrap"
if [ "$XBPS_LIBC" = "musl" ]; then
hostmakedepends+=" libexecinfo-devel"
fi
if [ "$XBPS_TARGET_LIBC" = "musl" ]; then
makedepends+=" libexecinfo-devel"
fi
# rust upstream no longer ships cargo-versioned tarballs
# need to use the corresponding rust version instead
_bootstrap_url="https://static.rust-lang.org/dist"
_cargo_dist_version="${_rust_dist_version}"
# 32-bit gnu ppc needs custom bootstrap because of patches
case "$XBPS_MACHINE" in
x86_64*|i686|ppc64le) ;;
ppc*)
# custom bootstrap tarballs still use cargo versioning, so override
_bootstrap_url="https://alpha.de.repo.voidlinux.org/distfiles"
_cargo_dist_version="0.54.0"
;;
esac
# always use external binary cargo; this allows us to break
# the cargo<->rust cycle that appears when cross-compiling
distfiles+=" ${_bootstrap_url}/cargo-${_cargo_dist_version}-${RUST_BUILD}.tar.xz"
case "$XBPS_MACHINE" in
i686)
checksum+="
deebb4a4de22a60f0dec5d5b84e8dfe6ce039835935dae96477a79468aefd927"
;;
x86_64)
checksum+="
e4437f6c83574fc60e183f4df439190f7610e4a669476802795645da66fbb83b"
;;
x86_64-musl)
checksum+="
ca236408cb2c35b8c3f7c2b4e9f1e69422ed24153f445192eafb6462351e5c2b"
;;
ppc64le)
checksum+="
ca1d94161c3a4021bca170ba4ca059b5606fcd70934aca89d8cea43746880ba7"
;;
ppc64le-musl)
checksum+="
1181b721addeb2aa471bf71549a7fb09f27167c382b480cefba272f770b9f039"
;;
ppc64)
checksum+="
7d9b0428d4cd8cdd76582b3113476228013ec0b674802f18b4b5e8bbefcd3ab2"
;;
ppc64-musl)
checksum+="
695d687c19a729504ac8b57a42e395258a8b801753baf1b0b17755d7f38f7eaa"
;;
ppc)
checksum+="
176f178b9e55f399311edb4888d931e5f696766f655cc9648ae4b6ef1bdc8369"
;;
ppc-musl)
checksum+="
234cf0792407065f4c5c4276886846cee2ecfb37eea1171c2c6e4a0fba7d324c"
;;
*) broken="cargo bootstrap binary unavailable for ${XBPS_MACHINE}";;
esac
_bootstrap_dir="stage0-bootstrap"
# as for the rust compiler, just depend on self when crosscompiling...
# this is because if we do that, we can skip stage0 build and considerably
# cut down the build time (the local-rebuild property is enabled for cross)
if [ "$CROSS_BUILD" ]; then
hostmakedepends+=" rust llvm12"
# These are required for building the buildhost's stage0/1
hostmakedepends+=" libffi-devel libxml2-devel ncurses-devel zlib-devel"
else
distfiles+="
${_bootstrap_url}/rustc-${_rust_dist_version}-${RUST_BUILD}.tar.xz
${_bootstrap_url}/rust-std-${_rust_dist_version}-${RUST_BUILD}.tar.xz"
case "$XBPS_MACHINE" in
i686)
checksum+="
93b05456ea8500864e020cfbb1dfbe0a93651406432b6950013f87b91ea6ff47
d63690da8adb531bb92e76e211b37d3cf941fa841eaaaa210cce4cd6301ca64a"
;;
x86_64)
checksum+="
9c2f0443a546dd18f1f020c7711a7b9864432545ceb812e79315c1e76508b193
66d5257bbd194db08e67ca63a74cc80cdc4a36eaa30bf7dfe65861d9deaff7f7"
;;
x86_64-musl)
checksum+="
50de8b4bcb0819ec0ca363e0aa53fc1c55bc85f53bc82da8dce20a132da7e7d9
413449866616b1cd048da1356a41d977bf4e037cce114f07c3afbb0497b3e4c6"
;;
ppc64le)
checksum+="
7624a5bf09bcaddc90851928d604e78ad9896b041ad1124b064a716b7250b42b
d29a9c16a52f3a5767733597efdb9cc1e3cb390961b11cf1d1792b48939de5ed"
;;
ppc64le-musl)
checksum+="
09cd44fed6bf2d7ac0d180fc1374022deeb08be1d245ee26d1cfccc62658d22f
c283d604807f1c00e95a5122352941a64a26c3031ff41b80d395ac01ab55aa80"
;;
ppc64)
checksum+="
3136af38b2413524f02bbf1377c32c82f5f3791c5f78b926d7d74ef667349a69
a01e07e15e151f5c6fdd7f3f167fa96326ea8fffdce402a3dbb9687f33ae5ccc"
;;
ppc64-musl)
checksum+="
5dbcb8ca33874d7a82543b4f9d9f1c51e5680a998b0b572119e8be6b8ae4f566
5f03e215507313d14fc5275ba6951d3d7590634909def352504f52ad57c24dc3"
;;
ppc)
checksum+="
be6ca5e02c04329b082eaf717ba2ea370d676a93e520cd5988883ea2ed8cb750
6006f7f78e30810e8b929ab5ab97cf5e4488a25f7fe6a49a1a548dd4745281e0"
;;
ppc-musl)
checksum+="
6ecf74e3718bfc03a09ece82a246c9fe268bbb9a7d96cb7d65b579a824e5e1d9
17d14e51263e253ba082fc0b05f887dad7d16c705304514aa3268904ac472d29"
;;
*) broken="rust bootstrap binaries unavailable for ${XBPS_MACHINE}";;
esac
fi
post_extract() {
mkdir -p "${wrksrc}/${_bootstrap_dir}/bin"
if [ -z "$CROSS_BUILD" ]; then
../rust-std-${_rust_dist_version}-${RUST_BUILD}/install.sh \
--destdir="${wrksrc}/${_bootstrap_dir}" --prefix=/ --disable-ldconfig
../rustc-${_rust_dist_version}-${RUST_BUILD}/install.sh \
--destdir="${wrksrc}/${_bootstrap_dir}" --prefix=/ --disable-ldconfig
fi
# cargo may not be packaged like the rest
cp ../cargo-${_cargo_dist_version}-${RUST_BUILD}/cargo/bin/cargo \
"${wrksrc}/${_bootstrap_dir}/bin"
}
# we need this because cargo verifies checksums of all files in vendor
# crates when it builds and gives us no way to override or update the
# file sanely... so just clear out the file list
_clear_vendor_checksums() {
sed -i 's/\("files":{\)[^}]*/\1/' vendor/$1/.cargo-checksum.json
}
post_patch() {
rm -rf src/llvm-project
if [ "$build_option_bindist" ]; then
for x in ${FILESDIR}/patches/static-llvm/*.patch; do
msg_normal "Applying patch $x\n"
patch -sNp1 -i ${x}
done
fi
# clear out all the checksum nonsense of patched vendor crates
_clear_vendor_checksums libc
_clear_vendor_checksums typenum
_clear_vendor_checksums cc-1.0.60
_clear_vendor_checksums gcc
_clear_vendor_checksums cc
_clear_vendor_checksums jemallocator
_clear_vendor_checksums rustc-ap-rustc_target
_clear_vendor_checksums target-lexicon
_clear_vendor_checksums tikv-jemallocator
}
do_configure() {
local _cargo_root _rust_root _local_rebuild _use_debug _use_debug_rustc _use_rpath _use_docs
if [ "$CROSS_BUILD" ]; then
_rust_root="/usr"
_local_rebuild="true"
else
_rust_root="${wrksrc}/${_bootstrap_dir}"
_local_rebuild="false"
fi
_cargo_root="${wrksrc}/${_bootstrap_dir}"
# disable rustc debug info as it bloats up rust-std significantly
# set to 1 or 2 if you wish to have debug info for rustc, it won't
# link on 32-bit platforms though (too big)
_use_debug_rustc="0"
# use stdlib debug level 2 for all platforms when generating debug
if [ -n "$XBPS_DEBUG_PKGS" ]; then
_use_debug="2"
else
_use_debug="0"
fi
# if true, the binaries will be built with rpath, so the binaries will be
# usable directly from the build directory, this is not desirable for
# packaging but is useful when building bootstrap binaries
if [ "$build_option_bindist" ]; then
_use_rpath="true"
_use_docs="false"
else
_use_rpath="false"
_use_docs="true"
fi
cat > config.toml <<- EOF
[build]
build = "${RUST_BUILD}"
host = [ "${RUST_TARGET}" ]
target = [ "${RUST_TARGET}" ]
cargo = "${_cargo_root}/bin/cargo"
rustc = "${_rust_root}/bin/rustc"
submodules = false
python = "python3"
locked-deps = true
vendor = true
full-bootstrap = false
local-rebuild = ${_local_rebuild}
extended = false
docs = ${_use_docs}
tools = []
[install]
prefix = "/usr"
[rust]
codegen-units = 1
codegen-units-std = 1
debug-assertions = false
debuginfo-level = ${_use_debug}
debuginfo-level-rustc = ${_use_debug_rustc}
debuginfo-level-tests = 0
backtrace = true
incremental = false
parallel-compiler = false
channel = "stable"
rpath = ${_use_rpath}
verbose-tests = true
dist-src = false
jemalloc = false
llvm-libunwind = "no"
codegen-tests = false
[dist]
src-tarball = false
[target.${RUST_BUILD}]
llvm-config = "/usr/bin/llvm-config"
crt-static = false
cc = "${CC_host:-$CC}"
cxx = "${CXX_host:-$CXX}"
ar = "${AR_host:-$AR}"
linker = "${CC_host:-$CC}"
EOF
if [ "$CROSS_BUILD" ]; then
cat >> config.toml <<- EOF
[target.${RUST_TARGET}]
llvm-config = "/usr/bin/llvm-config"
crt-static = false
cc = "${CC}"
cxx = "${CXX}"
ar = "${AR}"
linker = "${CC}"
EOF
fi
}
# Set the correct CFLAGS for the build host, we have to compile libbacktrace
# for it during stage1. Otherwise it attemps to use CFLAGS, which are the CFLAGS
# of the cross host.
do_build() {
if [ ! "$build_option_bindist" ]; then
export LLVM_LINK_SHARED=1
fi
export RUST_BACKTRACE=1
export CARGO_HOME="$wrksrc/.cargo"
export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
# prevent sysroot from leaking in
export RUSTFLAGS=""
env CFLAGS_${RUST_BUILD}="${CFLAGS_host}" \
python3 x.py dist --jobs $XBPS_MAKEJOBS
}
do_check() {
export RUST_BACKTRACE=1
python3 x.py test ${makejobs} --no-doc --no-fail-fast \
src/test/codegen \
src/test/codegen-units \
src/test/incremental \
src/test/mir-opt \
src/test/pretty \
src/test/run-make \
src/test/run-make-fulldeps \
src/test/ui \
src/test/ui-fulldeps
}
do_install() {
if [ "$build_option_bindist" ]; then
mkdir -p ${XBPS_SRCDISTDIR}/distfiles
install -m 0644 \
build/dist/rustc-${version}-${RUST_TARGET}.tar.xz \
build/dist/rust-std-${version}-${RUST_TARGET}.tar.xz \
${XBPS_SRCDISTDIR}/distfiles
exit 1
fi
vmkdir usr
tar xf build/dist/rustc-${version}-${RUST_TARGET}.tar.gz \
-C "$DESTDIR/usr" --strip-components=2 --exclude=manifest.in
tar xf build/dist/rust-std-${version}-${RUST_TARGET}.tar.gz \
-C "$DESTDIR/usr/lib" --strip-components=3 --exclude=manifest.in
tar xf build/dist/rustc-dev-${version}-${RUST_TARGET}.tar.gz \
-C "$DESTDIR/usr/lib" --strip-components=3 --exclude=manifest.in
tar xf build/dist/rust-docs-${version}-${RUST_TARGET}.tar.gz \
-C "$DESTDIR/usr" --strip-components=2 --exclude=manifest.in
vlicense COPYRIGHT
vlicense LICENSE-APACHE
vlicense LICENSE-MIT
cd ${DESTDIR}/usr/lib
# symlinks instead of copies
mv *.so rustlib/${RUST_TARGET}/lib
ln -sf rustlib/${RUST_TARGET}/lib/*.so .
# executable used for split dwarf, currently unstable on linux.
# it's copied directly from the local llvm package, but
# FIXME: cross builds are installing the version from the build machine,
# it shouldn't be necessary to remove it
rm rustlib/${RUST_TARGET}/bin/rust-llvm-dwp
}
rust-doc_package() {
short_desc+=" - documentation"
pkg_install() {
vmove usr/share/doc
}
}
rust-std_package() {
short_desc+=" - standard library"
if [ "$XBPS_TARGET_LIBC" = "musl" ]; then
depends="libexecinfo-devel"
fi
pkg_install() {
vmove usr/lib/rustlib
}
}