@@ -56,8 +56,13 @@ use std::{env, fmt, fs, io, mem, str};
5656pub  struct  SearchPaths ( OnceCell < Vec < PathBuf > > ) ; 
5757
5858impl  SearchPaths  { 
59-     pub ( super )  fn  get ( & self ,  sess :  & Session )  -> & [ PathBuf ]  { 
60-         self . 0 . get_or_init ( || archive_search_paths ( sess) ) 
59+     pub ( super )  fn  get ( & self ,  sess :  & Session )  -> impl  Iterator < Item  = & Path >  { 
60+         let  native_search_paths = || { 
61+             Vec :: from_iter ( 
62+                 sess. target_filesearch ( PathKind :: Native ) . search_path_dirs ( ) . map ( |p| p. to_owned ( ) ) , 
63+             ) 
64+         } ; 
65+         self . 0 . get_or_init ( native_search_paths) . iter ( ) . map ( |p| & * * p) 
6166    } 
6267} 
6368
@@ -310,8 +315,6 @@ fn link_rlib<'a>(
310315    flavor :  RlibFlavor , 
311316    tmpdir :  & MaybeTempDir , 
312317)  -> Result < Box < dyn  ArchiveBuilder  + ' a > ,  ErrorGuaranteed >  { 
313-     let  lib_search_paths = archive_search_paths ( sess) ; 
314- 
315318    let  mut  ab = archive_builder_builder. new_archive_builder ( sess) ; 
316319
317320    let  trailing_metadata = match  flavor { 
@@ -378,26 +381,24 @@ fn link_rlib<'a>(
378381    // feature then we'll need to figure out how to record what objects were 
379382    // loaded from the libraries found here and then encode that into the 
380383    // metadata of the rlib we're generating somehow. 
384+     let  search_paths = SearchPaths :: default ( ) ; 
381385    for  lib in  codegen_results. crate_info . used_libraries . iter ( )  { 
382386        let  NativeLibKind :: Static  {  bundle :  None  | Some ( true ) ,  .. }  = lib. kind  else  { 
383387            continue ; 
384388        } ; 
389+         let  search_paths = search_paths. get ( sess) ; 
385390        if  flavor == RlibFlavor :: Normal 
386391            && let  Some ( filename)  = lib. filename 
387392        { 
388-             let  path = find_native_static_library ( filename. as_str ( ) ,  true ,  & lib_search_paths ,  sess) ; 
393+             let  path = find_native_static_library ( filename. as_str ( ) ,  true ,  search_paths ,  sess) ; 
389394            let  src = read ( path) 
390395                . map_err ( |e| sess. dcx ( ) . emit_fatal ( errors:: ReadFileError  {  message :  e } ) ) ?; 
391396            let  ( data,  _)  = create_wrapper_file ( sess,  ".bundled_lib" . to_string ( ) ,  & src) ; 
392397            let  wrapper_file = emit_wrapper_file ( sess,  & data,  tmpdir,  filename. as_str ( ) ) ; 
393398            packed_bundled_libs. push ( wrapper_file) ; 
394399        }  else  { 
395-             let  path = find_native_static_library ( 
396-                 lib. name . as_str ( ) , 
397-                 lib. verbatim , 
398-                 & lib_search_paths, 
399-                 sess, 
400-             ) ; 
400+             let  path =
401+                 find_native_static_library ( lib. name . as_str ( ) ,  lib. verbatim ,  search_paths,  sess) ; 
401402            ab. add_archive ( & path,  Box :: new ( |_| false ) ) . unwrap_or_else ( |error| { 
402403                sess. dcx ( ) . emit_fatal ( errors:: AddNativeLibrary  {  library_path :  path,  error } ) 
403404            } ) ; 
@@ -1445,10 +1446,6 @@ fn preserve_objects_for_their_debuginfo(sess: &Session) -> (bool, bool) {
14451446    } 
14461447} 
14471448
1448- fn  archive_search_paths ( sess :  & Session )  -> Vec < PathBuf >  { 
1449-     sess. target_filesearch ( PathKind :: Native ) . search_path_dirs ( ) 
1450- } 
1451- 
14521449#[ derive( PartialEq ) ]  
14531450enum  RlibFlavor  { 
14541451    Normal , 
0 commit comments