@@ -9,18 +9,15 @@ use std::str;
99
1010use crate :: llvm:: archive_ro:: { ArchiveRO , Child } ;
1111use crate :: llvm:: { self , ArchiveKind , LLVMMachineType , LLVMRustCOFFShortExport } ;
12- use rustc_codegen_ssa:: back:: archive:: { find_library, ArchiveBuilder } ;
13- use rustc_codegen_ssa:: { looks_like_rust_object_file, METADATA_FILENAME } ;
12+ use rustc_codegen_ssa:: back:: archive:: ArchiveBuilder ;
1413use rustc_data_structures:: temp_dir:: MaybeTempDir ;
1514use rustc_middle:: middle:: cstore:: { DllCallingConvention , DllImport } ;
1615use rustc_session:: Session ;
17- use rustc_span:: symbol:: Symbol ;
1816
1917struct ArchiveConfig < ' a > {
2018 pub sess : & ' a Session ,
2119 pub dst : PathBuf ,
2220 pub src : Option < PathBuf > ,
23- pub lib_search_paths : Vec < PathBuf > ,
2421}
2522
2623/// Helper for adding many files to an archive.
@@ -54,13 +51,7 @@ fn is_relevant_child(c: &Child<'_>) -> bool {
5451}
5552
5653fn archive_config < ' a > ( sess : & ' a Session , output : & Path , input : Option < & Path > ) -> ArchiveConfig < ' a > {
57- use rustc_codegen_ssa:: back:: link:: archive_search_paths;
58- ArchiveConfig {
59- sess,
60- dst : output. to_path_buf ( ) ,
61- src : input. map ( |p| p. to_path_buf ( ) ) ,
62- lib_search_paths : archive_search_paths ( sess) ,
63- }
54+ ArchiveConfig { sess, dst : output. to_path_buf ( ) , src : input. map ( |p| p. to_path_buf ( ) ) }
6455}
6556
6657/// Map machine type strings to values of LLVM's MachineTypes enum.
@@ -111,57 +102,23 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
111102 . collect ( )
112103 }
113104
114- /// Adds all of the contents of a native library to this archive. This will
115- /// search in the relevant locations for a library named `name`.
116- fn add_native_library ( & mut self , name : Symbol , verbatim : bool ) {
117- let location =
118- find_library ( name, verbatim, & self . config . lib_search_paths , self . config . sess ) ;
119- self . add_archive ( & location, |_| false ) . unwrap_or_else ( |e| {
120- self . config . sess . fatal ( & format ! (
121- "failed to add native library {}: {}" ,
122- location. to_string_lossy( ) ,
123- e
124- ) ) ;
105+ fn add_archive < F > ( & mut self , archive : & Path , skip : F ) -> io:: Result < ( ) >
106+ where
107+ F : FnMut ( & str ) -> bool + ' static ,
108+ {
109+ let archive_ro = match ArchiveRO :: open ( archive) {
110+ Ok ( ar) => ar,
111+ Err ( e) => return Err ( io:: Error :: new ( io:: ErrorKind :: Other , e) ) ,
112+ } ;
113+ if self . additions . iter ( ) . any ( |ar| ar. path ( ) == archive) {
114+ return Ok ( ( ) ) ;
115+ }
116+ self . additions . push ( Addition :: Archive {
117+ path : archive. to_path_buf ( ) ,
118+ archive : archive_ro,
119+ skip : Box :: new ( skip) ,
125120 } ) ;
126- }
127-
128- /// Adds all of the contents of the rlib at the specified path to this
129- /// archive.
130- ///
131- /// This ignores adding the bytecode from the rlib, and if LTO is enabled
132- /// then the object file also isn't added.
133- fn add_rlib (
134- & mut self ,
135- rlib : & Path ,
136- name : & str ,
137- lto : bool ,
138- skip_objects : bool ,
139- ) -> io:: Result < ( ) > {
140- // Ignoring obj file starting with the crate name
141- // as simple comparison is not enough - there
142- // might be also an extra name suffix
143- let obj_start = name. to_owned ( ) ;
144-
145- self . add_archive ( rlib, move |fname : & str | {
146- // Ignore metadata files, no matter the name.
147- if fname == METADATA_FILENAME {
148- return true ;
149- }
150-
151- // Don't include Rust objects if LTO is enabled
152- if lto && looks_like_rust_object_file ( fname) {
153- return true ;
154- }
155-
156- // Otherwise if this is *not* a rust object and we're skipping
157- // objects then skip this file
158- if skip_objects && ( !fname. starts_with ( & obj_start) || !fname. ends_with ( ".o" ) ) {
159- return true ;
160- }
161-
162- // ok, don't skip this
163- false
164- } )
121+ Ok ( ( ) )
165122 }
166123
167124 /// Adds an arbitrary file to this archive
@@ -270,25 +227,6 @@ impl<'a> LlvmArchiveBuilder<'a> {
270227 self . src_archive . as_ref ( ) . unwrap ( ) . as_ref ( )
271228 }
272229
273- fn add_archive < F > ( & mut self , archive : & Path , skip : F ) -> io:: Result < ( ) >
274- where
275- F : FnMut ( & str ) -> bool + ' static ,
276- {
277- let archive_ro = match ArchiveRO :: open ( archive) {
278- Ok ( ar) => ar,
279- Err ( e) => return Err ( io:: Error :: new ( io:: ErrorKind :: Other , e) ) ,
280- } ;
281- if self . additions . iter ( ) . any ( |ar| ar. path ( ) == archive) {
282- return Ok ( ( ) ) ;
283- }
284- self . additions . push ( Addition :: Archive {
285- path : archive. to_path_buf ( ) ,
286- archive : archive_ro,
287- skip : Box :: new ( skip) ,
288- } ) ;
289- Ok ( ( ) )
290- }
291-
292230 fn llvm_archive_kind ( & self ) -> Result < ArchiveKind , & str > {
293231 let kind = & * self . config . sess . target . archive_format ;
294232 kind. parse ( ) . map_err ( |_| kind)
0 commit comments