@@ -2002,14 +2002,12 @@ pub fn run_cargo(
20022002 || filename. ends_with ( ".a" )
20032003 || is_debug_info ( & filename)
20042004 || is_dylib ( & filename)
2005+ || filename. ends_with ( ".rmeta" )
20052006 {
2006- // Always keep native libraries, rust dylibs and debuginfo
2007+ // Always keep native libraries, rust dylibs, debuginfo and crate metadata
20072008 keep = true ;
20082009 }
2009- if is_check && filename. ends_with ( ".rmeta" ) {
2010- // During check builds we need to keep crate metadata
2011- keep = true ;
2012- } else if rlib_only_metadata {
2010+ if !is_check && rlib_only_metadata {
20132011 if filename. contains ( "jemalloc_sys" )
20142012 || filename. contains ( "rustc_smir" )
20152013 || filename. contains ( "stable_mir" )
@@ -2021,7 +2019,6 @@ pub fn run_cargo(
20212019 // Distribute the rest of the rustc crates as rmeta files only to reduce
20222020 // the tarball sizes by about 50%. The object files are linked into
20232021 // librustc_driver.so, so it is still possible to link against them.
2024- keep |= filename. ends_with ( ".rmeta" ) ;
20252022 }
20262023 } else {
20272024 // In all other cases keep all rlibs
@@ -2067,7 +2064,12 @@ pub fn run_cargo(
20672064 let file_stem = parts. next ( ) . unwrap ( ) . to_owned ( ) ;
20682065 let extension = parts. next ( ) . unwrap ( ) . to_owned ( ) ;
20692066
2070- toplevel. push ( ( file_stem, extension, expected_len) ) ;
2067+ if extension == "so" || extension == "dylib" {
2068+ // FIXME workaround for the fact that cargo doesn't understand `-Zsplit-metadata`
2069+ toplevel. push ( ( file_stem. clone ( ) , "rmeta" . to_owned ( ) , None ) ) ;
2070+ }
2071+
2072+ toplevel. push ( ( file_stem, extension, Some ( expected_len) ) ) ;
20712073 }
20722074 } ) ;
20732075
@@ -2088,7 +2090,7 @@ pub fn run_cargo(
20882090 . collect :: < Vec < _ > > ( ) ;
20892091 for ( prefix, extension, expected_len) in toplevel {
20902092 let candidates = contents. iter ( ) . filter ( |& ( _, filename, meta) | {
2091- meta. len ( ) == expected_len
2093+ expected_len . map_or ( true , |expected_len| meta. len ( ) == expected_len)
20922094 && filename
20932095 . strip_prefix ( & prefix[ ..] )
20942096 . map ( |s| s. starts_with ( '-' ) && s. ends_with ( & extension[ ..] ) )
@@ -2099,6 +2101,7 @@ pub fn run_cargo(
20992101 } ) ;
21002102 let path_to_add = match max {
21012103 Some ( triple) => triple. 0 . to_str ( ) . unwrap ( ) ,
2104+ None if extension == "rmeta" => continue , // cfg(not(bootstrap)) remove this once -Zsplit-metadata is passed for all stages
21022105 None => panic ! ( "no output generated for {prefix:?} {extension:?}" ) ,
21032106 } ;
21042107 if is_dylib ( path_to_add) {
0 commit comments