@@ -15,16 +15,12 @@ use rustc_data_structures::temp_dir::MaybeTempDir;
15
15
use rustc_session:: cstore:: { DllCallingConvention , DllImport } ;
16
16
use rustc_session:: Session ;
17
17
18
- struct ArchiveConfig < ' a > {
19
- pub sess : & ' a Session ,
20
- pub dst : PathBuf ,
21
- pub src : Option < PathBuf > ,
22
- }
23
-
24
18
/// Helper for adding many files to an archive.
25
19
#[ must_use = "must call build() to finish building the archive" ]
26
20
pub struct LlvmArchiveBuilder < ' a > {
27
- config : ArchiveConfig < ' a > ,
21
+ sess : & ' a Session ,
22
+ dst : PathBuf ,
23
+ src : Option < PathBuf > ,
28
24
removals : Vec < String > ,
29
25
additions : Vec < Addition > ,
30
26
src_archive : Option < Option < ArchiveRO > > ,
@@ -50,10 +46,6 @@ fn is_relevant_child(c: &Child<'_>) -> bool {
50
46
}
51
47
}
52
48
53
- fn archive_config < ' a > ( sess : & ' a Session , output : & Path , input : Option < & Path > ) -> ArchiveConfig < ' a > {
54
- ArchiveConfig { sess, dst : output. to_path_buf ( ) , src : input. map ( |p| p. to_path_buf ( ) ) }
55
- }
56
-
57
49
/// Map machine type strings to values of LLVM's MachineTypes enum.
58
50
fn llvm_machine_type ( cpu : & str ) -> LLVMMachineType {
59
51
match cpu {
@@ -69,9 +61,10 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
69
61
/// Creates a new static archive, ready for modifying the archive specified
70
62
/// by `config`.
71
63
fn new ( sess : & ' a Session , output : & Path , input : Option < & Path > ) -> LlvmArchiveBuilder < ' a > {
72
- let config = archive_config ( sess, output, input) ;
73
64
LlvmArchiveBuilder {
74
- config,
65
+ sess,
66
+ dst : output. to_path_buf ( ) ,
67
+ src : input. map ( |p| p. to_path_buf ( ) ) ,
75
68
removals : Vec :: new ( ) ,
76
69
additions : Vec :: new ( ) ,
77
70
src_archive : None ,
@@ -131,11 +124,11 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
131
124
/// `Archive`.
132
125
fn build ( mut self ) {
133
126
let kind = self . llvm_archive_kind ( ) . unwrap_or_else ( |kind| {
134
- self . config . sess . fatal ( & format ! ( "Don't know how to build archive of type: {}" , kind) )
127
+ self . sess . fatal ( & format ! ( "Don't know how to build archive of type: {}" , kind) )
135
128
} ) ;
136
129
137
130
if let Err ( e) = self . build_with_llvm ( kind) {
138
- self . config . sess . fatal ( & format ! ( "failed to build archive: {}" , e) ) ;
131
+ self . sess . fatal ( & format ! ( "failed to build archive: {}" , e) ) ;
139
132
}
140
133
}
141
134
@@ -151,7 +144,7 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
151
144
output_path. with_extension ( "lib" )
152
145
} ;
153
146
154
- let target = & self . config . sess . target ;
147
+ let target = & self . sess . target ;
155
148
let mingw_gnu_toolchain = target. vendor == "pc"
156
149
&& target. os == "windows"
157
150
&& target. env == "gnu"
@@ -160,7 +153,7 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
160
153
let import_name_and_ordinal_vector: Vec < ( String , Option < u16 > ) > = dll_imports
161
154
. iter ( )
162
155
. map ( |import : & DllImport | {
163
- if self . config . sess . target . arch == "x86" {
156
+ if self . sess . target . arch == "x86" {
164
157
(
165
158
LlvmArchiveBuilder :: i686_decorated_name ( import, mingw_gnu_toolchain) ,
166
159
import. ordinal ,
@@ -197,11 +190,11 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
197
190
match std:: fs:: write ( & def_file_path, def_file_content) {
198
191
Ok ( _) => { }
199
192
Err ( e) => {
200
- self . config . sess . fatal ( & format ! ( "Error writing .DEF file: {}" , e) ) ;
193
+ self . sess . fatal ( & format ! ( "Error writing .DEF file: {}" , e) ) ;
201
194
}
202
195
} ;
203
196
204
- let dlltool = find_binutils_dlltool ( self . config . sess ) ;
197
+ let dlltool = find_binutils_dlltool ( self . sess ) ;
205
198
let result = std:: process:: Command :: new ( dlltool)
206
199
. args ( [
207
200
"-d" ,
@@ -215,9 +208,9 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
215
208
216
209
match result {
217
210
Err ( e) => {
218
- self . config . sess . fatal ( & format ! ( "Error calling dlltool: {}" , e) ) ;
211
+ self . sess . fatal ( & format ! ( "Error calling dlltool: {}" , e) ) ;
219
212
}
220
- Ok ( output) if !output. status . success ( ) => self . config . sess . fatal ( & format ! (
213
+ Ok ( output) if !output. status . success ( ) => self . sess . fatal ( & format ! (
221
214
"Dlltool could not create import library: {}\n {}" ,
222
215
String :: from_utf8_lossy( & output. stdout) ,
223
216
String :: from_utf8_lossy( & output. stderr)
@@ -263,13 +256,13 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
263
256
output_path_z. as_ptr ( ) ,
264
257
ffi_exports. as_ptr ( ) ,
265
258
ffi_exports. len ( ) ,
266
- llvm_machine_type ( & self . config . sess . target . arch ) as u16 ,
267
- !self . config . sess . target . is_like_msvc ,
259
+ llvm_machine_type ( & self . sess . target . arch ) as u16 ,
260
+ !self . sess . target . is_like_msvc ,
268
261
)
269
262
} ;
270
263
271
264
if result == crate :: llvm:: LLVMRustResult :: Failure {
272
- self . config . sess . fatal ( & format ! (
265
+ self . sess . fatal ( & format ! (
273
266
"Error creating import library for {}: {}" ,
274
267
lib_name,
275
268
llvm:: last_error( ) . unwrap_or( "unknown LLVM error" . to_string( ) )
@@ -278,7 +271,7 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
278
271
} ;
279
272
280
273
self . add_archive ( & output_path, |_| false ) . unwrap_or_else ( |e| {
281
- self . config . sess . fatal ( & format ! (
274
+ self . sess . fatal ( & format ! (
282
275
"failed to add native library {}: {}" ,
283
276
output_path. display( ) ,
284
277
e
@@ -292,13 +285,13 @@ impl<'a> LlvmArchiveBuilder<'a> {
292
285
if let Some ( ref a) = self . src_archive {
293
286
return a. as_ref ( ) ;
294
287
}
295
- let src = self . config . src . as_ref ( ) ?;
288
+ let src = self . src . as_ref ( ) ?;
296
289
self . src_archive = Some ( ArchiveRO :: open ( src) . ok ( ) ) ;
297
290
self . src_archive . as_ref ( ) . unwrap ( ) . as_ref ( )
298
291
}
299
292
300
293
fn llvm_archive_kind ( & self ) -> Result < ArchiveKind , & str > {
301
- let kind = & * self . config . sess . target . archive_format ;
294
+ let kind = & * self . sess . target . archive_format ;
302
295
kind. parse ( ) . map_err ( |_| kind)
303
296
}
304
297
@@ -308,7 +301,7 @@ impl<'a> LlvmArchiveBuilder<'a> {
308
301
let mut strings = Vec :: new ( ) ;
309
302
let mut members = Vec :: new ( ) ;
310
303
311
- let dst = CString :: new ( self . config . dst . to_str ( ) . unwrap ( ) ) ?;
304
+ let dst = CString :: new ( self . dst . to_str ( ) . unwrap ( ) ) ?;
312
305
313
306
unsafe {
314
307
if let Some ( archive) = self . src_archive ( ) {
0 commit comments