@@ -703,14 +703,19 @@ fn compute_metadata(
703703 // Avoid trashing the caches on RUSTFLAGS changing via `c_extra_filename`
704704 //
705705 // Limited to `c_extra_filename` to help with reproducible build / PGO issues.
706- build_runner
707- . bcx
708- . extra_args_for ( unit)
709- . hash ( & mut c_extra_filename_hasher) ;
706+ let default = Vec :: new ( ) ;
707+ let extra_args = build_runner. bcx . extra_args_for ( unit) . unwrap_or ( & default) ;
708+ if !has_remap_path_prefix ( & extra_args) {
709+ extra_args. hash ( & mut c_extra_filename_hasher) ;
710+ }
710711 if unit. mode . is_doc ( ) || unit. mode . is_doc_scrape ( ) {
711- unit. rustdocflags . hash ( & mut c_extra_filename_hasher) ;
712+ if !has_remap_path_prefix ( & unit. rustdocflags ) {
713+ unit. rustdocflags . hash ( & mut c_extra_filename_hasher) ;
714+ }
712715 } else {
713- unit. rustflags . hash ( & mut c_extra_filename_hasher) ;
716+ if !has_remap_path_prefix ( & unit. rustflags ) {
717+ unit. rustflags . hash ( & mut c_extra_filename_hasher) ;
718+ }
714719 }
715720
716721 let c_metadata = UnitHash ( c_metadata_hasher. finish ( ) ) ;
@@ -726,6 +731,20 @@ fn compute_metadata(
726731 }
727732}
728733
734+ /// HACK: Detect the *potential* presence of `--remap-path-prefix`
735+ ///
736+ /// As CLI parsing is contextual and dependent on the CLI definition to understand the context, we
737+ /// can't say for sure whether `--remap-path-prefix` is present, so we guess if anything looks like
738+ /// it.
739+ /// If we could, we'd strip it out for hashing.
740+ /// Instead, we use this to avoid hashing rustflags if it might be present to avoid the risk of taking
741+ /// a flag that is trying to make things reproducible and making things less reproducible by the
742+ /// `-Cextra-filename` showing up in the rlib, even with `split-debuginfo`.
743+ fn has_remap_path_prefix ( args : & [ String ] ) -> bool {
744+ args. iter ( )
745+ . any ( |s| s. starts_with ( "--remap-path-prefix=" ) || s == "--remap-path-prefix" )
746+ }
747+
729748/// Hash the version of rustc being used during the build process.
730749fn hash_rustc_version ( bcx : & BuildContext < ' _ , ' _ > , hasher : & mut StableHasher , unit : & Unit ) {
731750 let vers = & bcx. rustc ( ) . version ;
0 commit comments