@@ -5,7 +5,7 @@ use std::fs::File;
55use std:: io:: { self , Read , Seek } ;
66use std:: path:: { Path , PathBuf } ;
77
8- use rustc_codegen_ssa:: back:: archive:: ArchiveBuilder ;
8+ use rustc_codegen_ssa:: back:: archive:: { ArchiveBuilder , ArchiveBuilderBuilder } ;
99use rustc_session:: Session ;
1010
1111use object:: read:: archive:: ArchiveFile ;
@@ -17,9 +17,34 @@ enum ArchiveEntry {
1717 File ( PathBuf ) ,
1818}
1919
20+ pub ( crate ) struct ArArchiveBuilderBuilder ;
21+
22+ impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
23+ fn new_archive_builder < ' a > ( & self , sess : & ' a Session ) -> Box < dyn ArchiveBuilder < ' a > + ' a > {
24+ Box :: new ( ArArchiveBuilder {
25+ sess,
26+ use_gnu_style_archive : sess. target . archive_format == "gnu" ,
27+ // FIXME fix builtin ranlib on macOS
28+ no_builtin_ranlib : sess. target . is_like_osx ,
29+
30+ src_archives : vec ! [ ] ,
31+ entries : vec ! [ ] ,
32+ } )
33+ }
34+
35+ fn create_dll_import_lib (
36+ & self ,
37+ _sess : & Session ,
38+ _lib_name : & str ,
39+ _dll_imports : & [ rustc_session:: cstore:: DllImport ] ,
40+ _tmpdir : & Path ,
41+ ) -> PathBuf {
42+ bug ! ( "creating dll imports is not supported" ) ;
43+ }
44+ }
45+
2046pub ( crate ) struct ArArchiveBuilder < ' a > {
2147 sess : & ' a Session ,
22- dst : PathBuf ,
2348 use_gnu_style_archive : bool ,
2449 no_builtin_ranlib : bool ,
2550
@@ -30,30 +55,18 @@ pub(crate) struct ArArchiveBuilder<'a> {
3055}
3156
3257impl < ' a > ArchiveBuilder < ' a > for ArArchiveBuilder < ' a > {
33- fn new ( sess : & ' a Session , output : & Path ) -> Self {
34- ArArchiveBuilder {
35- sess,
36- dst : output. to_path_buf ( ) ,
37- use_gnu_style_archive : sess. target . archive_format == "gnu" ,
38- // FIXME fix builtin ranlib on macOS
39- no_builtin_ranlib : sess. target . is_like_osx ,
40-
41- src_archives : vec ! [ ] ,
42- entries : vec ! [ ] ,
43- }
44- }
45-
4658 fn add_file ( & mut self , file : & Path ) {
4759 self . entries . push ( (
4860 file. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) . into_bytes ( ) ,
4961 ArchiveEntry :: File ( file. to_owned ( ) ) ,
5062 ) ) ;
5163 }
5264
53- fn add_archive < F > ( & mut self , archive_path : & Path , mut skip : F ) -> std:: io:: Result < ( ) >
54- where
55- F : FnMut ( & str ) -> bool + ' static ,
56- {
65+ fn add_archive (
66+ & mut self ,
67+ archive_path : & Path ,
68+ mut skip : Box < dyn FnMut ( & str ) -> bool + ' static > ,
69+ ) -> std:: io:: Result < ( ) > {
5770 let read_cache = ReadCache :: new ( std:: fs:: File :: open ( & archive_path) ?) ;
5871 let archive = ArchiveFile :: parse ( & read_cache) . unwrap ( ) ;
5972 let archive_index = self . src_archives . len ( ) ;
@@ -74,7 +87,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
7487 Ok ( ( ) )
7588 }
7689
77- fn build ( mut self ) -> bool {
90+ fn build ( mut self : Box < Self > , output : & Path ) -> bool {
7891 enum BuilderKind {
7992 Bsd ( ar:: Builder < File > ) ,
8093 Gnu ( ar:: GnuBuilder < File > ) ,
@@ -163,7 +176,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
163176 let mut builder = if self . use_gnu_style_archive {
164177 BuilderKind :: Gnu (
165178 ar:: GnuBuilder :: new (
166- File :: create ( & self . dst ) . unwrap_or_else ( |err| {
179+ File :: create ( output ) . unwrap_or_else ( |err| {
167180 sess. fatal ( & format ! (
168181 "error opening destination during archive building: {}" ,
169182 err
@@ -178,7 +191,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
178191 } else {
179192 BuilderKind :: Bsd (
180193 ar:: Builder :: new (
181- File :: create ( & self . dst ) . unwrap_or_else ( |err| {
194+ File :: create ( output ) . unwrap_or_else ( |err| {
182195 sess. fatal ( & format ! (
183196 "error opening destination during archive building: {}" ,
184197 err
@@ -209,7 +222,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
209222
210223 // Run ranlib to be able to link the archive
211224 let status = std:: process:: Command :: new ( ranlib)
212- . arg ( self . dst )
225+ . arg ( output )
213226 . status ( )
214227 . expect ( "Couldn't run ranlib" ) ;
215228
@@ -220,17 +233,4 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
220233
221234 any_members
222235 }
223-
224- fn sess ( & self ) -> & Session {
225- self . sess
226- }
227-
228- fn create_dll_import_lib (
229- _sess : & Session ,
230- _lib_name : & str ,
231- _dll_imports : & [ rustc_session:: cstore:: DllImport ] ,
232- _tmpdir : & Path ,
233- ) -> PathBuf {
234- bug ! ( "creating dll imports is not supported" ) ;
235- }
236236}
0 commit comments