@@ -6,8 +6,7 @@ use std::fs::File;
66use std:: io:: { self , Read , Seek } ;
77use std:: path:: { Path , PathBuf } ;
88
9- use rustc_codegen_ssa:: back:: archive:: { find_library, ArchiveBuilder } ;
10- use rustc_codegen_ssa:: METADATA_FILENAME ;
9+ use rustc_codegen_ssa:: back:: archive:: ArchiveBuilder ;
1110use rustc_session:: Session ;
1211
1312use object:: read:: archive:: ArchiveFile ;
@@ -22,7 +21,6 @@ enum ArchiveEntry {
2221pub ( crate ) struct ArArchiveBuilder < ' a > {
2322 sess : & ' a Session ,
2423 dst : PathBuf ,
25- lib_search_paths : Vec < PathBuf > ,
2624 use_gnu_style_archive : bool ,
2725 no_builtin_ranlib : bool ,
2826
@@ -34,8 +32,6 @@ pub(crate) struct ArArchiveBuilder<'a> {
3432
3533impl < ' a > ArchiveBuilder < ' a > for ArArchiveBuilder < ' a > {
3634 fn new ( sess : & ' a Session , output : & Path , input : Option < & Path > ) -> Self {
37- use rustc_codegen_ssa:: back:: link:: archive_search_paths;
38-
3935 let ( src_archives, entries) = if let Some ( input) = input {
4036 let read_cache = ReadCache :: new ( File :: open ( input) . unwrap ( ) ) ;
4137 let archive = ArchiveFile :: parse ( & read_cache) . unwrap ( ) ;
@@ -57,7 +53,6 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
5753 ArArchiveBuilder {
5854 sess,
5955 dst : output. to_path_buf ( ) ,
60- lib_search_paths : archive_search_paths ( sess) ,
6156 use_gnu_style_archive : sess. target . archive_format == "gnu" ,
6257 // FIXME fix builtin ranlib on macOS
6358 no_builtin_ranlib : sess. target . is_like_osx ,
@@ -87,40 +82,29 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
8782 ) ) ;
8883 }
8984
90- fn add_native_library ( & mut self , name : rustc_span:: symbol:: Symbol , verbatim : bool ) {
91- let location = find_library ( name, verbatim, & self . lib_search_paths , self . sess ) ;
92- self . add_archive ( location. clone ( ) , |_| false ) . unwrap_or_else ( |e| {
93- panic ! ( "failed to add native library {}: {}" , location. to_string_lossy( ) , e) ;
94- } ) ;
95- }
96-
97- fn add_rlib (
98- & mut self ,
99- rlib : & Path ,
100- name : & str ,
101- lto : bool ,
102- skip_objects : bool ,
103- ) -> io:: Result < ( ) > {
104- self . add_archive ( rlib. to_owned ( ) , move |fname : & str | {
105- // Ignore metadata files, no matter the name.
106- if fname == METADATA_FILENAME {
107- return true ;
108- }
85+ fn add_archive < F > ( & mut self , archive_path : & Path , mut skip : F ) -> std:: io:: Result < ( ) >
86+ where
87+ F : FnMut ( & str ) -> bool + ' static ,
88+ {
89+ let read_cache = ReadCache :: new ( std:: fs:: File :: open ( & archive_path) ?) ;
90+ let archive = ArchiveFile :: parse ( & read_cache) . unwrap ( ) ;
91+ let archive_index = self . src_archives . len ( ) ;
10992
110- // Don't include Rust objects if LTO is enabled
111- if lto && fname. starts_with ( name) && fname. ends_with ( ".o" ) {
112- return true ;
93+ for entry in archive. members ( ) {
94+ let entry = entry. map_err ( |err| io:: Error :: new ( io:: ErrorKind :: InvalidData , err) ) ?;
95+ let file_name = String :: from_utf8 ( entry. name ( ) . to_vec ( ) )
96+ . map_err ( |err| io:: Error :: new ( io:: ErrorKind :: InvalidData , err) ) ?;
97+ if !skip ( & file_name) {
98+ self . entries . push ( (
99+ file_name. into_bytes ( ) ,
100+ ArchiveEntry :: FromArchive { archive_index, file_range : entry. file_range ( ) } ,
101+ ) ) ;
113102 }
103+ }
114104
115- // Otherwise if this is *not* a rust object and we're skipping
116- // objects then skip this file
117- if skip_objects && ( !fname. starts_with ( name) || !fname. ends_with ( ".o" ) ) {
118- return true ;
119- }
105+ self . src_archives . push ( read_cache. into_inner ( ) ) ;
106+ Ok ( ( ) )
120107
121- // ok, don't skip this
122- false
123- } )
124108 }
125109
126110 fn update_symbols ( & mut self ) { }
@@ -265,29 +249,3 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
265249 bug ! ( "injecting dll imports is not supported" ) ;
266250 }
267251}
268-
269- impl < ' a > ArArchiveBuilder < ' a > {
270- fn add_archive < F > ( & mut self , archive_path : PathBuf , mut skip : F ) -> io:: Result < ( ) >
271- where
272- F : FnMut ( & str ) -> bool ,
273- {
274- let read_cache = ReadCache :: new ( std:: fs:: File :: open ( & archive_path) ?) ;
275- let archive = ArchiveFile :: parse ( & read_cache) . unwrap ( ) ;
276- let archive_index = self . src_archives . len ( ) ;
277-
278- for entry in archive. members ( ) {
279- let entry = entry. map_err ( |err| io:: Error :: new ( io:: ErrorKind :: InvalidData , err) ) ?;
280- let file_name = String :: from_utf8 ( entry. name ( ) . to_vec ( ) )
281- . map_err ( |err| io:: Error :: new ( io:: ErrorKind :: InvalidData , err) ) ?;
282- if !skip ( & file_name) {
283- self . entries . push ( (
284- file_name. into_bytes ( ) ,
285- ArchiveEntry :: FromArchive { archive_index, file_range : entry. file_range ( ) } ,
286- ) ) ;
287- }
288- }
289-
290- self . src_archives . push ( read_cache. into_inner ( ) ) ;
291- Ok ( ( ) )
292- }
293- }
0 commit comments