diff options
author | stefson <herrtimson@yahoo.de> | 2019-10-11 19:50:06 +0200 |
---|---|---|
committer | stefson <herrtimson@yahoo.de> | 2019-10-11 19:50:06 +0200 |
commit | 80567847560b60882eca2ddb4cec11479e14c5ac (patch) | |
tree | e34d2a6d7c051206618891c0e1990f6e4a8ff261 | |
parent | Merge pull request #445 from stefson/cranelift-0.45 (diff) | |
download | rust-80567847560b60882eca2ddb4cec11479e14c5ac.tar.gz rust-80567847560b60882eca2ddb4cec11479e14c5ac.tar.bz2 rust-80567847560b60882eca2ddb4cec11479e14c5ac.zip |
dev-lang/rust: add beta channel ebuild
-rw-r--r-- | dev-lang/rust/files/pr64823.patch | 476 | ||||
-rw-r--r-- | dev-lang/rust/rust-999.ebuild | 343 |
2 files changed, 819 insertions, 0 deletions
diff --git a/dev-lang/rust/files/pr64823.patch b/dev-lang/rust/files/pr64823.patch new file mode 100644 index 0000000..d0a9fe6 --- /dev/null +++ b/dev-lang/rust/files/pr64823.patch @@ -0,0 +1,476 @@ +From faee5fd388a564febc56aa642241f221c0ac1cd1 Mon Sep 17 00:00:00 2001 +From: Josh Stone <jistone@redhat.com> +Date: Thu, 26 Sep 2019 14:44:08 -0700 +Subject: [PATCH 1/6] [WIP] minimize the rust-std component + +--- + src/bootstrap/builder.rs | 1 + + src/bootstrap/dist.rs | 79 +++++++++++++++++++++++++++++++++++++++- + 2 files changed, 78 insertions(+), 2 deletions(-) + +diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs +index 5d586f0c461d..afdcabc08302 100644 +--- a/src/bootstrap/builder.rs ++++ b/src/bootstrap/builder.rs +@@ -443,6 +443,7 @@ impl<'a> Builder<'a> { + dist::Rustc, + dist::DebuggerScripts, + dist::Std, ++ dist::StdZ, + dist::Analysis, + dist::Src, + dist::PlainSourceTarball, +diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs +index d9dff77a30e6..ceb7acb83e74 100644 +--- a/src/bootstrap/dist.rs ++++ b/src/bootstrap/dist.rs +@@ -675,6 +675,81 @@ impl Step for Std { + return distdir(builder).join(format!("{}-{}.tar.gz", name, target)); + } + ++ builder.ensure(compile::Std { compiler, target }); ++ ++ let image = tmpdir(builder).join(format!("{}-{}-image", name, target)); ++ let _ = fs::remove_dir_all(&image); ++ ++ ++ let dst = image.join("lib/rustlib").join(target).join("lib"); ++ t!(fs::create_dir_all(&dst)); ++ ++ let stamp = dbg!(compile::libstd_stamp(builder, compiler, target)); ++ for (path, host) in builder.read_stamp_file(&stamp) { ++ if !host { ++ builder.copy(&path, &dst.join(path.file_name().unwrap())); ++ } ++ } ++ ++ let mut cmd = rust_installer(builder); ++ cmd.arg("generate") ++ .arg("--product-name=Rust") ++ .arg("--rel-manifest-dir=rustlib") ++ .arg("--success-message=std-is-standing-at-the-ready.") ++ .arg("--image-dir").arg(&image) ++ .arg("--work-dir").arg(&tmpdir(builder)) ++ .arg("--output-dir").arg(&distdir(builder)) ++ .arg(format!("--package-name={}-{}", name, target)) ++ .arg(format!("--component-name=rust-std-{}", target)) ++ .arg("--legacy-manifest-dirs=rustlib,cargo"); ++ ++ builder.info(&format!("Dist std stage{} ({} -> {})", ++ compiler.stage, &compiler.host, target)); ++ let _time = timeit(builder); ++ builder.run(&mut cmd); ++ builder.remove_dir(&image); ++ distdir(builder).join(format!("{}-{}.tar.gz", name, target)) ++ } ++} ++ ++#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)] ++pub struct StdZ { ++ pub compiler: Compiler, ++ pub target: Interned<String>, ++} ++ ++impl Step for StdZ { ++ type Output = PathBuf; ++ const DEFAULT: bool = true; ++ ++ fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { ++ run.path("src/libstdZ") ++ } ++ ++ fn make_run(run: RunConfig<'_>) { ++ run.builder.ensure(StdZ { ++ compiler: run.builder.compiler_for( ++ run.builder.top_stage, ++ run.builder.config.build, ++ run.target, ++ ), ++ target: run.target, ++ }); ++ } ++ ++ fn run(self, builder: &Builder<'_>) -> PathBuf { ++ let compiler = self.compiler; ++ let target = self.target; ++ ++ let name = pkgname(builder, "rust-stdZ"); ++ ++ // The only true set of target libraries came from the build triple, so ++ // let's reduce redundant work by only producing archives from that host. ++ if compiler.host != builder.config.build { ++ builder.info("\tskipping, not a build host"); ++ return distdir(builder).join(format!("{}-{}.tar.gz", name, target)); ++ } ++ + // We want to package up as many target libraries as possible + // for the `rust-std` package, so if this is a host target we + // depend on librustc and otherwise we just depend on libtest. +@@ -710,12 +785,12 @@ impl Step for Std { + cmd.arg("generate") + .arg("--product-name=Rust") + .arg("--rel-manifest-dir=rustlib") +- .arg("--success-message=std-is-standing-at-the-ready.") ++ .arg("--success-message=stdZ-is-standing-at-the-ready.") + .arg("--image-dir").arg(&image) + .arg("--work-dir").arg(&tmpdir(builder)) + .arg("--output-dir").arg(&distdir(builder)) + .arg(format!("--package-name={}-{}", name, target)) +- .arg(format!("--component-name=rust-std-{}", target)) ++ .arg(format!("--component-name=rust-stdZ-{}", target)) + .arg("--legacy-manifest-dirs=rustlib,cargo"); + + builder.info(&format!("Dist std stage{} ({} -> {})", + +From dc8ee51c5418ce37b63f1c9bdee98745f5dfe627 Mon Sep 17 00:00:00 2001 +From: Josh Stone <jistone@redhat.com> +Date: Fri, 27 Sep 2019 12:31:00 -0700 +Subject: [PATCH 2/6] Use builder.compiler_for() to find the libstd stamp + +--- + src/bootstrap/dist.rs | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs +index ceb7acb83e74..e1e47d5370a0 100644 +--- a/src/bootstrap/dist.rs ++++ b/src/bootstrap/dist.rs +@@ -680,11 +680,11 @@ impl Step for Std { + let image = tmpdir(builder).join(format!("{}-{}-image", name, target)); + let _ = fs::remove_dir_all(&image); + +- + let dst = image.join("lib/rustlib").join(target).join("lib"); + t!(fs::create_dir_all(&dst)); + +- let stamp = dbg!(compile::libstd_stamp(builder, compiler, target)); ++ let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target); ++ let stamp = dbg!(compile::libstd_stamp(builder, compiler_to_use, target)); + for (path, host) in builder.read_stamp_file(&stamp) { + if !host { + builder.copy(&path, &dst.join(path.file_name().unwrap())); + +From 9175f279b583fa71d8b4f6078af319e9a2155b75 Mon Sep 17 00:00:00 2001 +From: Josh Stone <jistone@redhat.com> +Date: Thu, 3 Oct 2019 10:57:19 -0700 +Subject: [PATCH 3/6] add dist::RustcDev for unstable compiler libraries + +--- + src/bootstrap/builder.rs | 2 +- + src/bootstrap/dist.rs | 102 +++++++++++++++++---------------------- + 2 files changed, 46 insertions(+), 58 deletions(-) + +diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs +index afdcabc08302..bfba39961a22 100644 +--- a/src/bootstrap/builder.rs ++++ b/src/bootstrap/builder.rs +@@ -443,7 +443,7 @@ impl<'a> Builder<'a> { + dist::Rustc, + dist::DebuggerScripts, + dist::Std, +- dist::StdZ, ++ dist::RustcDev, + dist::Analysis, + dist::Src, + dist::PlainSourceTarball, +diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs +index e1e47d5370a0..e5a43dcb29f6 100644 +--- a/src/bootstrap/dist.rs ++++ b/src/bootstrap/dist.rs +@@ -637,6 +637,28 @@ impl Step for DebuggerScripts { + } + } + ++fn skip_host_target_lib(builder: &Builder<'_>, compiler: Compiler) -> bool { ++ // The only true set of target libraries came from the build triple, so ++ // let's reduce redundant work by only producing archives from that host. ++ if compiler.host != builder.config.build { ++ builder.info("\tskipping, not a build host"); ++ true ++ } else { ++ false ++ } ++} ++ ++/// Copy stamped files into an image's `target/lib` directory. ++fn copy_target_libs(builder: &Builder<'_>, target: &str, image: &Path, stamp: &Path) { ++ let dst = image.join("lib/rustlib").join(target).join("lib"); ++ t!(fs::create_dir_all(&dst)); ++ for (path, host) in builder.read_stamp_file(stamp) { ++ if !host || builder.config.build == target { ++ builder.copy(&path, &dst.join(path.file_name().unwrap())); ++ } ++ } ++} ++ + #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)] + pub struct Std { + pub compiler: Compiler, +@@ -667,12 +689,9 @@ impl Step for Std { + let target = self.target; + + let name = pkgname(builder, "rust-std"); +- +- // The only true set of target libraries came from the build triple, so +- // let's reduce redundant work by only producing archives from that host. +- if compiler.host != builder.config.build { +- builder.info("\tskipping, not a build host"); +- return distdir(builder).join(format!("{}-{}.tar.gz", name, target)); ++ let archive = distdir(builder).join(format!("{}-{}.tar.gz", name, target)); ++ if skip_host_target_lib(builder, compiler) { ++ return archive; + } + + builder.ensure(compile::Std { compiler, target }); +@@ -680,16 +699,9 @@ impl Step for Std { + let image = tmpdir(builder).join(format!("{}-{}-image", name, target)); + let _ = fs::remove_dir_all(&image); + +- let dst = image.join("lib/rustlib").join(target).join("lib"); +- t!(fs::create_dir_all(&dst)); +- + let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target); +- let stamp = dbg!(compile::libstd_stamp(builder, compiler_to_use, target)); +- for (path, host) in builder.read_stamp_file(&stamp) { +- if !host { +- builder.copy(&path, &dst.join(path.file_name().unwrap())); +- } +- } ++ let stamp = compile::libstd_stamp(builder, compiler_to_use, target); ++ copy_target_libs(builder, &target, &image, &stamp); + + let mut cmd = rust_installer(builder); + cmd.arg("generate") +@@ -708,26 +720,27 @@ impl Step for Std { + let _time = timeit(builder); + builder.run(&mut cmd); + builder.remove_dir(&image); +- distdir(builder).join(format!("{}-{}.tar.gz", name, target)) ++ archive + } + } + + #[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)] +-pub struct StdZ { ++pub struct RustcDev { + pub compiler: Compiler, + pub target: Interned<String>, + } + +-impl Step for StdZ { ++impl Step for RustcDev { + type Output = PathBuf; + const DEFAULT: bool = true; ++ const ONLY_HOSTS: bool = true; + + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { +- run.path("src/libstdZ") ++ run.path("rustc-dev") + } + + fn make_run(run: RunConfig<'_>) { +- run.builder.ensure(StdZ { ++ run.builder.ensure(RustcDev { + compiler: run.builder.compiler_for( + run.builder.top_stage, + run.builder.config.build, +@@ -741,64 +754,39 @@ impl Step for StdZ { + let compiler = self.compiler; + let target = self.target; + +- let name = pkgname(builder, "rust-stdZ"); +- +- // The only true set of target libraries came from the build triple, so +- // let's reduce redundant work by only producing archives from that host. +- if compiler.host != builder.config.build { +- builder.info("\tskipping, not a build host"); +- return distdir(builder).join(format!("{}-{}.tar.gz", name, target)); ++ let name = pkgname(builder, "rustc-dev"); ++ let archive = distdir(builder).join(format!("{}-{}.tar.gz", name, target)); ++ if skip_host_target_lib(builder, compiler) { ++ return archive; + } + +- // We want to package up as many target libraries as possible +- // for the `rust-std` package, so if this is a host target we +- // depend on librustc and otherwise we just depend on libtest. +- if builder.hosts.iter().any(|t| t == target) { +- builder.ensure(compile::Rustc { compiler, target }); +- } else { +- builder.ensure(compile::Std { compiler, target }); +- } ++ builder.ensure(compile::Rustc { compiler, target }); + + let image = tmpdir(builder).join(format!("{}-{}-image", name, target)); + let _ = fs::remove_dir_all(&image); + +- let dst = image.join("lib/rustlib").join(target); +- t!(fs::create_dir_all(&dst)); +- let mut src = builder.sysroot_libdir(compiler, target).to_path_buf(); +- src.pop(); // Remove the trailing /lib folder from the sysroot_libdir +- builder.cp_filtered(&src, &dst, &|path| { +- if let Some(name) = path.file_name().and_then(|s| s.to_str()) { +- if name == builder.config.rust_codegen_backends_dir.as_str() { +- return false +- } +- if name == "bin" { +- return false +- } +- if name.contains("LLVM") { +- return false +- } +- } +- true +- }); ++ let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target); ++ let stamp = compile::librustc_stamp(builder, compiler_to_use, target); ++ copy_target_libs(builder, &target, &image, &stamp); + + let mut cmd = rust_installer(builder); + cmd.arg("generate") + .arg("--product-name=Rust") + .arg("--rel-manifest-dir=rustlib") +- .arg("--success-message=stdZ-is-standing-at-the-ready.") ++ .arg("--success-message=Rust-is-ready-to-develop.") + .arg("--image-dir").arg(&image) + .arg("--work-dir").arg(&tmpdir(builder)) + .arg("--output-dir").arg(&distdir(builder)) + .arg(format!("--package-name={}-{}", name, target)) +- .arg(format!("--component-name=rust-stdZ-{}", target)) ++ .arg(format!("--component-name=rustc-dev-{}", target)) + .arg("--legacy-manifest-dirs=rustlib,cargo"); + +- builder.info(&format!("Dist std stage{} ({} -> {})", ++ builder.info(&format!("Dist rustc-dev stage{} ({} -> {})", + compiler.stage, &compiler.host, target)); + let _time = timeit(builder); + builder.run(&mut cmd); + builder.remove_dir(&image); +- distdir(builder).join(format!("{}-{}.tar.gz", name, target)) ++ archive + } + } + + +From bd4e9d5fe146d5475dc35f5f61d5186b15692fdc Mon Sep 17 00:00:00 2001 +From: Josh Stone <jistone@redhat.com> +Date: Thu, 3 Oct 2019 11:40:39 -0700 +Subject: [PATCH 4/6] add rustc-dev to tools/build-manifest + +--- + src/tools/build-manifest/src/main.rs | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs +index f41e7dd17ede..d5933789a649 100644 +--- a/src/tools/build-manifest/src/main.rs ++++ b/src/tools/build-manifest/src/main.rs +@@ -399,6 +399,7 @@ impl Builder { + fn add_packages_to(&mut self, manifest: &mut Manifest) { + let mut package = |name, targets| self.package(name, &mut manifest.pkg, targets); + package("rustc", HOSTS); ++ package("rustc-dev", HOSTS); + package("cargo", HOSTS); + package("rust-mingw", MINGW); + package("rust-std", TARGETS); +@@ -473,6 +474,7 @@ impl Builder { + // and so is rust-mingw if it's available for the target. + components.extend(vec![ + host_component("rustc"), ++ host_component("rustc-dev"), + host_component("rust-std"), + host_component("cargo"), + host_component("rust-docs"), +@@ -498,6 +500,11 @@ impl Builder { + .filter(|&&target| target != host) + .map(|target| Component::from_str("rust-std", target)) + ); ++ extensions.extend( ++ HOSTS.iter() ++ .filter(|&&target| target != host) ++ .map(|target| Component::from_str("rustc-dev", target)) ++ ); + extensions.push(Component::from_str("rust-src", "*")); + + // If the components/extensions don't actually exist for this + +From 2dcf2f0f7b965d5977dfbafec9128084bdd82a42 Mon Sep 17 00:00:00 2001 +From: Josh Stone <jistone@redhat.com> +Date: Mon, 7 Oct 2019 09:31:51 -0700 +Subject: [PATCH 5/6] Only install rustc-dev by default on nightly + +--- + src/tools/build-manifest/src/main.rs | 10 +++++++++- + 1 file changed, 9 insertions(+), 1 deletion(-) + +diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs +index d5933789a649..97e758f9b823 100644 +--- a/src/tools/build-manifest/src/main.rs ++++ b/src/tools/build-manifest/src/main.rs +@@ -474,7 +474,6 @@ impl Builder { + // and so is rust-mingw if it's available for the target. + components.extend(vec![ + host_component("rustc"), +- host_component("rustc-dev"), + host_component("rust-std"), + host_component("cargo"), + host_component("rust-docs"), +@@ -483,6 +482,15 @@ impl Builder { + components.push(host_component("rust-mingw")); + } + ++ // The compiler libraries are not stable for end users, but `rustc-dev` was only recently ++ // split out of `rust-std`. We'll include it by default as a transition for nightly users, ++ // but ship it as an optional component on the beta and stable channels. ++ if self.rust_release == "nightly" { ++ components.push(host_component("rustc-dev")); ++ } else { ++ extensions.push(host_component("rustc-dev")); ++ } ++ + // Tools are always present in the manifest, + // but might be marked as unavailable if they weren't built. + extensions.extend(vec![ + +From d3052540993b6acf009d39949b79077a49544934 Mon Sep 17 00:00:00 2001 +From: Josh Stone <jistone@redhat.com> +Date: Mon, 7 Oct 2019 15:49:51 -0700 +Subject: [PATCH 6/6] Add rustc-dev to nightly default and complete profiles + +--- + src/tools/build-manifest/src/main.rs | 15 +++++++++++++++ + 1 file changed, 15 insertions(+) + +diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs +index 97e758f9b823..c0d2deab2f8b 100644 +--- a/src/tools/build-manifest/src/main.rs ++++ b/src/tools/build-manifest/src/main.rs +@@ -427,6 +427,13 @@ impl Builder { + "rls-preview", "rust-src", "llvm-tools-preview", + "lldb-preview", "rust-analysis", "miri-preview" + ]); ++ ++ // The compiler libraries are not stable for end users, but `rustc-dev` was only recently ++ // split out of `rust-std`. We'll include it by default as a transition for nightly users. ++ if self.rust_release == "nightly" { ++ self.extend_profile("default", &mut manifest.profiles, &["rustc-dev"]); ++ self.extend_profile("complete", &mut manifest.profiles, &["rustc-dev"]); ++ } + } + + fn add_renames_to(&self, manifest: &mut Manifest) { +@@ -549,6 +556,14 @@ impl Builder { + dst.insert(profile_name.to_owned(), pkgs.iter().map(|s| (*s).to_owned()).collect()); + } + ++ fn extend_profile(&mut self, ++ profile_name: &str, ++ dst: &mut BTreeMap<String, Vec<String>>, ++ pkgs: &[&str]) { ++ dst.get_mut(profile_name).expect("existing profile") ++ .extend(pkgs.iter().map(|s| (*s).to_owned())); ++ } ++ + fn package(&mut self, + pkgname: &str, + dst: &mut BTreeMap<String, Package>, diff --git a/dev-lang/rust/rust-999.ebuild b/dev-lang/rust/rust-999.ebuild new file mode 100644 index 0000000..f175e98 --- /dev/null +++ b/dev-lang/rust/rust-999.ebuild @@ -0,0 +1,343 @@ +# Copyright 1999-2019 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=7 + +PYTHON_COMPAT=( python2_7 python3_{5,6,7} pypy ) + +inherit check-reqs estack flag-o-matic llvm multiprocessing multilib-build python-any-r1 rust-toolchain toolchain-funcs git-r3 + +SLOT="beta" +MY_P="rust-beta" +EGIT_REPO_URI="https://github.com/rust-lang/rust.git" +EGIT_BRANCH="beta" + +EGIT_CHECKOUT_DIR="${MY_P}-src" +KEYWORDS="" + +CHOST_amd64=x86_64-unknown-linux-gnu +CHOST_x86=i686-unknown-linux-gnu +CHOST_arm64=aarch64-unknown-linux-gnu + +DESCRIPTION="Systems programming language from Mozilla" +HOMEPAGE="https://www.rust-lang.org/" + +RESTRICT="network-sandbox" + +ALL_LLVM_TARGETS=( AArch64 AMDGPU ARM BPF Hexagon Lanai Mips MSP430 + NVPTX PowerPC Sparc SystemZ WebAssembly X86 XCore ) +ALL_LLVM_TARGETS=( "${ALL_LLVM_TARGETS[@]/#/llvm_targets_}" ) +LLVM_TARGET_USEDEPS=${ALL_LLVM_TARGETS[@]/%/?} + +LICENSE="|| ( MIT Apache-2.0 ) BSD-1 BSD-2 BSD-4 UoI-NCSA" + +IUSE="clippy cpu_flags_x86_sse2 debug doc libressl rls rustfmt system-llvm wasm sanitize miri zsh-completion ${ALL_LLVM_TARGETS[*]}" + +# Please keep the LLVM dependency block separate. Since LLVM is slotted, +# we need to *really* make sure we're not pulling one than more slot +# simultaneously. + +# How to use it: +# 1. List all the working slots (with min versions) in ||, newest first. +# 2. Update the := to specify *max* version, e.g. < 9. +# 3. Specify LLVM_MAX_SLOT, e.g. 8. +LLVM_DEPEND=" + || ( + sys-devel/llvm:8[llvm_targets_WebAssembly?] + wasm? ( >=sys-devel/lld-8 ) + ) + <sys-devel/llvm-10:= +" +LLVM_MAX_SLOT=9 + +COMMON_DEPEND=" + sys-libs/zlib + !libressl? ( dev-libs/openssl:0= ) + libressl? ( dev-libs/libressl:0= ) + net-libs/libssh2 + net-libs/http-parser:= + net-misc/curl[ssl] + system-llvm? ( + ${LLVM_DEPEND} + ) +" + +DEPEND="${COMMON_DEPEND} + ${PYTHON_DEPS} + || ( + >=sys-devel/gcc-4.7 + >=sys-devel/clang-3.5 + ) + dev-util/cmake +" + +RDEPEND="${COMMON_DEPEND} + >=app-eselect/eselect-rust-20190311 + !dev-util/cargo + rustfmt? ( !dev-util/rustfmt ) +" + +REQUIRED_USE="|| ( ${ALL_LLVM_TARGETS[*]} ) + wasm? ( llvm_targets_WebAssembly ) + x86? ( cpu_flags_x86_sse2 ) + ?? ( system-llvm sanitize ) +" + +PATCHES=( + "${FILESDIR}"/pr64823.patch + ) + +S="${WORKDIR}/${MY_P}-src" + +toml_usex() { + usex "$1" true false +} + +pre_build_checks() { + CHECKREQS_DISK_BUILD="7G" + eshopts_push -s extglob + if is-flagq '-g?(gdb)?([1-9])'; then + CHECKREQS_DISK_BUILD="10G" + fi + eshopts_pop + check-reqs_pkg_setup +} + +pkg_pretend() { + pre_build_checks +} + +pkg_setup() { + unset SUDO_USER + + pre_build_checks + python-any-r1_pkg_setup + if use system-llvm; then + EGIT_SUBMODULES=( "*" "-src/llvm-project" ) + llvm_pkg_setup + fi +} + +src_prepare() { + local rust_stage0_root="${WORKDIR}"/rust-stage0 + + default +} + +src_unpack() { + git-r3_src_unpack +} + +src_configure() { + local rust_target="" rust_targets="" arch_cflags + + # Collect rust target names to compile standard libs for all ABIs. + for v in $(multilib_get_enabled_abi_pairs); do + rust_targets="${rust_targets},\"$(rust_abi $(get_abi_CHOST ${v##*.}))\"" + done + if use wasm; then + rust_targets="${rust_targets},\"wasm32-unknown-unknown\"" + fi + rust_targets="${rust_targets#,}" + + local extended="true" tools="\"cargo\"," + if use clippy; then + tools="\"clippy\",$tools" + fi + if use rls; then + tools="\"rls\",\"analysis\",\"src\",$tools" + fi + if use rustfmt; then + tools="\"rustfmt\",$tools" + fi + if use miri; then + tools="\"miri\",$tools" + fi + + local rust_stage0_root="${WORKDIR}"/rust-stage0 + + rust_target="$(rust_abi)" + + cat <<- EOF > "${S}"/config.toml + [llvm] + optimize = $(toml_usex !debug) + release-debuginfo = $(toml_usex debug) + assertions = $(toml_usex debug) + targets = "${LLVM_TARGETS// /;}" + experimental-targets = "" + link-shared = $(toml_usex system-llvm) + [build] + build = "${rust_target}" + host = ["${rust_target}"] + target = [${rust_targets}] + docs = $(toml_usex doc) + submodules = false + python = "${EPYTHON}" + locked-deps = true + vendor = false + sanitizers = $(toml_usex sanitize) + extended = ${extended} + tools = [${tools}] + verbose = 2 + [install] + prefix = "${EPREFIX}/usr" + libdir = "$(get_libdir)/${P}" + docdir = "share/doc/${P}" + mandir = "share/${P}/man" + [rust] + optimize = $(toml_usex !debug) + debuginfo-level = $(usex debug 2 0) + debug-assertions = $(toml_usex debug) + default-linker = "$(tc-getCC)" + rpath = false + ignore-git = false + lld = $(usex system-llvm false $(toml_usex wasm)) + llvm-tools = $(usex system-llvm false true) + EOF + + for v in $(multilib_get_enabled_abi_pairs); do + rust_target=$(rust_abi $(get_abi_CHOST ${v##*.})) + arch_cflags="$(get_abi_CFLAGS ${v##*.})" + + cat <<- EOF >> "${S}"/config.env + CFLAGS_${rust_target}=${arch_cflags} + EOF + + cat <<- EOF >> "${S}"/config.toml + [target.${rust_target}] + cc = "$(tc-getBUILD_CC)" + cxx = "$(tc-getBUILD_CXX)" + linker = "$(tc-getCC)" + ar = "$(tc-getAR)" + EOF + if use system-llvm; then + cat <<- EOF >> "${S}"/config.toml + llvm-config = "$(get_llvm_prefix "${LLVM_MAX_SLOT}")/bin/llvm-config" + EOF + fi + done + + if use wasm; then + cat <<- EOF >> "${S}"/config.toml + [target.wasm32-unknown-unknown] + linker = "$(usex system-llvm lld rust-lld)" + EOF + fi +} + +src_compile() { + env $(cat "${S}"/config.env)\ + "${EPYTHON}" ./x.py build -vv --config="${S}"/config.toml -j$(makeopts_jobs) || die +} + +src_install() { + local rust_target abi_libdir + + env DESTDIR="${D}" "${EPYTHON}" ./x.py install -vv -j$(makeopts_jobs) --config="${S}"/config.toml || die + + mv "${ED}/usr/bin/rustc" "${ED}/usr/bin/rustc-${PV}" || die + mv "${ED}/usr/bin/rustdoc" "${ED}/usr/bin/rustdoc-${PV}" || die + mv "${ED}/usr/bin/rust-gdb" "${ED}/usr/bin/rust-gdb-${PV}" || die + mv "${ED}/usr/bin/rust-gdbgui" "${ED}/usr/bin/rust-gdbgui-${PV}" || die + mv "${ED}/usr/bin/rust-lldb" "${ED}/usr/bin/rust-lldb-${PV}" || die + mv "${ED}/usr/bin/cargo" "${ED}/usr/bin/cargo-${PV}" || die + if use clippy; then + mv "${ED}/usr/bin/clippy-driver" "${ED}/usr/bin/clippy-driver-${PV}" || die + mv "${ED}/usr/bin/cargo-clippy" "${ED}/usr/bin/cargo-clippy-${PV}" || die + fi + if use rls; then + mv "${ED}/usr/bin/rls" "${ED}/usr/bin/rls-${PV}" || die + fi + if use rustfmt; then + mv "${ED}/usr/bin/rustfmt" "${ED}/usr/bin/rustfmt-${PV}" || die + mv "${ED}/usr/bin/cargo-fmt" "${ED}/usr/bin/cargo-fmt-${PV}" || die + fi + if use miri; then + mv "${ED}/usr/bin/miri" "${ED}/usr/bin/miri-${PV}" || die + mv "${ED}/usr/bin/cargo-miri" "${ED}/usr/bin/cargo-miri-${PV}" || die + fi + if ! use zsh-completion; then + rm "${ED}/usr/share/zsh/site-functions/_cargo" # fix https://bugs.gentoo.org/675026 + fi + + # Copy shared library versions of standard libraries for all targets + # into the system's abi-dependent lib directories because the rust + # installer only does so for the native ABI. + for v in $(multilib_get_enabled_abi_pairs); do + if [ ${v##*.} = ${DEFAULT_ABI} ]; then + continue + fi + abi_libdir=$(get_abi_LIBDIR ${v##*.}) + rust_target=$(rust_abi $(get_abi_CHOST ${v##*.})) + mkdir -p "${ED}/usr/${abi_libdir}/${P}" + cp "${ED}/usr/$(get_libdir)/${P}/rustlib/${rust_target}/lib"/*.so \ + "${ED}/usr/${abi_libdir}/${P}" || die + done + + dodoc COPYRIGHT + + cat <<-EOF > "${T}"/50${P} + LDPATH="${EPREFIX}/usr/$(get_libdir)/${P}" + MANPATH="${EPREFIX}/usr/share/${P}/man" + EOF + if use rls; then + cat <<-EOF >> "${T}"/50${P} + RUST_SRC_PATH="${EPREFIX}/usr/$(get_libdir)/${P}/rustlib/src/rust/src/" + EOF + fi + doenvd "${T}"/50${P} + + # note: eselect-rust adds EROOT to all paths below + cat <<-EOF > "${T}/provider-${P}" + /usr/bin/rustdoc + /usr/bin/rust-gdb + /usr/bin/rust-gdbgui + /usr/bin/rust-lldb + EOF + echo /usr/bin/cargo >> "${T}/provider-${P}" + if use clippy; then + echo /usr/bin/clippy-driver >> "${T}/provider-${P}" + echo /usr/bin/cargo-clippy >> "${T}/provider-${P}" + fi + if use rls; then + echo /usr/bin/rls >> "${T}/provider-${P}" + fi + if use rustfmt; then + echo /usr/bin/rustfmt >> "${T}/provider-${P}" + echo /usr/bin/cargo-fmt >> "${T}/provider-${P}" + fi + if use miri; then + echo /usr/bin/miri >> "${T}/provider-${P}" + echo /usr/bin/cargo-miri >> "${T}/provider-${P}" + fi + dodir /etc/env.d/rust + insinto /etc/env.d/rust + doins "${T}/provider-${P}" +} + +pkg_postinst() { + eselect rust update --if-unset + + elog "Rust installs a helper script for calling GDB and LLDB," + elog "for your convenience it is installed under /usr/bin/rust-{gdb,lldb}-${PV}." + + ewarn "cargo is now installed from dev-lang/rust{,-bin} instead of dev-util/cargo." + ewarn "This might have resulted in a dangling symlink for /usr/bin/cargo on some" + ewarn "systems. This can be resolved by calling 'sudo eselect rust set ${P}'." + + if has_version app-editors/emacs || has_version app-editors/emacs-vcs; then + elog "install app-emacs/rust-mode to get emacs support for rust." + fi + + if has_version app-editors/gvim || has_version app-editors/vim; then + elog "install app-vim/rust-vim to get vim support for rust." + fi + + if has_version 'app-shells/zsh'; then + elog "install app-shells/rust-zshcomp to get zsh completion for rust." + fi +} + +pkg_postrm() { + eselect rust cleanup +} |