@@ -2070,14 +2070,12 @@ pub fn run_cargo(
20702070 || filename. ends_with ( ".a" )
20712071 || is_debug_info ( & filename)
20722072 || is_dylib ( & filename)
2073+ || filename. ends_with ( ".rmeta" )
20732074 {
2074- // Always keep native libraries, rust dylibs and debuginfo
2075+ // Always keep native libraries, rust dylibs, debuginfo and crate metadata
20752076 keep = true ;
20762077 }
2077- if is_check && filename. ends_with ( ".rmeta" ) {
2078- // During check builds we need to keep crate metadata
2079- keep = true ;
2080- } else if rlib_only_metadata {
2078+ if !is_check && rlib_only_metadata {
20812079 if filename. contains ( "jemalloc_sys" )
20822080 || filename. contains ( "rustc_smir" )
20832081 || filename. contains ( "stable_mir" )
@@ -2089,7 +2087,6 @@ pub fn run_cargo(
20892087 // Distribute the rest of the rustc crates as rmeta files only to reduce
20902088 // the tarball sizes by about 50%. The object files are linked into
20912089 // librustc_driver.so, so it is still possible to link against them.
2092- keep |= filename. ends_with ( ".rmeta" ) ;
20932090 }
20942091 } else {
20952092 // In all other cases keep all rlibs
@@ -2135,7 +2132,12 @@ pub fn run_cargo(
21352132 let file_stem = parts. next ( ) . unwrap ( ) . to_owned ( ) ;
21362133 let extension = parts. next ( ) . unwrap ( ) . to_owned ( ) ;
21372134
2138- toplevel. push ( ( file_stem, extension, expected_len) ) ;
2135+ if extension == "so" || extension == "dylib" {
2136+ // FIXME workaround for the fact that cargo doesn't understand `-Zsplit-metadata`
2137+ toplevel. push ( ( file_stem. clone ( ) , "rmeta" . to_owned ( ) , None ) ) ;
2138+ }
2139+
2140+ toplevel. push ( ( file_stem, extension, Some ( expected_len) ) ) ;
21392141 }
21402142 } ) ;
21412143
@@ -2156,7 +2158,7 @@ pub fn run_cargo(
21562158 . collect :: < Vec < _ > > ( ) ;
21572159 for ( prefix, extension, expected_len) in toplevel {
21582160 let candidates = contents. iter ( ) . filter ( |& ( _, filename, meta) | {
2159- meta. len ( ) == expected_len
2161+ expected_len . map_or ( true , |expected_len| meta. len ( ) == expected_len)
21602162 && filename
21612163 . strip_prefix ( & prefix[ ..] )
21622164 . map ( |s| s. starts_with ( '-' ) && s. ends_with ( & extension[ ..] ) )
@@ -2167,6 +2169,7 @@ pub fn run_cargo(
21672169 } ) ;
21682170 let path_to_add = match max {
21692171 Some ( triple) => triple. 0 . to_str ( ) . unwrap ( ) ,
2172+ None if extension == "rmeta" => continue , // cfg(not(bootstrap)) remove this once -Zsplit-metadata is passed for all stages
21702173 None => panic ! ( "no output generated for {prefix:?} {extension:?}" ) ,
21712174 } ;
21722175 if is_dylib ( path_to_add) {
0 commit comments