void-packages/srcpkgs/rust/template
Johannes aed83545f2 Revert "rust: nocross for now"
This reverts commit f2b49f910d.
2020-06-20 19:18:41 +02:00

312 lines
9.2 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
pkgname=rust
version=1.44.1
revision=1
_rust_dist_version=1.43.1
_cargo_dist_version=0.44.0
# Always make sure custom distfiles used for bootstrap are
# uploaded to https://alpha.de.repo.voidlinux.org/distfiles/
wrksrc="rustc-${version}-src"
hostmakedepends="cmake curl pkg-config python3 tar"
makedepends="libffi-devel ncurses-devel libxml2-devel zlib-devel llvm10"
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="7e2e64cb298dd5d5aea52eafe943ba0458fa82f2987fdcda1ff6f537b6f88473"
lib32disabled=yes
patch_args="-Np1"
build_options="bindist"
desc_option_bindist="Generate tarballs for bootstrap"
_bootstrap_dir="stage0-bootstrap"
if [ "$CROSS_BUILD" ]; then
hostmakedepends+=" cargo llvm10"
# These are required for building the buildhost's stage0/1
hostmakedepends+=" libffi-devel libxml2-devel ncurses-devel zlib-devel"
else
_bootstrap_url="https://static.rust-lang.org/dist"
# 32-bit ppc needs custom bootstrap for now because of patches
case "$XBPS_MACHINE" in
x86_64*|i686|ppc64le) ;;
ppc*) _bootstrap_url="https://alpha.de.repo.voidlinux.org/distfiles" ;;
*) broken="unsupported host: ${XBPS_MACHINE}" ;;
esac
distfiles+="
${_bootstrap_url}/rustc-${_rust_dist_version}-${RUST_BUILD}.tar.xz
${_bootstrap_url}/rust-std-${_rust_dist_version}-${RUST_BUILD}.tar.xz
${_bootstrap_url}/cargo-${_cargo_dist_version}-${RUST_BUILD}.tar.xz"
# checksums must be specified per arch
case "$XBPS_MACHINE" in
i686)
checksum+="
b415a406443cafa85e426d56d02fb52231b8d78ad1fec33b79b757d8ef4ed64c
9913d3e21efc13445e3b71f6e1103c63b130544e1f28a99a0bb642276ebca985
c7b4045b2001be2e97b0b08dfaee02097aea0e8a9983b42585d733cfa1e69683"
;;
x86_64)
checksum+="
a18b89572ff2e55eb9e0428efcdb60eacd82fe28c4d825d169b0ffc9e3c55ceb
dabc62db53c2e7ffeba2824d4c52a938486b04c01a93ecba00c5d529868f6cfc
84ba23058542691dae8157beec6a7679a420643eb6a708134bb1dfb01cbdebea"
;;
x86_64-musl)
checksum+="
be982dc01b5c86a3f2b0b99a2ca0e13b3cea698ee6f1db9fa024de5c8b35a75d
f3b55147ff6e01448699eaf0875d7956ea38eeef42a19cda9d555e814470e823
653cb60214d6f1000c9a7775111dccd093c0118e7f7bf5f2f1f53a7e5e2420b3"
;;
ppc64le)
checksum+="
8fd21a9eac7e27a5f7af9d9357455d1ff5aef01d84b4025a773caaae6e0a6db7
235bdaf836a0bd139257d6cc0566e0c3d4d1e07c04304ed9a8d200299aaa4a48
4f90cd6cbcf9e9d6ba11830e093092e4e6c3d156ffde2e729933869b7a039ff9"
;;
ppc64le-musl)
checksum+="
2c32096c0f1b3a756cc29d6ecaf89296148a7a99d43baa0141bee490b353b502
fa87695bdede026b031010716fafbe2890cbff00acc3042fd372dd7cc5eb46a7
a85e8c9714a8bb7c17cd23993c677f51d9e0d6f5e85ab10f53ec1639b19bbbd4"
;;
ppc64)
checksum+="
4aa250cd14553ae3a438cd7a7290a79b899d1fbec9fc60985bbce070b500883e
2cd6e88be42db44338c18fa6e3170ffea679ee73825826112cdbf6dd9ed0619a
983e2fbec9c4bfe66bab37ad64cdd5b47918378e421d9bf639e938f120650199"
;;
ppc64-musl)
checksum+="
f3c4fb775e63248914fece31199312dd2f69660f10b696ebbc56d41d4bc4ac2c
c3d580c71e5a716056347513588d4445bdb8225e2ee5d9f2cf87c5bb4357bcb1
f974893d1cac6c799345bece08c7f796eb50e1a77c4b9bc2a6451d161a57c660"
;;
ppc)
checksum+="
109d6af5d05cfbde5a476d07cf8b3093a974b0c76922bf8cd1046c5e11f5caaa
a90152808c82f863f3c14647ebfbb6ae66d065ea4577be1036f6dc229c1e7e89
48f4419300fe758ebe024e6449a5ca1dff07803047a815b3d3909170baa7adcc"
;;
ppc-musl)
checksum+="
3d5211d6c5cf241b3d3dba343c027d05ff04765e2dd4175168095a86e7c9de22
04a5cdb4f18ccae3eb9059c84adf7a7778484e89c8404ba67cde814019ec5b57
bbb93a757e75d09cb5f6d6dd837e32212acd8888426406352eccf52f329386f1"
;;
esac
fi
post_extract() {
if [ -z "$CROSS_BUILD" ]; then
mkdir -p "${wrksrc}/${_bootstrap_dir}"
../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
# cargo may not be packaged like the rest
cp ../cargo-${_cargo_dist_version}-${RUST_BUILD}/cargo/bin/cargo \
"${wrksrc}/${_bootstrap_dir}/bin"
fi
}
# 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 backtrace-sys
_clear_vendor_checksums lzma-sys
}
do_configure() {
local _rust_root _local_rebuild _use_debug _use_debug_rustc _use_rpath
if [ "$CROSS_BUILD" ]; then
_rust_root="/usr"
_local_rebuild="true"
else
_rust_root="${wrksrc}/${_bootstrap_dir}"
_local_rebuild="false"
fi
# 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"
else
_use_rpath="false"
fi
cat > config.toml <<- EOF
[build]
build = "${RUST_BUILD}"
host = [ "${RUST_TARGET}" ]
target = [ "${RUST_TARGET}" ]
cargo = "${_rust_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 = false
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 = false
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/compile-fail \
src/test/incremental \
src/test/mir-opt \
src/test/pretty \
src/test/run-fail \
src/test/run-fail/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
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 .
}
rust-doc_package() {
short_desc+=" - documentation"
archs=noarch
pkg_install() {
vmove usr/share/doc
}
}
rust-std_package() {
short_desc+=" - standard library"
pkg_install() {
vmove usr/lib/rustlib
}
}