rust: use rustbuild, enable musl support.

Closes #4570.
This commit is contained in:
Christian Neukirchen 2016-08-06 22:41:08 +02:00
parent 1a7ee04e0a
commit 0ba40e8bc2
6 changed files with 241 additions and 9 deletions

View file

@ -0,0 +1,21 @@
https://github.com/rust-lang/cargo/issues/2937
--- a/src/cargo/util/flock.rs
+++ b/src/cargo/util/flock.rs
@@ -282,7 +282,7 @@
human(format!("failed to lock file: {}", path.display()))
});
- #[cfg(target_os = "linux")]
+ #[cfg(all(target_os = "linux", not(target_env = "musl")))]
fn is_on_nfs_mount(path: &Path) -> bool {
use std::ffi::CString;
use std::mem;
@@ -302,7 +302,7 @@
}
}
- #[cfg(not(target_os = "linux"))]
+ #[cfg(any(not(target_os = "linux"), target_env = "musl"))]
fn is_on_nfs_mount(_path: &Path) -> bool {
false
}

View file

@ -3,6 +3,7 @@ pkgname=cargo
version=0.11.0
revision=2
_githash_installer=c37d3747da75c280237dc2d6b925078e69555499
patch_args="-Np1"
build_style=gnu-configure
make_build_args="VERBOSE=1"
hostmakedepends="rust python curl cmake pkg-config"
@ -18,15 +19,33 @@ checksum="4f390d7ea3352a1ecafb53d1a2b98c2e195b81a5c652342a8b91672d9f1dde0a
6326434c225d25c6bfd28ff8bbc3108e331ae65e89a5c38dac8a2c8ffa09732b"
nocross=yes
case "$XBPS_MACHINE" in
x86_64-musl)
distfiles+="
https://alpine.geeknet.cz/distfiles/cargo-0.11.0-nightly-x86_64-alpine-linux-musl.tar.gz"
checksum+="
587172026c0565e839d96b0c1d4c68c000927817398241f96682dca47fa8c3b9"
;;
x86_64)
distfiles+="
https://static.rust-lang.org/cargo-dist/2016-04-10/cargo-nightly-x86_64-unknown-linux-gnu.tar.gz"
checksum+="
721a2bfb1f2ffff09b59911ba686a3a55eac6a2df88f19168be0a7c8a1fdffca"
;;
esac
post_extract() {
rm -rf src/rust-installer
mv ../rust-installer-${_githash_installer} src/rust-installer
sed -i 's,/etc/bash_completion.d,/share/bash-completion/completions,g' Makefile.in
mkdir -p target/snapshot
mv ../cargo-nightly*/cargo/* target/snapshot
}
pre_configure() {
configure_args+=" --host=${XBPS_TRIPLET/-pc-/-unknown-} --build=${XBPS_TRIPLET/-pc-/-unknown-}"
sed -i '/not recognized/s/err/warn/' configure
export LIBGIT2_SYS_USE_PKG_CONFIG=yes
export CARGO_HOME="${wrksrc}/.cargo"
}
post_install() {
rm -rf ${DESTDIR}/usr/lib/rustlib ${DESTDIR}/usr/share/doc/cargo

View file

@ -0,0 +1,19 @@
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Thu, 04 Aug 2016 17:53:00 +0200
Subject: [PATCH] Do not require FileCheck
--- a/src/bootstrap/build/sanity.rs
+++ b/src/bootstrap/build/sanity.rs
@@ -76,12 +76,6 @@
need_cmd(build.cxx(host).as_ref());
}
- // Externally configured LLVM requires FileCheck to exist
- let filecheck = build.llvm_filecheck(&build.config.build);
- if !filecheck.starts_with(&build.out) && !filecheck.exists() {
- panic!("filecheck executable {:?} does not exist", filecheck);
- }
-
for target in build.config.target.iter() {
// Either can't build or don't want to run jemalloc on these targets
if target.contains("rumprun") ||

View file

@ -0,0 +1,76 @@
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Thu, 04 Aug 2016 17:53:00 +0200
Subject: [PATCH] Do not link musl statically
Static linking of rustc on Alpine doesn't work yet.
This patch is ported from
https://gist.github.com/japaric/52b8816a4c86f5a4699bcc50ebc3e020.
--- a/src/bootstrap/build/sanity.rs
+++ b/src/bootstrap/build/sanity.rs
@@ -97,26 +91,6 @@
panic!("the iOS target is only supported on OSX");
}
- // Make sure musl-root is valid if specified
- if target.contains("musl") && (target.contains("x86_64") || target.contains("i686")) {
- match build.config.musl_root {
- Some(ref root) => {
- if fs::metadata(root.join("lib/libc.a")).is_err() {
- panic!("couldn't find libc.a in musl dir: {}",
- root.join("lib").display());
- }
- if fs::metadata(root.join("lib/libunwind.a")).is_err() {
- panic!("couldn't find libunwind.a in musl dir: {}",
- root.join("lib").display());
- }
- }
- None => {
- panic!("when targeting MUSL the build.musl-root option \
- must be specified in config.toml")
- }
- }
- }
-
if target.contains("msvc") {
// There are three builds of cmake on windows: MSVC, MinGW, and
// Cygwin. The Cygwin build does not have generators for Visual
--- a/src/liblibc/src/unix/mod.rs
+++ b/src/liblibc/src/unix/mod.rs
@@ -187,11 +187,6 @@
} else if #[cfg(all(not(stdbuild), feature = "use_std"))] {
// cargo build, don't pull in anything extra as the libstd dep
// already pulls in all libs.
- } else if #[cfg(any(all(target_env = "musl", not(target_arch = "mips")),
- target_env = "musleabi",
- target_env = "musleabihf"))] {
- #[link(name = "c", kind = "static")]
- extern {}
} else if #[cfg(target_os = "emscripten")] {
#[link(name = "c")]
extern {}
--- a/src/librustc_back/target/x86_64_unknown_linux_musl.rs
+++ b/src/librustc_back/target/x86_64_unknown_linux_musl.rs
@@ -11,7 +11,7 @@
use target::Target;
pub fn target() -> Target {
- let mut base = super::linux_musl_base::opts();
+ let mut base = super::linux_base::opts();
base.cpu = "x86-64".to_string();
base.max_atomic_width = 64;
base.pre_link_args.push("-m64".to_string());
--- a/src/libunwind/build.rs
+++ b/src/libunwind/build.rs
@@ -16,9 +16,7 @@
let target = env::var("TARGET").unwrap();
if target.contains("linux") {
- if target.contains("musl") && (target.contains("x86_64") || target.contains("i686")) {
- println!("cargo:rustc-link-lib=static=unwind");
- } else if !target.contains("android") {
+ if !target.contains("android") {
println!("cargo:rustc-link-lib=gcc_s");
}
} else if target.contains("freebsd") {

View file

@ -0,0 +1,19 @@
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Thu, 04 Aug 2016 17:53:00 +0200
Subject: [PATCH] Workaround for external LLVM built with LLVM_ENABLE_FFI
Workaround for problem with LLVM_ENABLE_FFI described in
https://github.com/rust-lang/rust/issues/34486.
--- a/src/librustc_llvm/lib.rs
+++ b/src/librustc_llvm/lib.rs
@@ -577,6 +577,9 @@
#[cfg(not(cargobuild))]
extern {}
+#[link(name = "ffi")]
+extern {}
+
#[linked_from = "rustllvm"] // not quite true but good enough
extern {
/* Create and destroy contexts. */

View file

@ -4,33 +4,111 @@ version=1.10.0
revision=1
wrksrc="rustc-${version}"
lib32disabled=yes
patch_args="-Np1"
build_style=configure
# XXX musl support still incomplete
only_for_archs="x86_64"
hostmakedepends="pkg-config curl python"
make_build_args="dist VERBOSE=1"
only_for_archs="x86_64 x86_64-musl"
hostmakedepends="cmake curl pkg-config python"
makedepends="libffi-devel lld-devel llvm ncurses-devel zlib-devel"
short_desc="Safe, concurrent, practical systems language"
maintainer="Juan RP <xtraeme@voidlinux.eu>"
homepage="http://www.rust-lang.org/"
license="MIT, Apache-2.0"
distfiles="https://static.rust-lang.org/dist/rustc-${version}-src.tar.gz"
checksum=a4015aacf4f6d8a8239253c4da46e7abaa8584f8214d1828d2ff0a8f56176869
checksum="a4015aacf4f6d8a8239253c4da46e7abaa8584f8214d1828d2ff0a8f56176869"
case "$XBPS_MACHINE" in
x86_64-musl)
distfiles+="
https://alpine.geeknet.cz/distfiles/rustc-${version}-x86_64-unknown-linux-musl.tar.gz
https://alpine.geeknet.cz/distfiles/rust-std-${version}-x86_64-unknown-linux-musl.tar.gz
https://alpine.geeknet.cz/distfiles/cargo-0.11.0-nightly-x86_64-alpine-linux-musl.tar.gz"
checksum+="
a7d8baacfa2225c923de28ecef2c9550c1d82cef3b90f6a1b8431359da7e7e69
335527615fc1a5f53d41c1d8556645bfe0b4f3a39f72ad859b392392066d9239
587172026c0565e839d96b0c1d4c68c000927817398241f96682dca47fa8c3b9"
;;
x86_64)
distfiles+="
https://static.rust-lang.org/dist/2016-05-24/rustc-1.9.0-x86_64-unknown-linux-gnu.tar.gz
https://static.rust-lang.org/dist/2016-05-24/rust-std-1.9.0-x86_64-unknown-linux-gnu.tar.gz
https://static.rust-lang.org/cargo-dist/2016-04-10/cargo-nightly-x86_64-unknown-linux-gnu.tar.gz"
checksum+="
d0704d10237c66c3efafa6f7e5570c59a1d3fe5c6d99487540f90ebb37cd84c4
82db31ce846d2ed986b10bf7859e207a5e7f3d78b0e333bb4b1d6795af4ec44b
721a2bfb1f2ffff09b59911ba686a3a55eac6a2df88f19168be0a7c8a1fdffca"
;;
esac
post_extract() {
rm -rf src/llvm
mkdir -p stage0
cp -flr ../rustc-*/rustc/* stage0
cp -flr ../rust-std-*/rust-std-*/* stage0
cp -flr ../cargo-*/cargo/* stage0
# XXX: Cheat Rust build system so we can build rustc using different
# version of (prebuilt) stable rustc than preconfigured. It's hack-ish,
# but since we're basically rebuilding rustc with the same version,
# it's actually safe.
# Note: --enable-local-rebuild from #33787 didn't work, don't know why.
rustc_ver="$($wrksrc/stage0/bin/rustc --version | cut -f2 -d ' ')"
rustc_key="$(printf "$rustc_ver" | md5sum | cut -c1-8)"
sed -Ei \
-e "s/^(rustc):.*/\1: $rustc_ver-1970-01-01/" \
-e "s/^(rustc_key):.*/\1: $rustc_key/" \
src/stage0.txt
# Generate config for bootstrap.py to use our prebuilt rustc and cargo
# for bootstrapping instead of downloading snapshot from internet.
cat > config.toml <<EOF
[build]
cargo = "$wrksrc/stage0/bin/cargo"
rustc = "$wrksrc/stage0/bin/rustc"
EOF
}
pre_build() {
export CARGO_HOME="$wrksrc/.cargo"
}
do_configure() {
local _triplet
case $XBPS_TARGET_MACHINE in
i686*) _triplet=i686-unknown-linux-gnu;;
x86_64*) _triplet=x86_64-unknown-linux-gnu;;
x86_64) _triplet=x86_64-unknown-linux-gnu;;
x86_64-musl) _triplet=x86_64-unknown-linux-musl;;
*) _triplet=$XBPS_TARGET_MACHINE;;
esac
./configure --prefix=/usr --disable-docs --enable-ccache --build=${_triplet} --release-channel=stable
configure_args="
--prefix=/usr
--host=${_triplet}
--build=${_triplet}
--release-channel=stable
--disable-docs
--disable-rpath
--enable-ccache
--enable-rustbuild
--llvm-root=/usr
"
case "$XBPS_TARGET_MACHINE" in
*-musl)
configure_args+="--musl-root=/usr --disable-jemalloc"
;;
esac
./configure $configure_args
}
post_install() {
do_install() {
vmkdir usr
tar xf build/dist/rustc-*.tar.gz -C "$DESTDIR/usr" --strip-components=2 --exclude=manifest.in
tar xf build/dist/rust-std-*.tar.gz -C "$DESTDIR/usr/lib" --strip-components=3 --exclude=manifest.in
vlicense COPYRIGHT
vlicense LICENSE-APACHE
vlicense LICENSE-MIT
cd ${DESTDIR}/usr/lib/rustlib
rm install.log uninstall.sh components manifest-rustc rust-installer-version
cd ${DESTDIR}/usr/lib
ln -sf rustlib/*/lib/*.so . # symlinks instead of copies