From: Sunil Dora <[email protected]>

HygieneEncodeContext::encode walks a hash set while it writes the syntax
context and expansion records into the rmeta, so the byte order of the
records follows the iteration order of the set and differs between
builds on the arm workers. The added patch sorts both sets before they
are written.

Upstream tracks this as rust-lang/rust issue 129094 and is fixing it
differently in pull request 161450, which is still open, so carry the
sort until that lands.

Patch from Alejandro Enedino Hernandez Samaniego's strict-version-hash
series:
https://lists.openembedded.org/g/openembedded-core/topic/120939810

[YOCTO #16376]

Signed-off-by: Sunil Dora <[email protected]>
---
 ...hygiene-encoding-order-deterministic.patch | 58 +++++++++++++++++++
 meta/recipes-devtools/rust/rust-source.inc    |  1 +
 2 files changed, 59 insertions(+)
 create mode 100644 
meta/recipes-devtools/rust/files/0009-rustc-span-make-hygiene-encoding-order-deterministic.patch

diff --git 
a/meta/recipes-devtools/rust/files/0009-rustc-span-make-hygiene-encoding-order-deterministic.patch
 
b/meta/recipes-devtools/rust/files/0009-rustc-span-make-hygiene-encoding-order-deterministic.patch
new file mode 100644
index 0000000000..dddb1c99ba
--- /dev/null
+++ 
b/meta/recipes-devtools/rust/files/0009-rustc-span-make-hygiene-encoding-order-deterministic.patch
@@ -0,0 +1,58 @@
+From 9c190d14f93bf27c7f1c94d400cda6f48f285a34 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] rust: sort syntax contexts and expansions before encoding
+
+HygieneEncodeContext encodes the pending syntax contexts and expansions in
+hash-map order, so the encoded rmeta depends on the build host. Sort both
+before encoding. Upstream is fixing the same problem with a different
+approach in https://github.com/rust-lang/rust/pull/161450, which is still
+open, so this is a local fix rather than a backport of it.
+
+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
+
+Upstream-Status: Inappropriate [OE-specific]
+
+Signed-off-by: Alejandro Enedino Hernandez Samaniego <[email protected]>
+Signed-off-by: Sunil Dora <[email protected]>
+---
+ compiler/rustc_span/src/hygiene.rs | 10 ++++++----
+ 1 file changed, 6 insertions(+), 4 deletions(-)
+
+diff --git a/compiler/rustc_span/src/hygiene.rs 
b/compiler/rustc_span/src/hygiene.rs
+index 1c74205..a464eca 100644
+--- a/compiler/rustc_span/src/hygiene.rs
++++ b/compiler/rustc_span/src/hygiene.rs
+@@ -1313,12 +1313,12 @@ impl HygieneEncodeContext {
+ 
+             // Consume the current round of syntax contexts.
+             // Drop the lock() temporary early.
+-            // It's fine to iterate over a HashMap, because the serialization 
of the table
+-            // that we insert data into doesn't depend on insertion order.
+             #[allow(rustc::potential_query_instability)]
+-            let latest_ctxts = { mem::take(&mut *self.latest_ctxts.lock()) 
}.into_iter();
++            let mut latest_ctxts: Vec<_> = { mem::take(&mut 
*self.latest_ctxts.lock()) }.into_iter().collect();
++            latest_ctxts.sort_by_key(|ctxt| ctxt.0);
+             let all_ctxt_data: Vec<_> = HygieneData::with(|data| {
+                 latest_ctxts
++                    .into_iter()
+                     .map(|ctxt| (ctxt, data.syntax_context_data[ctxt.0 as 
usize].key()))
+                     .collect()
+             });
+@@ -1330,9 +1330,11 @@ impl HygieneEncodeContext {
+ 
+             // Same as above, but for expansions instead of syntax contexts.
+             #[allow(rustc::potential_query_instability)]
+-            let latest_expns = { mem::take(&mut *self.latest_expns.lock()) 
}.into_iter();
++            let mut latest_expns: Vec<_> = { mem::take(&mut 
*self.latest_expns.lock()) }.into_iter().collect();
++            latest_expns.sort_by_key(|expn| (expn.krate, expn.local_id));
+             let all_expn_data: Vec<_> = HygieneData::with(|data| {
+                 latest_expns
++                    .into_iter()
+                     .map(|expn| (expn, data.expn_data(expn).clone(), 
data.expn_hash(expn)))
+                     .collect()
+             });
+-- 
+2.43.0
diff --git a/meta/recipes-devtools/rust/rust-source.inc 
b/meta/recipes-devtools/rust/rust-source.inc
index a50a3fd001..562f4afb65 100644
--- a/meta/recipes-devtools/rust/rust-source.inc
+++ b/meta/recipes-devtools/rust/rust-source.inc
@@ -11,6 +11,7 @@ SRC_URI += 
"https://static.rust-lang.org/dist/rustc-${RUST_VERSION}-src.tar.xz;n
             
file://0005-rustc_codegen_llvm-Do-not-pass-amx-tf32-to-LLVM-23.patch;patchdir=${RUSTSRC}
 \
             
file://0007-cargo-omit-host-triple-from-unit-metadata-hash.patch;patchdir=${RUSTSRC}
 \
             
file://0008-rustc-hir-make-doc-link-metadata-order-deterministic.patch;patchdir=${RUSTSRC}
 \
+            
file://0009-rustc-span-make-hygiene-encoding-order-deterministic.patch;patchdir=${RUSTSRC}
 \
 "
 SRC_URI[rust.sha256sum] = 
"be1816e7f6c40abb90245ad6e024bed2a7e88d7dda4561e4d5470207df616b9f"
 
-- 
2.43.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#245847): 
https://lists.openembedded.org/g/openembedded-core/message/245847
Mute This Topic: https://lists.openembedded.org/mt/121261381/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

  • [OE-core] [PATCH ... Dora, Sunil Kumar via lists.openembedded.org
    • [OE-core] [P... Dora, Sunil Kumar via lists.openembedded.org
    • [OE-core] [P... Dora, Sunil Kumar via lists.openembedded.org
    • [OE-core] [P... Dora, Sunil Kumar via lists.openembedded.org
    • Re: [OE-core... Alejandro Hernandez Samaniego via lists.openembedded.org
      • Re: [OE-... Dora, Sunil Kumar via lists.openembedded.org
      • Re: [OE-... Dora, Sunil Kumar via lists.openembedded.org
      • Re: [OE-... Antonin Godard via lists.openembedded.org
      • Re: [OE-... Richard Purdie via lists.openembedded.org
        • Re: ... Alejandro Hernandez Samaniego via lists.openembedded.org
    • [OE-core] [P... Dora, Sunil Kumar via lists.openembedded.org
    • [OE-core] [P... Dora, Sunil Kumar via lists.openembedded.org

Reply via email to