@@ -56,8 +56,13 @@ use std::{env, fmt, fs, io, mem, str};
56
56
pub struct SearchPaths ( OnceCell < Vec < PathBuf > > ) ;
57
57
58
58
impl 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)
61
66
}
62
67
}
63
68
@@ -310,8 +315,6 @@ fn link_rlib<'a>(
310
315
flavor : RlibFlavor ,
311
316
tmpdir : & MaybeTempDir ,
312
317
) -> Result < Box < dyn ArchiveBuilder + ' a > , ErrorGuaranteed > {
313
- let lib_search_paths = archive_search_paths ( sess) ;
314
-
315
318
let mut ab = archive_builder_builder. new_archive_builder ( sess) ;
316
319
317
320
let trailing_metadata = match flavor {
@@ -378,26 +381,24 @@ fn link_rlib<'a>(
378
381
// feature then we'll need to figure out how to record what objects were
379
382
// loaded from the libraries found here and then encode that into the
380
383
// metadata of the rlib we're generating somehow.
384
+ let search_paths = SearchPaths :: default ( ) ;
381
385
for lib in codegen_results. crate_info . used_libraries . iter ( ) {
382
386
let NativeLibKind :: Static { bundle : None | Some ( true ) , .. } = lib. kind else {
383
387
continue ;
384
388
} ;
389
+ let search_paths = search_paths. get ( sess) ;
385
390
if flavor == RlibFlavor :: Normal
386
391
&& let Some ( filename) = lib. filename
387
392
{
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) ;
389
394
let src = read ( path)
390
395
. map_err ( |e| sess. dcx ( ) . emit_fatal ( errors:: ReadFileError { message : e } ) ) ?;
391
396
let ( data, _) = create_wrapper_file ( sess, ".bundled_lib" . to_string ( ) , & src) ;
392
397
let wrapper_file = emit_wrapper_file ( sess, & data, tmpdir, filename. as_str ( ) ) ;
393
398
packed_bundled_libs. push ( wrapper_file) ;
394
399
} 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) ;
401
402
ab. add_archive ( & path, Box :: new ( |_| false ) ) . unwrap_or_else ( |error| {
402
403
sess. dcx ( ) . emit_fatal ( errors:: AddNativeLibrary { library_path : path, error } )
403
404
} ) ;
@@ -1445,10 +1446,6 @@ fn preserve_objects_for_their_debuginfo(sess: &Session) -> (bool, bool) {
1445
1446
}
1446
1447
}
1447
1448
1448
- fn archive_search_paths ( sess : & Session ) -> Vec < PathBuf > {
1449
- sess. target_filesearch ( PathKind :: Native ) . search_path_dirs ( )
1450
- }
1451
-
1452
1449
#[ derive( PartialEq ) ]
1453
1450
enum RlibFlavor {
1454
1451
Normal ,
0 commit comments