@@ -2,16 +2,15 @@ use std::fs::File;
2
2
use std:: path:: { Path , PathBuf } ;
3
3
4
4
use rustc_session:: Session ;
5
- use rustc_codegen_ssa:: back:: archive:: { find_library , ArchiveBuilder } ;
6
- use rustc_codegen_ssa :: METADATA_FILENAME ;
5
+ use rustc_codegen_ssa:: back:: archive:: ArchiveBuilder ;
6
+
7
7
use rustc_data_structures:: temp_dir:: MaybeTempDir ;
8
8
use rustc_middle:: middle:: cstore:: DllImport ;
9
- use rustc_span :: symbol :: Symbol ;
9
+
10
10
11
11
struct ArchiveConfig < ' a > {
12
12
sess : & ' a Session ,
13
13
dst : PathBuf ,
14
- lib_search_paths : Vec < PathBuf > ,
15
14
use_native_ar : bool ,
16
15
use_gnu_style_archive : bool ,
17
16
}
@@ -35,11 +34,9 @@ pub struct ArArchiveBuilder<'a> {
35
34
36
35
impl < ' a > ArchiveBuilder < ' a > for ArArchiveBuilder < ' a > {
37
36
fn new ( sess : & ' a Session , output : & Path , input : Option < & Path > ) -> Self {
38
- use rustc_codegen_ssa:: back:: link:: archive_search_paths;
39
37
let config = ArchiveConfig {
40
38
sess,
41
39
dst : output. to_path_buf ( ) ,
42
- lib_search_paths : archive_search_paths ( sess) ,
43
40
use_native_ar : false ,
44
41
// FIXME test for linux and System V derivatives instead
45
42
use_gnu_style_archive : sess. target . options . archive_format == "gnu" ,
@@ -94,47 +91,27 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
94
91
) ) ;
95
92
}
96
93
97
- fn add_native_library ( & mut self , name : Symbol , verbatim : bool ) {
98
- let location = find_library ( name, verbatim, & self . config . lib_search_paths , self . config . sess ) ;
99
- self . add_archive ( location. clone ( ) , |_| false )
100
- . unwrap_or_else ( |e| {
101
- panic ! (
102
- "failed to add native library {}: {}" ,
103
- location. to_string_lossy( ) ,
104
- e
105
- ) ;
106
- } ) ;
107
- }
108
-
109
- fn add_rlib (
110
- & mut self ,
111
- rlib : & Path ,
112
- name : & str ,
113
- lto : bool ,
114
- skip_objects : bool ,
115
- ) -> std:: io:: Result < ( ) > {
116
- let obj_start = name. to_owned ( ) ;
117
-
118
- self . add_archive ( rlib. to_owned ( ) , move |fname : & str | {
119
- // Ignore metadata files, no matter the name.
120
- if fname == METADATA_FILENAME {
121
- return true ;
122
- }
123
-
124
- // Don't include Rust objects if LTO is enabled
125
- if lto && fname. starts_with ( & obj_start) && fname. ends_with ( ".o" ) {
126
- return true ;
127
- }
94
+ fn add_archive < F > ( & mut self , archive_path : & Path , mut skip : F ) -> std:: io:: Result < ( ) >
95
+ where
96
+ F : FnMut ( & str ) -> bool + ' static ,
97
+ {
98
+ let mut archive = ar:: Archive :: new ( std:: fs:: File :: open ( & archive_path) ?) ;
99
+ let archive_index = self . src_archives . len ( ) ;
128
100
129
- // Otherwise if this is *not* a rust object and we're skipping
130
- // objects then skip this file
131
- if skip_objects && ( !fname. starts_with ( & obj_start) || !fname. ends_with ( ".o" ) ) {
132
- return true ;
101
+ let mut i = 0 ;
102
+ while let Some ( entry) = archive. next_entry ( ) {
103
+ let entry = entry?;
104
+ let file_name = String :: from_utf8 ( entry. header ( ) . identifier ( ) . to_vec ( ) )
105
+ . map_err ( |err| std:: io:: Error :: new ( std:: io:: ErrorKind :: InvalidData , err) ) ?;
106
+ if !skip ( & file_name) {
107
+ self . entries
108
+ . push ( ( file_name, ArchiveEntry :: FromArchive { archive_index, entry_index : i } ) ) ;
133
109
}
110
+ i += 1 ;
111
+ }
134
112
135
- // ok, don't skip this
136
- return false ;
137
- } )
113
+ self . src_archives . push ( ( archive_path. to_owned ( ) , archive) ) ;
114
+ Ok ( ( ) )
138
115
}
139
116
140
117
fn update_symbols ( & mut self ) {
@@ -239,32 +216,3 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
239
216
unimplemented ! ( ) ;
240
217
}
241
218
}
242
-
243
- impl < ' a > ArArchiveBuilder < ' a > {
244
- fn add_archive < F > ( & mut self , archive_path : PathBuf , mut skip : F ) -> std:: io:: Result < ( ) >
245
- where
246
- F : FnMut ( & str ) -> bool + ' static ,
247
- {
248
- let mut archive = ar:: Archive :: new ( std:: fs:: File :: open ( & archive_path) ?) ;
249
- let archive_index = self . src_archives . len ( ) ;
250
-
251
- let mut i = 0 ;
252
- while let Some ( entry) = archive. next_entry ( ) {
253
- let entry = entry. unwrap ( ) ;
254
- let file_name = String :: from_utf8 ( entry. header ( ) . identifier ( ) . to_vec ( ) ) . unwrap ( ) ;
255
- if !skip ( & file_name) {
256
- self . entries . push ( (
257
- file_name,
258
- ArchiveEntry :: FromArchive {
259
- archive_index,
260
- entry_index : i,
261
- } ,
262
- ) ) ;
263
- }
264
- i += 1 ;
265
- }
266
-
267
- self . src_archives . push ( ( archive_path, archive) ) ;
268
- Ok ( ( ) )
269
- }
270
- }
0 commit comments