From aacb4980d2c7ccc07fd9105c8bb31468c5ccbec7 Mon Sep 17 00:00:00 2001 From: Fabio Valentini Date: Fri, 28 Aug 2020 23:03:37 +0200 Subject: [PATCH] fix LTO with doctests (backported cargo PR#8657) --- 0002-Fix-LTO-with-doctests.patch | 133 +++++++++++++++++++++++++++++++ rust.spec | 8 +- 2 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 0002-Fix-LTO-with-doctests.patch diff --git a/0002-Fix-LTO-with-doctests.patch b/0002-Fix-LTO-with-doctests.patch new file mode 100644 index 0000000..e251c11 --- /dev/null +++ b/0002-Fix-LTO-with-doctests.patch @@ -0,0 +1,133 @@ +From 2c9deaabf99dab9998f6ddbbe496d19ff7ce31f0 Mon Sep 17 00:00:00 2001 +From: Fabio Valentini +Date: Fri, 28 Aug 2020 21:56:45 +0200 +Subject: [PATCH 2/2] Fix LTO with doctests + +--- + .../src/cargo/core/compiler/context/mod.rs | 3 +- + .../cargo/src/cargo/core/compiler/mod.rs | 59 +++++---------- + src/tools/cargo/src/cargo/core/profiles.rs | 7 +- + src/tools/cargo/tests/testsuite/lto.rs | 71 ++++++++++++++++--- + 4 files changed, 85 insertions(+), 55 deletions(-) + +diff --git a/src/tools/cargo/src/cargo/core/compiler/context/mod.rs b/src/tools/cargo/src/cargo/core/compiler/context/mod.rs +index 52b954dd1..82831f423 100644 +--- a/src/tools/cargo/src/cargo/core/compiler/context/mod.rs ++++ b/src/tools/cargo/src/cargo/core/compiler/context/mod.rs +@@ -210,7 +210,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> { + // Collect information for `rustdoc --test`. + if unit.mode.is_doc_test() { + let mut unstable_opts = false; +- let args = compiler::extern_args(&self, unit, &mut unstable_opts)?; ++ let mut args = compiler::extern_args(&self, unit, &mut unstable_opts)?; ++ args.extend(compiler::lto_args(&self, unit)); + self.compilation.to_doc_test.push(compilation::Doctest { + unit: unit.clone(), + args, +diff --git a/src/tools/cargo/src/cargo/core/compiler/mod.rs b/src/tools/cargo/src/cargo/core/compiler/mod.rs +index 9399c5042..47d2b9bb4 100644 +--- a/src/tools/cargo/src/cargo/core/compiler/mod.rs ++++ b/src/tools/cargo/src/cargo/core/compiler/mod.rs +@@ -783,49 +783,9 @@ fn build_base_args( + cmd.arg("-C").arg(format!("panic={}", panic)); + } + +- match cx.lto[unit] { +- lto::Lto::Run(None) => { +- cmd.arg("-C").arg("lto"); +- } +- lto::Lto::Run(Some(s)) => { +- cmd.arg("-C").arg(format!("lto={}", s)); +- } +- lto::Lto::Off => { +- cmd.arg("-C").arg("lto=off"); +- } +- lto::Lto::ObjectAndBitcode => {} // this is rustc's default +- lto::Lto::OnlyBitcode => { +- // Note that this compiler flag, like the one below, is just an +- // optimization in terms of build time. If we don't pass it then +- // both object code and bitcode will show up. This is lagely just +- // compat until the feature lands on stable and we can remove the +- // conditional branch. +- if cx +- .bcx +- .target_data +- .info(CompileKind::Host) +- .supports_embed_bitcode +- .unwrap() +- { +- cmd.arg("-Clinker-plugin-lto"); +- } +- } +- lto::Lto::OnlyObject => { +- if cx +- .bcx +- .target_data +- .info(CompileKind::Host) +- .supports_embed_bitcode +- .unwrap() +- { +- cmd.arg("-Cembed-bitcode=no"); +- } +- } +- } ++ cmd.args(<o_args(cx, unit)); + + if let Some(n) = codegen_units { +- // There are some restrictions with LTO and codegen-units, so we +- // only add codegen units when LTO is not used. + cmd.arg("-C").arg(&format!("codegen-units={}", n)); + } + +@@ -952,6 +912,23 @@ fn build_base_args( + Ok(()) + } + ++fn lto_args(cx: &Context<'_, '_>, unit: &Unit) -> Vec { ++ let mut result = Vec::new(); ++ let mut push = |arg: &str| { ++ result.push(OsString::from("-C")); ++ result.push(OsString::from(arg)); ++ }; ++ match cx.lto[unit] { ++ lto::Lto::Run(None) => push("lto"), ++ lto::Lto::Run(Some(s)) => push(&format!("lto={}", s)), ++ lto::Lto::Off => push("lto=off"), ++ lto::Lto::ObjectAndBitcode => {} // this is rustc's default ++ lto::Lto::OnlyBitcode => push("linker-plugin-lto"), ++ lto::Lto::OnlyObject => push("embed-bitcode=no"), ++ } ++ result ++} ++ + fn build_deps_args( + cmd: &mut ProcessBuilder, + cx: &mut Context<'_, '_>, +diff --git a/src/tools/cargo/src/cargo/core/profiles.rs b/src/tools/cargo/src/cargo/core/profiles.rs +index 6a28bd261..ca0c2e417 100644 +--- a/src/tools/cargo/src/cargo/core/profiles.rs ++++ b/src/tools/cargo/src/cargo/core/profiles.rs +@@ -302,7 +302,7 @@ impl Profiles { + }; + + match mode { +- CompileMode::Test | CompileMode::Bench => { ++ CompileMode::Test | CompileMode::Bench | CompileMode::Doctest => { + if release { + ( + InternedString::new("bench"), +@@ -315,10 +315,7 @@ impl Profiles { + ) + } + } +- CompileMode::Build +- | CompileMode::Check { .. } +- | CompileMode::Doctest +- | CompileMode::RunCustomBuild => { ++ CompileMode::Build | CompileMode::Check { .. } | CompileMode::RunCustomBuild => { + // Note: `RunCustomBuild` doesn't normally use this code path. + // `build_unit_profiles` normally ensures that it selects the + // ancestor's profile. However, `cargo clean -p` can hit this +-- +2.26.2 + diff --git a/rust.spec b/rust.spec index ed134fb..d5f9032 100644 --- a/rust.spec +++ b/rust.spec @@ -53,7 +53,7 @@ Name: rust Version: 1.46.0 -Release: 1%{?dist} +Release: 2%{?dist} Summary: The Rust Programming Language License: (ASL 2.0 or MIT) and (BSD and MIT) # ^ written as: (rust itself) and (bundled libraries) @@ -69,6 +69,8 @@ Source0: https://static.rust-lang.org/dist/%{rustc_package}.tar.xz # https://github.com/rust-lang/cargo/pull/8598 Patch1: 0001-Fix-jobserver_exists-test-on-single-cpu-systems.patch +# https://github.com/rust-lang/cargo/pull/8657 (backported) +Patch2: 0002-Fix-LTO-with-doctests.patch ### RHEL-specific patches below ### @@ -409,6 +411,7 @@ test -f '%{local_rust_root}/bin/rustc' %setup -q -n %{rustc_package} %patch1 -p1 -d src/tools/cargo +%patch2 -p1 %if %with disabled_libssh2 %patch100 -p1 @@ -744,6 +747,9 @@ rm -f %{buildroot}%{rustlibdir}/etc/lldb_*.py* %changelog +* Fri Aug 28 2020 Fabio Valentini - 1.46.0-2 +- Fix LTO with doctests (backported cargo PR#8657). + * Thu Aug 27 2020 Josh Stone - 1.46.0-1 - Update to 1.46.0.