@@ -5,7 +5,7 @@ use std::fs::File;
5
5
use std:: io:: { self , Read , Seek } ;
6
6
use std:: path:: { Path , PathBuf } ;
7
7
8
- use rustc_codegen_ssa:: back:: archive:: ArchiveBuilder ;
8
+ use rustc_codegen_ssa:: back:: archive:: { ArchiveBuilder , ArchiveBuilderBuilder } ;
9
9
use rustc_session:: Session ;
10
10
11
11
use object:: read:: archive:: ArchiveFile ;
@@ -17,9 +17,34 @@ enum ArchiveEntry {
17
17
File ( PathBuf ) ,
18
18
}
19
19
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
+
20
46
pub ( crate ) struct ArArchiveBuilder < ' a > {
21
47
sess : & ' a Session ,
22
- dst : PathBuf ,
23
48
use_gnu_style_archive : bool ,
24
49
no_builtin_ranlib : bool ,
25
50
@@ -30,30 +55,18 @@ pub(crate) struct ArArchiveBuilder<'a> {
30
55
}
31
56
32
57
impl < ' 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
-
46
58
fn add_file ( & mut self , file : & Path ) {
47
59
self . entries . push ( (
48
60
file. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) . into_bytes ( ) ,
49
61
ArchiveEntry :: File ( file. to_owned ( ) ) ,
50
62
) ) ;
51
63
}
52
64
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 < ( ) > {
57
70
let read_cache = ReadCache :: new ( std:: fs:: File :: open ( & archive_path) ?) ;
58
71
let archive = ArchiveFile :: parse ( & read_cache) . unwrap ( ) ;
59
72
let archive_index = self . src_archives . len ( ) ;
@@ -74,7 +87,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
74
87
Ok ( ( ) )
75
88
}
76
89
77
- fn build ( mut self ) -> bool {
90
+ fn build ( mut self : Box < Self > , output : & Path ) -> bool {
78
91
enum BuilderKind {
79
92
Bsd ( ar:: Builder < File > ) ,
80
93
Gnu ( ar:: GnuBuilder < File > ) ,
@@ -163,7 +176,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
163
176
let mut builder = if self . use_gnu_style_archive {
164
177
BuilderKind :: Gnu (
165
178
ar:: GnuBuilder :: new (
166
- File :: create ( & self . dst ) . unwrap_or_else ( |err| {
179
+ File :: create ( output ) . unwrap_or_else ( |err| {
167
180
sess. fatal ( & format ! (
168
181
"error opening destination during archive building: {}" ,
169
182
err
@@ -178,7 +191,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
178
191
} else {
179
192
BuilderKind :: Bsd (
180
193
ar:: Builder :: new (
181
- File :: create ( & self . dst ) . unwrap_or_else ( |err| {
194
+ File :: create ( output ) . unwrap_or_else ( |err| {
182
195
sess. fatal ( & format ! (
183
196
"error opening destination during archive building: {}" ,
184
197
err
@@ -209,7 +222,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
209
222
210
223
// Run ranlib to be able to link the archive
211
224
let status = std:: process:: Command :: new ( ranlib)
212
- . arg ( self . dst )
225
+ . arg ( output )
213
226
. status ( )
214
227
. expect ( "Couldn't run ranlib" ) ;
215
228
@@ -220,17 +233,4 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
220
233
221
234
any_members
222
235
}
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
- }
236
236
}
0 commit comments