]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
rust: restore parallel builds, disable lto only for rustdoc
authorAlexander Kanavin <alex@linutronix.de>
Tue, 4 Feb 2025 10:42:05 +0000 (11:42 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 5 Feb 2025 12:48:25 +0000 (12:48 +0000)
The original reproducibility fix was problematic for a couple reasons:

- disabling both lto and parallel builds had an unfortunate effect of nearly
doubling rust-native and rust build times (which are slow to begin with).
Disabling lto hurts runtime performance too.

- both of these things were done for the *entire build*, while the only
problematic item is the librustdoc crate.

- lto=off option in config.toml has an effect only on building rustc
(the compiler itself), and doesn't help with rustdoc reproducibility.
Actual fix is the codegen-units setting, which indirectly disables
lto via giving llvm only one unit to work with at a time.

After some digging, here's a more targeted fix for the problem.

Why librustdoc is non-reproducible, but not anything else
remains a mystery, hidden deep in rust-llvm's lto optimization code.

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/recipes-devtools/rust/files/0001-src-core-build_steps-tool.rs-switch-off-lto-for-rust.patch [new file with mode: 0644]
meta/recipes-devtools/rust/files/rustdoc-repro-issue-fix-cargo-config-for-codegenunits.patch [deleted file]
meta/recipes-devtools/rust/rust-source.inc
meta/recipes-devtools/rust/rust_1.81.0.bb

diff --git a/meta/recipes-devtools/rust/files/0001-src-core-build_steps-tool.rs-switch-off-lto-for-rust.patch b/meta/recipes-devtools/rust/files/0001-src-core-build_steps-tool.rs-switch-off-lto-for-rust.patch
new file mode 100644 (file)
index 0000000..e63cfb0
--- /dev/null
@@ -0,0 +1,46 @@
+From ce68809d41291f671b440abce41f8f71c95428aa Mon Sep 17 00:00:00 2001
+From: Alexander Kanavin <alex@linutronix.de>
+Date: Mon, 3 Feb 2025 20:06:46 +0100
+Subject: [PATCH] src/core/build_steps/tool.rs: switch off lto for rustdoc
+
+For reasons currently unknown, librustdoc binary ends up with
+non-reproducible .llvm.<number> suffixes in its symbols - but
+not any other binary.
+
+Disabling lto avoids creating these suffixes. More info about the option:
+https://doc.rust-lang.org/rustc/codegen-options/index.html#lto
+
+As seen below, there's a comment in the source tree saying not to tweak the options
+but this only creates a mix of lto and non-lto optimized binary objects from
+various crates, which should be safe to mix.
+
+Upstream-Status: Inappropriate [reported at https://github.com/rust-lang/rust/issues/134589]
+Signed-off-by: Alexander Kanavin <alex@linutronix.de>
+---
+ src/bootstrap/src/core/build_steps/tool.rs | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs
+index 087df2f8a..00790affb 100644
+--- a/src/bootstrap/src/core/build_steps/tool.rs
++++ b/src/bootstrap/src/core/build_steps/tool.rs
+@@ -635,7 +635,7 @@ impl Step for Rustdoc {
+         }
+         // NOTE: Never modify the rustflags here, it breaks the build cache for other tools!
+-        let cargo = prepare_tool_cargo(
++        let mut cargo = prepare_tool_cargo(
+             builder,
+             build_compiler,
+             Mode::ToolRustc,
+@@ -645,6 +645,7 @@ impl Step for Rustdoc {
+             SourceType::InTree,
+             features.as_slice(),
+         );
++        cargo.rustflag("-Clto=off");
+         let _guard = builder.msg_tool(
+             Kind::Build,
+-- 
+2.39.5
+
diff --git a/meta/recipes-devtools/rust/files/rustdoc-repro-issue-fix-cargo-config-for-codegenunits.patch b/meta/recipes-devtools/rust/files/rustdoc-repro-issue-fix-cargo-config-for-codegenunits.patch
deleted file mode 100644 (file)
index 0aab877..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-rust: rustdoc reproducibility issue fix
-
-rust: rustdoc reproducibility issue fix
-
-The 'codegen-units' option split the crate into multiple compilation units for parallel compilation. Currently, this split is causing the rustdoc to generate differnt binary between the builds.
-To fix this the codegen-units & the lto options are disabled.
-
-More info about options:
-https://doc.rust-lang.org/cargo/reference/profiles.html#codegen-units
-https://doc.rust-lang.org/rustc/codegen-options/index.html#lto
-
-Upstream-Status: Inappropriate [oe specific]
-
-Signed-off-by: Sundeep KOKKONDA <sundeep.kokkonda@windriver.com>
----
---- a/.cargo/config.toml
-+++ b/.cargo/config.toml
-@@ -3,3 +3,7 @@
-
- [source.vendored-sources]
- directory = "vendor"
-+
-+[profile.release]
-+codegen-units = 1
-+
-
index 8484c94ef8b0a361b74d986bb532f98f7510aea3..83355935fcc9472456612f797ffe5e843eca8255 100644 (file)
@@ -4,10 +4,10 @@ SRC_URI += "https://static.rust-lang.org/dist/rustc-${RUST_VERSION}-src.tar.xz;n
             file://zlib-off64_t.patch;patchdir=${RUSTSRC} \
             file://rv32-rustix-libc-backend.patch;patchdir=${RUSTSRC} \
             file://rv32-cargo-rustix-0.38.28-fix.patch;patchdir=${RUSTSRC} \
-            file://rustdoc-repro-issue-fix-cargo-config-for-codegenunits.patch;patchdir=${RUSTSRC} \
             file://rust-oe-selftest.patch;patchdir=${RUSTSRC} \
             file://repro-issue-fix-with-cc-crate-hashmap.patch;patchdir=${RUSTSRC} \
             file://oeqa-selftest-Increase-timeout-in-process-sigpipe-ru.patch;patchdir=${RUSTSRC} \
+            file://0001-src-core-build_steps-tool.rs-switch-off-lto-for-rust.patch;patchdir=${RUSTSRC} \
 "
 SRC_URI[rust.sha256sum] = "36217ef7e32f40a180e3d79bd666b4dfdaed49dd381023a5fb765fd12d0092ce"
 
index 288b0fbb4438fa043a7445a6a8c534732fa04e6d..1038c275f6d5e6194f67d38e093c510f113ddec2 100644 (file)
@@ -136,7 +136,6 @@ python do_configure() {
     config.add_section("rust")
     config.set("rust", "rpath", e(True))
     config.set("rust", "remap-debuginfo", e(True))
-    config.set("rust", "lto", "\"off\"")
     config.set("rust", "channel", e(d.expand("${RUST_CHANNEL}")))
 
     # Whether or not to optimize the compiler and standard library