mbox series

[0/3] rust/cargo-c: keep the build host out of cargo -C metadata

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

Message

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

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