@@ -2050,14 +2050,12 @@ pub fn run_cargo(
20502050 || filename. ends_with ( ".a" )
20512051 || is_debug_info ( & filename)
20522052 || is_dylib ( Path :: new ( & * filename) )
2053+ || filename. ends_with ( ".rmeta" )
20532054 {
2054- // Always keep native libraries, rust dylibs and debuginfo
2055+ // Always keep native libraries, rust dylibs, debuginfo and crate metadata
20552056 keep = true ;
20562057 }
2057- if is_check && filename. ends_with ( ".rmeta" ) {
2058- // During check builds we need to keep crate metadata
2059- keep = true ;
2060- } else if rlib_only_metadata {
2058+ if !is_check && rlib_only_metadata {
20612059 if filename. contains ( "jemalloc_sys" )
20622060 || filename. contains ( "rustc_smir" )
20632061 || filename. contains ( "stable_mir" )
@@ -2069,7 +2067,6 @@ pub fn run_cargo(
20692067 // Distribute the rest of the rustc crates as rmeta files only to reduce
20702068 // the tarball sizes by about 50%. The object files are linked into
20712069 // librustc_driver.so, so it is still possible to link against them.
2072- keep |= filename. ends_with ( ".rmeta" ) ;
20732070 }
20742071 } else {
20752072 // In all other cases keep all rlibs
@@ -2115,7 +2112,12 @@ pub fn run_cargo(
21152112 let file_stem = parts. next ( ) . unwrap ( ) . to_owned ( ) ;
21162113 let extension = parts. next ( ) . unwrap ( ) . to_owned ( ) ;
21172114
2118- toplevel. push ( ( file_stem, extension, expected_len) ) ;
2115+ if extension == "so" || extension == "dylib" {
2116+ // FIXME workaround for the fact that cargo doesn't understand `-Zsplit-metadata`
2117+ toplevel. push ( ( file_stem. clone ( ) , "rmeta" . to_owned ( ) , None ) ) ;
2118+ }
2119+
2120+ toplevel. push ( ( file_stem, extension, Some ( expected_len) ) ) ;
21192121 }
21202122 } ) ;
21212123
@@ -2136,7 +2138,7 @@ pub fn run_cargo(
21362138 . collect :: < Vec < _ > > ( ) ;
21372139 for ( prefix, extension, expected_len) in toplevel {
21382140 let candidates = contents. iter ( ) . filter ( |& ( _, filename, meta) | {
2139- meta. len ( ) == expected_len
2141+ expected_len . is_none_or ( |expected_len| meta. len ( ) == expected_len)
21402142 && filename
21412143 . strip_prefix ( & prefix[ ..] )
21422144 . map ( |s| s. starts_with ( '-' ) && s. ends_with ( & extension[ ..] ) )
@@ -2147,6 +2149,7 @@ pub fn run_cargo(
21472149 } ) ;
21482150 let path_to_add = match max {
21492151 Some ( triple) => triple. 0 . to_str ( ) . unwrap ( ) ,
2152+ None if extension == "rmeta" => continue , // cfg(not(bootstrap)) remove this once -Zsplit-metadata is passed for all stages
21502153 None => panic ! ( "no output generated for {prefix:?} {extension:?}" ) ,
21512154 } ;
21522155 if is_dylib ( Path :: new ( path_to_add) ) {
0 commit comments