@@ -6,8 +6,7 @@ use std::fs::File;
6
6
use std:: io:: { self , Read , Seek } ;
7
7
use std:: path:: { Path , PathBuf } ;
8
8
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 ;
11
10
use rustc_session:: Session ;
12
11
13
12
use object:: read:: archive:: ArchiveFile ;
@@ -22,7 +21,6 @@ enum ArchiveEntry {
22
21
pub ( crate ) struct ArArchiveBuilder < ' a > {
23
22
sess : & ' a Session ,
24
23
dst : PathBuf ,
25
- lib_search_paths : Vec < PathBuf > ,
26
24
use_gnu_style_archive : bool ,
27
25
no_builtin_ranlib : bool ,
28
26
@@ -34,8 +32,6 @@ pub(crate) struct ArArchiveBuilder<'a> {
34
32
35
33
impl < ' a > ArchiveBuilder < ' a > for ArArchiveBuilder < ' a > {
36
34
fn new ( sess : & ' a Session , output : & Path , input : Option < & Path > ) -> Self {
37
- use rustc_codegen_ssa:: back:: link:: archive_search_paths;
38
-
39
35
let ( src_archives, entries) = if let Some ( input) = input {
40
36
let read_cache = ReadCache :: new ( File :: open ( input) . unwrap ( ) ) ;
41
37
let archive = ArchiveFile :: parse ( & read_cache) . unwrap ( ) ;
@@ -57,7 +53,6 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
57
53
ArArchiveBuilder {
58
54
sess,
59
55
dst : output. to_path_buf ( ) ,
60
- lib_search_paths : archive_search_paths ( sess) ,
61
56
use_gnu_style_archive : sess. target . archive_format == "gnu" ,
62
57
// FIXME fix builtin ranlib on macOS
63
58
no_builtin_ranlib : sess. target . is_like_osx ,
@@ -87,40 +82,29 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
87
82
) ) ;
88
83
}
89
84
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 ( ) ;
109
92
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
+ ) ) ;
113
102
}
103
+ }
114
104
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 ( ( ) )
120
107
121
- // ok, don't skip this
122
- false
123
- } )
124
108
}
125
109
126
110
fn update_symbols ( & mut self ) { }
@@ -265,29 +249,3 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
265
249
bug ! ( "injecting dll imports is not supported" ) ;
266
250
}
267
251
}
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