diff mbox series

[1/3] cargo-c: keep the build host triple out of cargo unit metadata

Message ID 20261105113205.1571267-2-sunilkumar.dora@windriver.com
State New
Headers show
Series rust/cargo-c: keep the build host out of cargo -C metadata | expand

Commit Message

Dora, Sunil Kumar Nov. 5, 2026, 11:32 a.m. UTC
From: Sunil Dora <sunilkumar.dora@windriver.com>

rust-source.inc carries 0004-cargo-omit-host-triple-from-unit-metadata-hash.patch
so that cargo does not hash the "host:" line of rustc -vV into the unit
metadata of build scripts and proc-macros. That line goes into both
hashes of a host unit, so without the patch every target crate that has
a build script or uses a proc-macro gets a different unit_id, and with
that a different -C extra-filename and OUT_DIR path, on an x86_64 and
on an aarch64 build host.

The cargo-c copy of rust/files/0006-cargo-keep-host-deps-*.patch,
later in this series, takes care of the -C metadata (symbol names) side;
this one is still needed for the file names and OUT_DIR, which end up
in some binaries as strings.

cargo-c does not use that cargo binary. It links its own copy of the
cargo crate (from crates.io), so recipes built with cargo-cbuild still
have the problem. Carry the same patch here for that crate,
only the paths are different.

Drop this together with rust/files/0004-cargo-omit-host-triple-*.patch.

[YOCTO #16376]

Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
---
 ...-host-triple-from-unit-metadata-hash.patch | 64 +++++++++++++++++++
 .../cargo-c/cargo-c_0.10.26+cargo-0.100.0.bb  |  1 +
 2 files changed, 65 insertions(+)
 create mode 100644 meta/recipes-devtools/cargo-c/cargo-c/0002-cargo-omit-host-triple-from-unit-metadata-hash.patch
diff mbox series

Patch

diff --git a/meta/recipes-devtools/cargo-c/cargo-c/0002-cargo-omit-host-triple-from-unit-metadata-hash.patch b/meta/recipes-devtools/cargo-c/cargo-c/0002-cargo-omit-host-triple-from-unit-metadata-hash.patch
new file mode 100644
index 0000000000..339317d486
--- /dev/null
+++ b/meta/recipes-devtools/cargo-c/cargo-c/0002-cargo-omit-host-triple-from-unit-metadata-hash.patch
@@ -0,0 +1,64 @@ 
+From 5c4fd7d8b85f4de5be387777a782fc3ddd1227d8 Mon Sep 17 00:00:00 2001
+From: Alejandro Enedino Hernandez Samaniego <alejandro@enedino.org>
+Date: Tue, 15 Sep 2026 17:05:36 +0530
+Subject: [PATCH] cargo: keep the build host triple out of unit metadata
+
+cargo hashes the "host:" line of "rustc -vV" into the metadata of host
+units, that is build scripts and proc-macros. Every target crate that
+depends on one picks that up through its own metadata, so the same crate
+gets a different -C metadata and StableCrateId on an x86_64 and an aarch64
+build host. Drop the host from the hash. The same class of problem is
+reported upstream, framed as OS differences, in
+https://github.com/rust-lang/cargo/issues/8140.
+
+Patch by Alejandro Enedino Hernandez Samaniego, from his strict-version-hash
+v5 series for openembedded-core:
+https://lists.openembedded.org/g/openembedded-core/topic/120939810
+
+This is the patch carried in rust-source.inc for the cargo binary, applied
+here to the cargo library crate that cargo-c links against, so that
+recipes built through cargo-cbuild get the same behaviour.
+
+Upstream-Status: Inappropriate [OE-specific]
+
+Signed-off-by: Alejandro Enedino Hernandez Samaniego <alejandro@enedino.org>
+Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
+---
+
+diff --git a/src/compiler/build_runner/compilation_files.rs b/src/compiler/build_runner/compilation_files.rs
+index 88cab85..9dbd203 100644
+--- a/src/compiler/build_runner/compilation_files.rs
++++ b/src/compiler/build_runner/compilation_files.rs
+@@ -877,7 +877,7 @@ fn has_remap_path_prefix(args: &[String]) -> bool {
+ }
+ 
+ /// Hash the version of rustc being used during the build process.
+-fn hash_rustc_version(bcx: &BuildContext<'_, '_>, hasher: &mut StableHasher, unit: &Unit) {
++fn hash_rustc_version(bcx: &BuildContext<'_, '_>, hasher: &mut StableHasher, _unit: &Unit) {
+     let vers = &bcx.rustc().version;
+     if vers.pre.is_empty() || bcx.gctx.cli_unstable().separate_nightlies {
+         // For stable, keep the artifacts separate. This helps if someone is
+@@ -886,7 +886,7 @@ fn hash_rustc_version(bcx: &BuildContext<'_, '_>, hasher: &mut StableHasher, uni
+         // omitted since rustc should produce the same output for each target
+         // regardless of the host.
+         for line in bcx.rustc().verbose_version.lines() {
+-            if unit.kind.is_host() || !line.starts_with("host: ") {
++            if !line.starts_with("host: ") {
+                 line.hash(hasher);
+             }
+         }
+@@ -899,12 +899,6 @@ fn hash_rustc_version(bcx: &BuildContext<'_, '_>, hasher: &mut StableHasher, uni
+     // This assumes that the first segment is the important bit ("nightly",
+     // "beta", "dev", etc.). Skip other parts like the `.3` in `-beta.3`.
+     vers.pre.split('.').next().hash(hasher);
+-    // Keep "host" since some people switch hosts to implicitly change
+-    // targets, (like gnu vs musl or gnu vs msvc). In the future, we may want
+-    // to consider hashing `unit.kind.short_name()` instead.
+-    if unit.kind.is_host() {
+-        bcx.rustc().host.hash(hasher);
+-    }
+     // None of the other lines are important. Currently they are:
+     // binary: rustc  <-- or "rustdoc"
+     // commit-hash: 38114ff16e7856f98b2b4be7ab4cd29b38bed59a
+-- 
+2.43.0
diff --git a/meta/recipes-devtools/cargo-c/cargo-c_0.10.26+cargo-0.100.0.bb b/meta/recipes-devtools/cargo-c/cargo-c_0.10.26+cargo-0.100.0.bb
index 722a128d43..37d6a59aca 100644
--- a/meta/recipes-devtools/cargo-c/cargo-c_0.10.26+cargo-0.100.0.bb
+++ b/meta/recipes-devtools/cargo-c/cargo-c_0.10.26+cargo-0.100.0.bb
@@ -7,6 +7,7 @@  LIC_FILES_CHKSUM = " \
 
 SRC_URI = "crate://crates.io/cargo-c/${PV};name=cargo-c \
            file://0001-parking-lot-Use-libc-SYS_futex_time64-on-riscv32.patch;patchdir=../parking_lot_core-0.9.12/ \
+           file://0002-cargo-omit-host-triple-from-unit-metadata-hash.patch;patchdir=../cargo-0.100.0/ \
 "
 SRC_URI[cargo-c.sha256sum] = "5ff6e05531e58286d3c02ec0adb7f254e5d532a8d4b667f30b9942d802e1db25"
 S = "${CARGO_VENDORING_DIRECTORY}/cargo-c-${PV}"