1
1
use std:: fs:: File ;
2
2
use std:: path:: { Path , PathBuf } ;
3
3
4
- use rustc_codegen_ssa:: back:: archive:: ArchiveBuilder ;
4
+ use rustc_codegen_ssa:: back:: archive:: { ArchiveBuilder , ArchiveBuilderBuilder } ;
5
5
use rustc_session:: Session ;
6
6
7
7
use rustc_session:: cstore:: DllImport ;
8
8
9
9
struct ArchiveConfig < ' a > {
10
10
sess : & ' a Session ,
11
- dst : PathBuf ,
12
11
use_native_ar : bool ,
13
12
use_gnu_style_archive : bool ,
14
13
}
@@ -22,42 +21,56 @@ enum ArchiveEntry {
22
21
File ( PathBuf ) ,
23
22
}
24
23
25
- pub struct ArArchiveBuilder < ' a > {
26
- config : ArchiveConfig < ' a > ,
27
- src_archives : Vec < ( PathBuf , ar:: Archive < File > ) > ,
28
- // Don't use `HashMap` here, as the order is important. `rust.metadata.bin` must always be at
29
- // the end of an archive for linkers to not get confused.
30
- entries : Vec < ( String , ArchiveEntry ) > ,
31
- }
24
+ pub struct ArArchiveBuilderBuilder ;
32
25
33
- impl < ' a > ArchiveBuilder < ' a > for ArArchiveBuilder < ' a > {
34
- fn new ( sess : & ' a Session , output : & Path ) -> Self {
26
+ impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
27
+ fn new_archive_builder < ' a > ( & self , sess : & ' a Session ) -> Box < dyn ArchiveBuilder < ' a > + ' a > {
35
28
let config = ArchiveConfig {
36
29
sess,
37
- dst : output. to_path_buf ( ) ,
38
30
use_native_ar : false ,
39
31
// FIXME test for linux and System V derivatives instead
40
32
use_gnu_style_archive : sess. target . options . archive_format == "gnu" ,
41
33
} ;
42
34
43
- ArArchiveBuilder {
35
+ Box :: new ( ArArchiveBuilder {
44
36
config,
45
37
src_archives : vec ! [ ] ,
46
38
entries : vec ! [ ] ,
47
- }
39
+ } )
40
+ }
41
+
42
+ fn create_dll_import_lib (
43
+ & self ,
44
+ _sess : & Session ,
45
+ _lib_name : & str ,
46
+ _dll_imports : & [ DllImport ] ,
47
+ _tmpdir : & Path ,
48
+ ) -> PathBuf {
49
+ unimplemented ! ( ) ;
48
50
}
51
+ }
49
52
53
+ pub struct ArArchiveBuilder < ' a > {
54
+ config : ArchiveConfig < ' a > ,
55
+ src_archives : Vec < ( PathBuf , ar:: Archive < File > ) > ,
56
+ // Don't use `HashMap` here, as the order is important. `rust.metadata.bin` must always be at
57
+ // the end of an archive for linkers to not get confused.
58
+ entries : Vec < ( String , ArchiveEntry ) > ,
59
+ }
60
+
61
+ impl < ' a > ArchiveBuilder < ' a > for ArArchiveBuilder < ' a > {
50
62
fn add_file ( & mut self , file : & Path ) {
51
63
self . entries . push ( (
52
64
file. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ,
53
65
ArchiveEntry :: File ( file. to_owned ( ) ) ,
54
66
) ) ;
55
67
}
56
68
57
- fn add_archive < F > ( & mut self , archive_path : & Path , mut skip : F ) -> std:: io:: Result < ( ) >
58
- where
59
- F : FnMut ( & str ) -> bool + ' static ,
60
- {
69
+ fn add_archive (
70
+ & mut self ,
71
+ archive_path : & Path ,
72
+ mut skip : Box < dyn FnMut ( & str ) -> bool + ' static > ,
73
+ ) -> std:: io:: Result < ( ) > {
61
74
let mut archive = ar:: Archive :: new ( std:: fs:: File :: open ( & archive_path) ?) ;
62
75
let archive_index = self . src_archives . len ( ) ;
63
76
@@ -77,7 +90,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
77
90
Ok ( ( ) )
78
91
}
79
92
80
- fn build ( mut self ) -> bool {
93
+ fn build ( mut self : Box < Self > , output : & Path ) -> bool {
81
94
use std:: process:: Command ;
82
95
83
96
fn add_file_using_ar ( archive : & Path , file : & Path ) {
@@ -97,17 +110,17 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
97
110
}
98
111
99
112
let mut builder = if self . config . use_native_ar {
100
- BuilderKind :: NativeAr ( & self . config . dst )
113
+ BuilderKind :: NativeAr ( output )
101
114
} else if self . config . use_gnu_style_archive {
102
115
BuilderKind :: Gnu ( ar:: GnuBuilder :: new (
103
- File :: create ( & self . config . dst ) . unwrap ( ) ,
116
+ File :: create ( output ) . unwrap ( ) ,
104
117
self . entries
105
118
. iter ( )
106
119
. map ( |( name, _) | name. as_bytes ( ) . to_vec ( ) )
107
120
. collect ( ) ,
108
121
) )
109
122
} else {
110
- BuilderKind :: Bsd ( ar:: Builder :: new ( File :: create ( & self . config . dst ) . unwrap ( ) ) )
123
+ BuilderKind :: Bsd ( ar:: Builder :: new ( File :: create ( output ) . unwrap ( ) ) )
111
124
} ;
112
125
113
126
let any_members = !self . entries . is_empty ( ) ;
@@ -164,28 +177,13 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
164
177
std:: mem:: drop ( builder) ;
165
178
166
179
// Run ranlib to be able to link the archive
167
- let status = std:: process:: Command :: new ( "ranlib" )
168
- . arg ( self . config . dst )
169
- . status ( )
170
- . expect ( "Couldn't run ranlib" ) ;
180
+ let status =
181
+ std:: process:: Command :: new ( "ranlib" ) . arg ( output) . status ( ) . expect ( "Couldn't run ranlib" ) ;
171
182
172
183
if !status. success ( ) {
173
184
self . config . sess . fatal ( & format ! ( "Ranlib exited with code {:?}" , status. code( ) ) ) ;
174
185
}
175
186
176
187
any_members
177
188
}
178
-
179
- fn sess ( & self ) -> & Session {
180
- self . config . sess
181
- }
182
-
183
- fn create_dll_import_lib (
184
- _sess : & Session ,
185
- _lib_name : & str ,
186
- _dll_imports : & [ DllImport ] ,
187
- _tmpdir : & Path ,
188
- ) -> PathBuf {
189
- unimplemented ! ( ) ;
190
- }
191
189
}
0 commit comments