@@ -219,15 +219,24 @@ pub fn get_linker(sess: &Session, linker: &Path, flavor: LinkerFlavor) -> (PathB
219219 ( linker. to_path_buf ( ) , cmd)
220220}
221221
222- pub fn each_linked_rlib ( sess : & Session ,
223- info : & CrateInfo ,
224- f : & mut dyn FnMut ( CrateNum , & Path ) ) -> Result < ( ) , String > {
222+ pub fn each_linked_rlib (
223+ info : & CrateInfo ,
224+ f : & mut dyn FnMut ( CrateNum , & Path ) ,
225+ ) -> Result < ( ) , String > {
225226 let crates = info. used_crates_static . iter ( ) ;
226- let fmts = sess. dependency_formats . borrow ( ) ;
227- let fmts = fmts. get ( & config:: CrateType :: Executable )
228- . or_else ( || fmts. get ( & config:: CrateType :: Staticlib ) )
229- . or_else ( || fmts. get ( & config:: CrateType :: Cdylib ) )
230- . or_else ( || fmts. get ( & config:: CrateType :: ProcMacro ) ) ;
227+ let mut fmts = None ;
228+ for ( ty, list) in info. dependency_formats . iter ( ) {
229+ match ty {
230+ config:: CrateType :: Executable |
231+ config:: CrateType :: Staticlib |
232+ config:: CrateType :: Cdylib |
233+ config:: CrateType :: ProcMacro => {
234+ fmts = Some ( list) ;
235+ break ;
236+ }
237+ _ => { }
238+ }
239+ }
231240 let fmts = match fmts {
232241 Some ( f) => f,
233242 None => return Err ( "could not find formats for rlibs" . to_string ( ) )
@@ -406,7 +415,7 @@ fn link_staticlib<'a, B: ArchiveBuilder<'a>>(sess: &'a Session,
406415 tempdir) ;
407416 let mut all_native_libs = vec ! [ ] ;
408417
409- let res = each_linked_rlib ( sess , & codegen_results. crate_info , & mut |cnum, path| {
418+ let res = each_linked_rlib ( & codegen_results. crate_info , & mut |cnum, path| {
410419 let name = & codegen_results. crate_info . crate_name [ & cnum] ;
411420 let native_libs = & codegen_results. crate_info . native_libraries [ & cnum] ;
412421
@@ -1294,11 +1303,13 @@ pub fn add_local_native_libraries(cmd: &mut dyn Linker,
12941303// Rust crates are not considered at all when creating an rlib output. All
12951304// dependencies will be linked when producing the final output (instead of
12961305// the intermediate rlib version)
1297- fn add_upstream_rust_crates < ' a , B : ArchiveBuilder < ' a > > ( cmd : & mut dyn Linker ,
1298- sess : & ' a Session ,
1299- codegen_results : & CodegenResults ,
1300- crate_type : config:: CrateType ,
1301- tmpdir : & Path ) {
1306+ fn add_upstream_rust_crates < ' a , B : ArchiveBuilder < ' a > > (
1307+ cmd : & mut dyn Linker ,
1308+ sess : & ' a Session ,
1309+ codegen_results : & CodegenResults ,
1310+ crate_type : config:: CrateType ,
1311+ tmpdir : & Path ,
1312+ ) {
13021313 // All of the heavy lifting has previously been accomplished by the
13031314 // dependency_format module of the compiler. This is just crawling the
13041315 // output of that module, adding crates as necessary.
@@ -1307,8 +1318,10 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(cmd: &mut dyn Linker,
13071318 // will slurp up the object files inside), and linking to a dynamic library
13081319 // involves just passing the right -l flag.
13091320
1310- let formats = sess. dependency_formats . borrow ( ) ;
1311- let data = formats. get ( & crate_type) . unwrap ( ) ;
1321+ let ( _, data) = codegen_results. crate_info . dependency_formats
1322+ . iter ( )
1323+ . find ( |( ty, _) | * ty == crate_type)
1324+ . expect ( "failed to find crate type in dependency format list" ) ;
13121325
13131326 // Invoke get_used_crates to ensure that we get a topological sorting of
13141327 // crates.
@@ -1620,10 +1633,12 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(cmd: &mut dyn Linker,
16201633// generic function calls a native function, then the generic function must
16211634// be instantiated in the target crate, meaning that the native symbol must
16221635// also be resolved in the target crate.
1623- pub fn add_upstream_native_libraries ( cmd : & mut dyn Linker ,
1624- sess : & Session ,
1625- codegen_results : & CodegenResults ,
1626- crate_type : config:: CrateType ) {
1636+ pub fn add_upstream_native_libraries (
1637+ cmd : & mut dyn Linker ,
1638+ sess : & Session ,
1639+ codegen_results : & CodegenResults ,
1640+ crate_type : config:: CrateType ,
1641+ ) {
16271642 // Be sure to use a topological sorting of crates because there may be
16281643 // interdependencies between native libraries. When passing -nodefaultlibs,
16291644 // for example, almost all native libraries depend on libc, so we have to
@@ -1633,8 +1648,10 @@ pub fn add_upstream_native_libraries(cmd: &mut dyn Linker,
16331648 // This passes RequireStatic, but the actual requirement doesn't matter,
16341649 // we're just getting an ordering of crate numbers, we're not worried about
16351650 // the paths.
1636- let formats = sess. dependency_formats . borrow ( ) ;
1637- let data = formats. get ( & crate_type) . unwrap ( ) ;
1651+ let ( _, data) = codegen_results. crate_info . dependency_formats
1652+ . iter ( )
1653+ . find ( |( ty, _) | * ty == crate_type)
1654+ . expect ( "failed to find crate type in dependency format list" ) ;
16381655
16391656 let crates = & codegen_results. crate_info . used_crates_static ;
16401657 for & ( cnum, _) in crates {
0 commit comments