From 0ba40e8bc28b428a3f370785f8f7dc32cc0ff4b2 Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Sat, 6 Aug 2016 22:41:08 +0200 Subject: [PATCH] rust: use rustbuild, enable musl support. Closes #4570. --- .../cargo/patches/musl-NFS_SUPER_MAGICK.patch | 21 ++++ srcpkgs/cargo/template | 19 ++++ .../rust/patches/dont-require-filecheck.patch | 19 ++++ .../rust/patches/link-musl-dynamically.patch | 76 +++++++++++++++ srcpkgs/rust/patches/llvm-with-ffi.patch | 19 ++++ srcpkgs/rust/template | 96 +++++++++++++++++-- 6 files changed, 241 insertions(+), 9 deletions(-) create mode 100644 srcpkgs/cargo/patches/musl-NFS_SUPER_MAGICK.patch create mode 100644 srcpkgs/rust/patches/dont-require-filecheck.patch create mode 100644 srcpkgs/rust/patches/link-musl-dynamically.patch create mode 100644 srcpkgs/rust/patches/llvm-with-ffi.patch diff --git a/srcpkgs/cargo/patches/musl-NFS_SUPER_MAGICK.patch b/srcpkgs/cargo/patches/musl-NFS_SUPER_MAGICK.patch new file mode 100644 index 00000000000..415766ad915 --- /dev/null +++ b/srcpkgs/cargo/patches/musl-NFS_SUPER_MAGICK.patch @@ -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 + } diff --git a/srcpkgs/cargo/template b/srcpkgs/cargo/template index a7fc437ee3f..6912971b090 100644 --- a/srcpkgs/cargo/template +++ b/srcpkgs/cargo/template @@ -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 diff --git a/srcpkgs/rust/patches/dont-require-filecheck.patch b/srcpkgs/rust/patches/dont-require-filecheck.patch new file mode 100644 index 00000000000..430cc9320ca --- /dev/null +++ b/srcpkgs/rust/patches/dont-require-filecheck.patch @@ -0,0 +1,19 @@ +From: Jakub Jirutka +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") || diff --git a/srcpkgs/rust/patches/link-musl-dynamically.patch b/srcpkgs/rust/patches/link-musl-dynamically.patch new file mode 100644 index 00000000000..d15eb91ded2 --- /dev/null +++ b/srcpkgs/rust/patches/link-musl-dynamically.patch @@ -0,0 +1,76 @@ +From: Jakub Jirutka +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") { diff --git a/srcpkgs/rust/patches/llvm-with-ffi.patch b/srcpkgs/rust/patches/llvm-with-ffi.patch new file mode 100644 index 00000000000..23504eac715 --- /dev/null +++ b/srcpkgs/rust/patches/llvm-with-ffi.patch @@ -0,0 +1,19 @@ +From: Jakub Jirutka +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. */ diff --git a/srcpkgs/rust/template b/srcpkgs/rust/template index ac6c653348b..fab49a67237 100644 --- a/srcpkgs/rust/template +++ b/srcpkgs/rust/template @@ -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 " 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 <