Skip to contentSkip to conversation

rust/cargo-c: keep the build host out of cargo -C metadata

PATCH In review [email protected] 2 participants 6 messages Nov 5 – Nov 10

lore
Share & tools
lore
#0 lore raw

cover rust/cargo-c: keep the build host out of cargo -C metadata

From: Sunil Dora <[email protected]>

This series is for the remaining rust part of [YOCTO #16376]. On the reproducible-arm (121) and reproducible-arm-cross (119) builders the rust-rustdoc and librust-lib-example packages come out different from the x86_64 build. The reason is in cargo, not in rustc.

cargo builds the -C metadata of a crate from the -C metadata of all its dependencies, including the build script and the proc-macros. Those are resolved for the build host, so their dependency graph can change with the host. For rustdoc the build script depends on sha2 -> cpufeatures, and cpufeatures pulls in libc only on aarch64-linux. That one extra crate changes the hash of the build script, then of librustdoc, and with it every symbol name in rustdoc.

Patches:
1/3 cargo-c: the host-triple fix we already carry in rust/files/0004
never reached cargo-c, because cargo-c links its own copy of the cargo crate. Carry the same patch for cargo-0.100.0. This one is about unit_id (file names, OUT_DIR); 3/3 is about -C metadata.
2/3 rust: carry the fix I sent upstream (rust-lang/cargo#17522). For a
target unit, host-kind dependencies contribute only their package id to -C metadata. unit_id, -C extra-filename and fingerprints are not changed, so file names and rebuilds stay as they are.
3/3 cargo-c: same fix for the cargo crate in cargo-c.

Testing:
- Autobuilder run with these changes (x86_64 vs aarch64 sides confirmed).
- Built cargo-native, cargo-c-native, rust and rust-c-lib-example for qemuarm64.
- Local check on one x86_64 machine: with a rustc wrapper that reports aarch64 as the host, a crate with sha2 as build-dependency gets a different -C metadata from OE's cargo and cargo-cbuild without the series, and the same value with it.
- The upstream PR also has a cargo testsuite test for this. It is not carried here.

Upstream: rust-lang/cargo#17522[1] is still a draft. The discussion is in rust-lang/cargo#8140[2]. On the rustc side there was no objection to dropping build deps from -C metadata of the main crate, but the cargo team would prefer to handle this as part of a bigger rework of fingerprinting (rust-lang/cargo#17439)[3]. So I expect we have to carry these for a while. They should be dropped on the rust / cargo-c upgrade that has the upstream fix.

Not fixed by this series (still differing on the arm builders):
- rust, rust-dbg: this is on the rustc side (proc-macro host_hash in the rmeta, and one crate hash). Working on it separately.
- librpm-sequoia: symbols are identical now, but three strings still have the build script OUT_DIR hash in them. 1/3 takes the host triple out of that hash, but the host side dependency graph still goes into unit_id, and cargo keeps that host dependent on purpose.

[1] https://github.com/rust-lang/cargo/pull/17522/
[2] https://github.com/rust-lang/cargo/issues/8140
[3] https://github.com/rust-lang/cargo/issues/17439

Sunil Dora (3):
cargo-c: keep the build host triple out of cargo unit metadata
rust: keep host-kind dependency metadata out of target -C metadata
cargo-c: keep host-kind dependency metadata out of target -C metadata

 ...-host-triple-from-unit-metadata-hash.patch |  64 +++++++++
 ...ps-out-of-the-target-C-metadata-hash.patch | 123 ++++++++++++++++++
 .../cargo-c/cargo-c_0.10.26+cargo-0.100.0.bb  |   2 +
 ...ps-out-of-the-target-C-metadata-hash.patch | 123 ++++++++++++++++++
 meta/recipes-devtools/rust/rust-source.inc    |   1 +
 5 files changed, 313 insertions(+)
 create mode 100644 meta/recipes-devtools/cargo-c/cargo-c/0002-cargo-omit-host-triple-from-unit-metadata-hash.patch
 create mode 100644 meta/recipes-devtools/cargo-c/cargo-c/0003-cargo-keep-host-deps-out-of-the-target-C-metadata-hash.patch
 create mode 100644 meta/recipes-devtools/rust/files/0006-cargo-keep-host-deps-out-of-the-target-C-metadata-hash.patch
Signature · 1 line
2.49.0
#1 lore raw

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

From: Sunil Dora <[email protected]>

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]

---
 ...-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
meta/recipes-devtools/cargo-c/cargo-c/0002-cargo-omit-host-triple-from-unit-metadata-hash.patch new file +64 -0
new file mode 100644
index 0000000000..339317d486
@@ -0,0 +1,64 @@
+From 5c4fd7d8b85f4de5be387777a782fc3ddd1227d8 Mon Sep 17 00:00:00 2001
+From: Alejandro Enedino Hernandez Samaniego <[email protected]>
+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 <[email protected]>
+Signed-off-by: Sunil Dora <[email protected]>
+---
+
+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
meta/recipes-devtools/cargo-c/cargo-c_0.10.26+cargo-0.100.0.bb +1 -0
index 722a128d43..37d6a59aca 100644
@@ -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}"
Signature · 1 line
2.49.0
#2 lore raw

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

Quoted 15 lines · On 2026-11-05 06:32, [email protected] wrote:

From: Sunil Dora<[email protected]>

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.

Quoted 6 lines

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.

Huh?

That patch is still there.
https://git.openembedded.org/openembedded-core/tree/meta/recipes-devtools/rust/files/0004-cargo-omit-host-triple-from-unit-metadata-hash.patch

What do you mean or is this a comment that should be removed?

In general, this patch series is good but maybe you need to review the commit logs.

../Randy

Quoted 92 lines

[YOCTO #16376]

---
  ...-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

meta/recipes-devtools/cargo-c/cargo-c/0002-cargo-omit-host-triple-from-unit-metadata-hash.patch new file +64 -0
new file mode 100644
index 0000000000..339317d486
@@ -0,0 +1,64 @@
+From 5c4fd7d8b85f4de5be387777a782fc3ddd1227d8 Mon Sep 17 00:00:00 2001
+From: Alejandro Enedino Hernandez Samaniego<[email protected]>
+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<[email protected]>
+Signed-off-by: Sunil Dora<[email protected]>
+---
+
+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
meta/recipes-devtools/cargo-c/cargo-c_0.10.26+cargo-0.100.0.bb +1 -0
index 722a128d43..37d6a59aca 100644
@@ -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}"
Signature · 2 lines
# Randy MacLeod
# Wind River Linux
#3 lore raw

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

Hi Randy,

Quoted 24 lines · Randy
Quoted 15 lines · On 2026-11-05 06:32, [email protected] wrote:

From: Sunil Dora<[email protected]>

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.

Quoted 6 lines

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.

Quoted 8 lines

Huh?

That patch is still there.
https://git.openembedded.org/openembedded-core/tree/meta/recipes-
devtools/rust/files/0004-cargo-omit-host-triple-from-unit-metadata- hash.patch

What do you mean or is this a comment that should be removed?

Sorry, I worded that badly. Nothing is being dropped now. I meant it as a note for the future: this cargo-c patch is a copy of the rust/files/0004 patch, so whenever that one gets removed or updated (say, once upstream cargo stops hashing the host triple), the cargo-c copy should be removed or updated along with it. I did not want somebody to clean up one and forget the other.

Reading it again, I agree it sounds like the 0004 patch is already gone, or that this patch itself should be dropped. Same wording is at the end of 3/3 as well.

Quoted 3 lines

In general, this patch series is good but maybe you need to review the commit logs.

Will do. I will go through all three commit logs once more and send a v2 with the wording fixed.

Quoted 103 lines

../Randy

Quoted 93 lines

[YOCTO #16376]

---
  ...-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

meta/recipes-devtools/cargo-c/cargo-c/0002-cargo-omit-host-triple-from-unit-metadata-hash.patch new file +64 -0
new file mode 100644
index 0000000000..339317d486
@@ -0,0 +1,64 @@
+From 5c4fd7d8b85f4de5be387777a782fc3ddd1227d8 Mon Sep 17 00:00:00 2001
+From: Alejandro Enedino Hernandez Samaniego<[email protected]>
+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<[email protected]>
+Signed-off-by: Sunil Dora<[email protected]>
+---
+
+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
meta/recipes-devtools/cargo-c/cargo-c_0.10.26+cargo-0.100.0.bb +1 -0
index 722a128d43..37d6a59aca 100644
@@ -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}"
Signature · 2 lines
# Randy MacLeod
# Wind River Linux
#4 lore raw

PATCH 2/3 rust: keep host-kind dependency metadata out of target -C metadata

In reply to [email protected]

From: Sunil Dora <[email protected]>

On the autobuilder the rust-rustdoc and librust-lib-example packages were not reproducible between the x86_64 and the aarch64 workers. Every symbol of librustdoc had a different hash on the aarch64 host, nothing else in the package was different.

The reason is in how cargo computes -C metadata for a crate. It mixes in the -C metadata of all the dependencies of the crate, including the build script and the proc-macros. Those are built for the build host, so their dependency tree can differ from one host to another.

For rustdoc the build script depends on sha2 -> cpufeatures, and cpufeatures pulls in libc only on aarch64-linux. That one extra crate changes the hash of the build script, from there the hash of librustdoc itself, and with it every symbol in it.

Carry the fix sent upstream (rust-lang/cargo#17522)[1]: for a target unit, host-kind dependencies contribute only their package id to -C metadata instead of their full hash. They are not linked into the target artifact anyway, so nothing is lost. unit_id, -C extra-filename and fingerprints are not touched, so file names and rebuild decisions stay as they are. Host units and builds without --target are not affected.

The upstream discussion is in rust-lang/cargo#8140[2]. The PR is still a draft, the cargo team would rather solve this as part of a bigger rework of fingerprinting (rust-lang/cargo#17439)[3], so we may have to carry this for some time. Drop it on the rust upgrade that has the fix.

[YOCTO #16376]

[1] https://github.com/rust-lang/cargo/pull/17522/
[2] https://github.com/rust-lang/cargo/issues/8140
[3] https://github.com/rust-lang/cargo/issues/17439

---
 ...ps-out-of-the-target-C-metadata-hash.patch | 123 ++++++++++++++++++
 meta/recipes-devtools/rust/rust-source.inc    |   1 +
 2 files changed, 124 insertions(+)
 create mode 100644 meta/recipes-devtools/rust/files/0006-cargo-keep-host-deps-out-of-the-target-C-metadata-hash.patch
meta/recipes-devtools/rust/files/0006-cargo-keep-host-deps-out-of-the-target-C-metadata-hash.patch new file +123 -0
new file mode 100644
index 0000000000..5e796b0164
@@ -0,0 +1,123 @@
+From f936d6a954455eff3a60968d155852f9de730228 Mon Sep 17 00:00:00 2001
+From: Sunil Dora <[email protected]>
+Date: Sun, 27 Sep 2026 08:47:23 +0530
+Subject: [PATCH] fix(compile): Keep host deps out of the target `-C metadata`
+ hash
+
+A target unit's `-C metadata` mixed in the `c_metadata` of its
+host-kind dependencies (build scripts, proc-macros). Their dependency
+graph depends on the host `cfg`, e.g. `cpufeatures` pulls in `libc`
+only on aarch64-linux, so the build host leaked into the symbols of
+cross-compiled crates such as rustdoc.
+
+Host-kind dependencies are not linked into the target artifact, so use
+their package id instead. `unit_id`, `-C extra-filename` and
+fingerprints are unchanged, as are host units and builds without
+`--target`. The upstream PR also adds a testsuite test that fakes the
+reported host; it is not carried here.
+
+Upstream-Status: Submitted [https://github.com/rust-lang/cargo/pull/17522]
+Signed-off-by: Sunil Dora <[email protected]>
+---
+
+diff --git a/src/tools/cargo/src/compiler/build_runner/compilation_files.rs b/src/tools/cargo/src/compiler/build_runner/compilation_files.rs
+index 593e57e..63855f3 100644
+--- a/src/tools/cargo/src/compiler/build_runner/compilation_files.rs
++++ b/src/tools/cargo/src/compiler/build_runner/compilation_files.rs
+@@ -89,6 +89,8 @@ impl fmt::Debug for UnitHash {
+ /// mangled symbols need to be stable between different builds with different
+ /// settings. For example, profile-guided optimizations need to swap
+ /// `RUSTFLAGS` between runs, but needs to keep the same symbol names.
++/// Likewise a target unit only mixes the package id of its host-kind
++/// dependencies into `c_metadata`, see `compute_metadata`.
+ #[derive(Copy, Clone, Debug)]
+ pub struct Metadata {
+     unit_id: UnitHash,
+@@ -744,7 +746,7 @@ fn compute_metadata(
+     let deps_metadata = build_runner
+         .unit_deps(unit)
+         .iter()
+-        .map(|dep| *metadata_of(&dep.unit, build_runner, metas))
++        .map(|dep| (&dep.unit, *metadata_of(&dep.unit, build_runner, metas)))
+         .collect::<Vec<_>>();
+     let c_extra_filename = use_extra_filename(bcx, unit);
+     let pkg_dir = use_pkg_dir(bcx, unit);
+@@ -843,16 +845,28 @@ fn compute_metadata(
+ 
+     let mut c_metadata_hasher = shared_hasher.clone();
+     // Mix in the target-metadata of all the dependencies of this target.
++    // Host-kind deps of a target unit (build scripts, proc-macros) are not
++    // linked into it, and their metadata depends on the build host, so use
++    // a host independent stand-in for them (rust-lang/cargo#8140).
+     let mut dep_c_metadata_hashes = deps_metadata
+         .iter()
+-        .map(|m| m.c_metadata)
++        .map(|(dep, m)| {
++            if !unit.kind.is_host() && dep.kind.is_host() {
++                host_independent_c_metadata(dep, ws_root)
++            } else {
++                m.c_metadata
++            }
++        })
+         .collect::<Vec<_>>();
+     dep_c_metadata_hashes.sort();
+     dep_c_metadata_hashes.hash(&mut c_metadata_hasher);
+ 
+     let mut unit_id_hasher = shared_hasher.clone();
+     // Mix in the target-metadata of all the dependencies of this target.
+-    let mut dep_unit_id_hashes = deps_metadata.iter().map(|m| m.unit_id).collect::<Vec<_>>();
++    let mut dep_unit_id_hashes = deps_metadata
++        .iter()
++        .map(|(_, m)| m.unit_id)
++        .collect::<Vec<_>>();
+     dep_unit_id_hashes.sort();
+     dep_unit_id_hashes.hash(&mut unit_id_hasher);
+     // Avoid trashing the caches on RUSTFLAGS changing via `unit_id`
+@@ -884,6 +898,15 @@ fn compute_metadata(
+     }
+ }
+ 
++/// Stand-in `c_metadata` for a host-kind dependency of a target unit:
++/// only the dependency's package id, see `compute_metadata`.
++fn host_independent_c_metadata(dep: &Unit, ws_root: &Path) -> UnitHash {
++    let mut hasher = StableHasher::new();
++    METADATA_VERSION.hash(&mut hasher);
++    dep.pkg.package_id().stable_hash(ws_root).hash(&mut hasher);
++    UnitHash(Hasher::finish(&hasher))
++}
++
+ /// HACK: Detect the *potential* presence of `--remap-path-prefix`
+ ///
+ /// As CLI parsing is contextual and dependent on the CLI definition to understand the context, we
+diff --git a/src/tools/cargo/src/compiler/fingerprint/mod.rs b/src/tools/cargo/src/compiler/fingerprint/mod.rs
+index 172165d..d7f1e55 100644
+--- a/src/tools/cargo/src/compiler/fingerprint/mod.rs
++++ b/src/tools/cargo/src/compiler/fingerprint/mod.rs
+@@ -74,7 +74,7 @@
+ //! `TargetKind` (bin/lib/etc.)                | ✓           | ✓                        | ✓
+ //! Enabled Features                           | ✓           | ✓                        | ✓
+ //! Declared Features                          | ✓           |                          |
+-//! Immediate dependency’s hashes              | ✓[^1]       | ✓                        | ✓
++//! Immediate dependency’s hashes              | ✓[^1]       | ✓                        | ✓[^9]
+ //! [`CompileKind`] (host/target)              | ✓           | ✓                        | ✓
+ //! `__CARGO_DEFAULT_LIB_METADATA`[^4]         |             | ✓                        | ✓
+ //! `__CARGO_RUSTC_BOOTSTRAP_WS_REMAP`[^2]     | ✓           |                          |
+@@ -91,7 +91,7 @@
+ //! `[lints.rust.unexpected_cfgs.check-cfg]`   | ✓           |                          |
+ //! `--extern priv:`                           | ✓           |                          |
+ //!
+-//! [^1]: Bin dependencies are not included.
++//! [^1]: Bin dependencies other than artifact dependencies are not included.
+ //!
+ //! [^2]: `__CARGO_RUSTC_BOOTSTRAP_WS_REMAP` is set by rustc bootstrap
+ //!       to customize remap-path-prefix
+@@ -111,6 +111,9 @@
+ //!
+ //! [^8]: including `-Cextra-filename`
+ //!
++//! [^9]: For a target-kind unit, host-kind dependencies (build scripts,
++//!       proc-macros) contribute only their `package_id`.
++//!
+ //! When deciding what should go in the Metadata vs the Fingerprint, consider
+ //! that some files (like dylibs) do not have a hash in their filename. Thus,
+ //! if a value changes, only the fingerprint will detect the change (consider,
meta/recipes-devtools/rust/rust-source.inc +1 -0
index b384a0c76e..42d45a1ca6 100644
@@ -8,6 +8,7 @@ SRC_URI += "https://static.rust-lang.org/dist/rustc-${RUST_VERSION}-src.tar.xz;n
             file://0003-bootstrap-skip-StdarchVerify-when-remote-testing.patch;patchdir=${RUSTSRC} \
             file://0004-cargo-omit-host-triple-from-unit-metadata-hash.patch;patchdir=${RUSTSRC} \
             file://0005-rustc-span-make-hygiene-encoding-order-deterministic.patch;patchdir=${RUSTSRC} \
+            file://0006-cargo-keep-host-deps-out-of-the-target-C-metadata-hash.patch;patchdir=${RUSTSRC} \
 "
 SRC_URI[rust.sha256sum] = "6451598a99e77f07571960f6b21d577399d3a30f33e80cbd2e3a4aae6535d265"
 
Signature · 1 line
2.49.0
#5 lore raw

PATCH 3/3 cargo-c: keep host-kind dependency metadata out of target -C metadata

In reply to [email protected]

From: Sunil Dora <[email protected]>

Same fix as rust/files/0006-cargo-keep-host-deps-*.patch (rust-lang/cargo#17522)[1], for the cargo crate that cargo-c links.

Without it cargo-cbuild still mixes the hashes of the host side dependencies (build script, proc-macros) into the -C metadata of target crates, so the symbol names depend on the build host. Only the paths differ from the rust copy.

Drop this together with rust/files/0006-cargo-keep-host-deps-*.patch.

[YOCTO #16376]

[1] https://github.com/rust-lang/cargo/pull/17522/

---
 ...ps-out-of-the-target-C-metadata-hash.patch | 123 ++++++++++++++++++
 .../cargo-c/cargo-c_0.10.26+cargo-0.100.0.bb  |   1 +
 2 files changed, 124 insertions(+)
 create mode 100644 meta/recipes-devtools/cargo-c/cargo-c/0003-cargo-keep-host-deps-out-of-the-target-C-metadata-hash.patch
meta/recipes-devtools/cargo-c/cargo-c/0003-cargo-keep-host-deps-out-of-the-target-C-metadata-hash.patch new file +123 -0
new file mode 100644
index 0000000000..a3caaa609e
@@ -0,0 +1,123 @@
+From f936d6a954455eff3a60968d155852f9de730228 Mon Sep 17 00:00:00 2001
+From: Sunil Dora <[email protected]>
+Date: Sun, 27 Sep 2026 08:47:23 +0530
+Subject: [PATCH] fix(compile): Keep host deps out of the target `-C metadata`
+ hash
+
+A target unit's `-C metadata` mixed in the `c_metadata` of its
+host-kind dependencies (build scripts, proc-macros). Their dependency
+graph depends on the host `cfg`, e.g. `cpufeatures` pulls in `libc`
+only on aarch64-linux, so the build host leaked into the symbols of
+cross-compiled crates such as rustdoc.
+
+Host-kind dependencies are not linked into the target artifact, so use
+their package id instead. `unit_id`, `-C extra-filename` and
+fingerprints are unchanged, as are host units and builds without
+`--target`. The upstream PR also adds a testsuite test that fakes the
+reported host; it is not carried here.
+
+Upstream-Status: Submitted [https://github.com/rust-lang/cargo/pull/17522]
+Signed-off-by: Sunil Dora <[email protected]>
+---
+
+diff --git a/src/compiler/build_runner/compilation_files.rs b/src/compiler/build_runner/compilation_files.rs
+index 593e57e..63855f3 100644
+--- a/src/compiler/build_runner/compilation_files.rs
++++ b/src/compiler/build_runner/compilation_files.rs
+@@ -89,6 +89,8 @@ impl fmt::Debug for UnitHash {
+ /// mangled symbols need to be stable between different builds with different
+ /// settings. For example, profile-guided optimizations need to swap
+ /// `RUSTFLAGS` between runs, but needs to keep the same symbol names.
++/// Likewise a target unit only mixes the package id of its host-kind
++/// dependencies into `c_metadata`, see `compute_metadata`.
+ #[derive(Copy, Clone, Debug)]
+ pub struct Metadata {
+     unit_id: UnitHash,
+@@ -744,7 +746,7 @@ fn compute_metadata(
+     let deps_metadata = build_runner
+         .unit_deps(unit)
+         .iter()
+-        .map(|dep| *metadata_of(&dep.unit, build_runner, metas))
++        .map(|dep| (&dep.unit, *metadata_of(&dep.unit, build_runner, metas)))
+         .collect::<Vec<_>>();
+     let c_extra_filename = use_extra_filename(bcx, unit);
+     let pkg_dir = use_pkg_dir(bcx, unit);
+@@ -843,16 +845,28 @@ fn compute_metadata(
+ 
+     let mut c_metadata_hasher = shared_hasher.clone();
+     // Mix in the target-metadata of all the dependencies of this target.
++    // Host-kind deps of a target unit (build scripts, proc-macros) are not
++    // linked into it, and their metadata depends on the build host, so use
++    // a host independent stand-in for them (rust-lang/cargo#8140).
+     let mut dep_c_metadata_hashes = deps_metadata
+         .iter()
+-        .map(|m| m.c_metadata)
++        .map(|(dep, m)| {
++            if !unit.kind.is_host() && dep.kind.is_host() {
++                host_independent_c_metadata(dep, ws_root)
++            } else {
++                m.c_metadata
++            }
++        })
+         .collect::<Vec<_>>();
+     dep_c_metadata_hashes.sort();
+     dep_c_metadata_hashes.hash(&mut c_metadata_hasher);
+ 
+     let mut unit_id_hasher = shared_hasher.clone();
+     // Mix in the target-metadata of all the dependencies of this target.
+-    let mut dep_unit_id_hashes = deps_metadata.iter().map(|m| m.unit_id).collect::<Vec<_>>();
++    let mut dep_unit_id_hashes = deps_metadata
++        .iter()
++        .map(|(_, m)| m.unit_id)
++        .collect::<Vec<_>>();
+     dep_unit_id_hashes.sort();
+     dep_unit_id_hashes.hash(&mut unit_id_hasher);
+     // Avoid trashing the caches on RUSTFLAGS changing via `unit_id`
+@@ -884,6 +898,15 @@ fn compute_metadata(
+     }
+ }
+ 
++/// Stand-in `c_metadata` for a host-kind dependency of a target unit:
++/// only the dependency's package id, see `compute_metadata`.
++fn host_independent_c_metadata(dep: &Unit, ws_root: &Path) -> UnitHash {
++    let mut hasher = StableHasher::new();
++    METADATA_VERSION.hash(&mut hasher);
++    dep.pkg.package_id().stable_hash(ws_root).hash(&mut hasher);
++    UnitHash(Hasher::finish(&hasher))
++}
++
+ /// HACK: Detect the *potential* presence of `--remap-path-prefix`
+ ///
+ /// As CLI parsing is contextual and dependent on the CLI definition to understand the context, we
+diff --git a/src/compiler/fingerprint/mod.rs b/src/compiler/fingerprint/mod.rs
+index 172165d..d7f1e55 100644
+--- a/src/compiler/fingerprint/mod.rs
++++ b/src/compiler/fingerprint/mod.rs
+@@ -74,7 +74,7 @@
+ //! `TargetKind` (bin/lib/etc.)                | ✓           | ✓                        | ✓
+ //! Enabled Features                           | ✓           | ✓                        | ✓
+ //! Declared Features                          | ✓           |                          |
+-//! Immediate dependency’s hashes              | ✓[^1]       | ✓                        | ✓
++//! Immediate dependency’s hashes              | ✓[^1]       | ✓                        | ✓[^9]
+ //! [`CompileKind`] (host/target)              | ✓           | ✓                        | ✓
+ //! `__CARGO_DEFAULT_LIB_METADATA`[^4]         |             | ✓                        | ✓
+ //! `__CARGO_RUSTC_BOOTSTRAP_WS_REMAP`[^2]     | ✓           |                          |
+@@ -91,7 +91,7 @@
+ //! `[lints.rust.unexpected_cfgs.check-cfg]`   | ✓           |                          |
+ //! `--extern priv:`                           | ✓           |                          |
+ //!
+-//! [^1]: Bin dependencies are not included.
++//! [^1]: Bin dependencies other than artifact dependencies are not included.
+ //!
+ //! [^2]: `__CARGO_RUSTC_BOOTSTRAP_WS_REMAP` is set by rustc bootstrap
+ //!       to customize remap-path-prefix
+@@ -111,6 +111,9 @@
+ //!
+ //! [^8]: including `-Cextra-filename`
+ //!
++//! [^9]: For a target-kind unit, host-kind dependencies (build scripts,
++//!       proc-macros) contribute only their `package_id`.
++//!
+ //! When deciding what should go in the Metadata vs the Fingerprint, consider
+ //! that some files (like dylibs) do not have a hash in their filename. Thus,
+ //! if a value changes, only the fingerprint will detect the change (consider,
meta/recipes-devtools/cargo-c/cargo-c_0.10.26+cargo-0.100.0.bb +1 -0
index 37d6a59aca..be69393a7a 100644
@@ -8,6 +8,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/ \
+           file://0003-cargo-keep-host-deps-out-of-the-target-C-metadata-hash.patch;patchdir=../cargo-0.100.0/ \
 "
 SRC_URI[cargo-c.sha256sum] = "5ff6e05531e58286d3c02ec0adb7f254e5d532a8d4b667f30b9942d802e1db25"
 S = "${CARGO_VENDORING_DIRECTORY}/cargo-c-${PV}"
Signature · 1 line
2.49.0