$OpenBSD: patch-src_bootstrap_builder_rs,v 1.17 2021/03/27 10:02:11 semarie Exp $
Pass the information that we want to override metadata (on final stage)
Index: src/bootstrap/builder.rs
--- src/bootstrap/builder.rs.orig
+++ src/bootstrap/builder.rs
@@ -1353,6 +1353,28 @@ impl<'a> Builder<'a> {
             );
         }
 
+        // Inform underline cargo that it should uses LIBR_METADATA_xxx hash if present
+        if compiler.is_final_stage(self) {
+            match mode {
+                Mode::Std => {
+                    cargo.env("OPENBSD_PORTS_LANG_RUST", "1");
+                },
+                Mode::Rustc => {
+                    cargo.env("OPENBSD_PORTS_LANG_RUST", "1");
+
+                    cargo.env_remove("LIBR_METADATA_adler");
+                    cargo.env_remove("LIBR_METADATA_cfg_if");
+                    cargo.env_remove("LIBR_METADATA_getopts");
+                    cargo.env_remove("LIBR_METADATA_hashbrown");
+                    cargo.env_remove("LIBR_METADATA_libc");
+                    cargo.env_remove("LIBR_METADATA_miniz_oxide");
+                    cargo.env_remove("LIBR_METADATA_rustc_demangle");
+                    cargo.env_remove("LIBR_METADATA_unicode_width");
+                },
+                _ => { },
+            }
+        }
+
         // If Control Flow Guard is enabled, pass the `control-flow-guard` flag to rustc
         // when compiling the standard library, since this might be linked into the final outputs
         // produced by rustc. Since this mitigation is only available on Windows, only enable it
@@ -1490,7 +1512,7 @@ impl<'a> Builder<'a> {
                 for el in stack.iter().rev() {
                     out += &format!("\t{:?}\n", el);
                 }
-                panic!(out);
+                panic!("{}", out);
             }
             if let Some(out) = self.cache.get(&step) {
                 self.verbose(&format!("{}c {:?}", "  ".repeat(stack.len()), step));
