@@ -2072,14 +2072,12 @@ pub fn run_cargo(
20722072 || filename. ends_with ( ".a" )
20732073 || is_debug_info ( & filename)
20742074 || is_dylib ( Path :: new ( & * filename) )
2075+ || filename. ends_with ( ".rmeta" )
20752076 {
2076- // Always keep native libraries, rust dylibs and debuginfo
2077+ // Always keep native libraries, rust dylibs, debuginfo and crate metadata
20772078 keep = true ;
20782079 }
2079- if is_check && filename. ends_with ( ".rmeta" ) {
2080- // During check builds we need to keep crate metadata
2081- keep = true ;
2082- } else if rlib_only_metadata {
2080+ if !is_check && rlib_only_metadata {
20832081 if filename. contains ( "jemalloc_sys" )
20842082 || filename. contains ( "rustc_smir" )
20852083 || filename. contains ( "stable_mir" )
@@ -2091,7 +2089,6 @@ pub fn run_cargo(
20912089 // Distribute the rest of the rustc crates as rmeta files only to reduce
20922090 // the tarball sizes by about 50%. The object files are linked into
20932091 // librustc_driver.so, so it is still possible to link against them.
2094- keep |= filename. ends_with ( ".rmeta" ) ;
20952092 }
20962093 } else {
20972094 // In all other cases keep all rlibs
@@ -2137,7 +2134,12 @@ pub fn run_cargo(
21372134 let file_stem = parts. next ( ) . unwrap ( ) . to_owned ( ) ;
21382135 let extension = parts. next ( ) . unwrap ( ) . to_owned ( ) ;
21392136
2140- toplevel. push ( ( file_stem, extension, expected_len) ) ;
2137+ if extension == "so" || extension == "dylib" {
2138+ // FIXME workaround for the fact that cargo doesn't understand `-Zsplit-metadata`
2139+ toplevel. push ( ( file_stem. clone ( ) , "rmeta" . to_owned ( ) , None ) ) ;
2140+ }
2141+
2142+ toplevel. push ( ( file_stem, extension, Some ( expected_len) ) ) ;
21412143 }
21422144 } ) ;
21432145
@@ -2158,7 +2160,7 @@ pub fn run_cargo(
21582160 . collect :: < Vec < _ > > ( ) ;
21592161 for ( prefix, extension, expected_len) in toplevel {
21602162 let candidates = contents. iter ( ) . filter ( |& ( _, filename, meta) | {
2161- meta. len ( ) == expected_len
2163+ expected_len . map_or ( true , |expected_len| meta. len ( ) == expected_len)
21622164 && filename
21632165 . strip_prefix ( & prefix[ ..] )
21642166 . map ( |s| s. starts_with ( '-' ) && s. ends_with ( & extension[ ..] ) )
@@ -2169,6 +2171,7 @@ pub fn run_cargo(
21692171 } ) ;
21702172 let path_to_add = match max {
21712173 Some ( triple) => triple. 0 . to_str ( ) . unwrap ( ) ,
2174+ None if extension == "rmeta" => continue , // cfg(not(bootstrap)) remove this once -Zsplit-metadata is passed for all stages
21722175 None => panic ! ( "no output generated for {prefix:?} {extension:?}" ) ,
21732176 } ;
21742177 if is_dylib ( Path :: new ( path_to_add) ) {
0 commit comments