@@ -10,10 +10,10 @@ use std::str;
10
10
use crate :: llvm:: archive_ro:: { ArchiveRO , Child } ;
11
11
use crate :: llvm:: { self , ArchiveKind } ;
12
12
use rustc_codegen_ssa:: { METADATA_FILENAME , RLIB_BYTECODE_EXTENSION } ;
13
- use rustc_codegen_ssa:: back:: archive:: find_library;
13
+ use rustc_codegen_ssa:: back:: archive:: { ArchiveBuilder , find_library} ;
14
14
use rustc:: session:: Session ;
15
15
16
- pub struct ArchiveConfig < ' a > {
16
+ struct ArchiveConfig < ' a > {
17
17
pub sess : & ' a Session ,
18
18
pub dst : PathBuf ,
19
19
pub src : Option < PathBuf > ,
@@ -22,7 +22,7 @@ pub struct ArchiveConfig<'a> {
22
22
23
23
/// Helper for adding many files to an archive.
24
24
#[ must_use = "must call build() to finish building the archive" ]
25
- pub struct ArchiveBuilder < ' a > {
25
+ pub struct LlvmArchiveBuilder < ' a > {
26
26
config : ArchiveConfig < ' a > ,
27
27
removals : Vec < String > ,
28
28
additions : Vec < Addition > ,
@@ -48,11 +48,26 @@ fn is_relevant_child(c: &Child<'_>) -> bool {
48
48
}
49
49
}
50
50
51
- impl < ' a > ArchiveBuilder < ' a > {
51
+ fn archive_config < ' a > ( sess : & ' a Session ,
52
+ output : & Path ,
53
+ input : Option < & Path > ) -> ArchiveConfig < ' a > {
54
+ use rustc_codegen_ssa:: back:: link:: archive_search_paths;
55
+ ArchiveConfig {
56
+ sess,
57
+ dst : output. to_path_buf ( ) ,
58
+ src : input. map ( |p| p. to_path_buf ( ) ) ,
59
+ lib_search_paths : archive_search_paths ( sess) ,
60
+ }
61
+ }
62
+
63
+ impl < ' a > ArchiveBuilder < ' a > for LlvmArchiveBuilder < ' a > {
52
64
/// Creates a new static archive, ready for modifying the archive specified
53
65
/// by `config`.
54
- pub fn new ( config : ArchiveConfig < ' a > ) -> ArchiveBuilder < ' a > {
55
- ArchiveBuilder {
66
+ fn new ( sess : & ' a Session ,
67
+ output : & Path ,
68
+ input : Option < & Path > ) -> LlvmArchiveBuilder < ' a > {
69
+ let config = archive_config ( sess, output, input) ;
70
+ LlvmArchiveBuilder {
56
71
config,
57
72
removals : Vec :: new ( ) ,
58
73
additions : Vec :: new ( ) ,
@@ -62,12 +77,12 @@ impl<'a> ArchiveBuilder<'a> {
62
77
}
63
78
64
79
/// Removes a file from this archive
65
- pub fn remove_file ( & mut self , file : & str ) {
80
+ fn remove_file ( & mut self , file : & str ) {
66
81
self . removals . push ( file. to_string ( ) ) ;
67
82
}
68
83
69
84
/// Lists all files in an archive
70
- pub fn src_files ( & mut self ) -> Vec < String > {
85
+ fn src_files ( & mut self ) -> Vec < String > {
71
86
if self . src_archive ( ) . is_none ( ) {
72
87
return Vec :: new ( )
73
88
}
@@ -83,18 +98,9 @@ impl<'a> ArchiveBuilder<'a> {
83
98
. collect ( )
84
99
}
85
100
86
- fn src_archive ( & mut self ) -> Option < & ArchiveRO > {
87
- if let Some ( ref a) = self . src_archive {
88
- return a. as_ref ( )
89
- }
90
- let src = self . config . src . as_ref ( ) ?;
91
- self . src_archive = Some ( ArchiveRO :: open ( src) . ok ( ) ) ;
92
- self . src_archive . as_ref ( ) . unwrap ( ) . as_ref ( )
93
- }
94
-
95
101
/// Adds all of the contents of a native library to this archive. This will
96
102
/// search in the relevant locations for a library named `name`.
97
- pub fn add_native_library ( & mut self , name : & str ) {
103
+ fn add_native_library ( & mut self , name : & str ) {
98
104
let location = find_library ( name, & self . config . lib_search_paths ,
99
105
self . config . sess ) ;
100
106
self . add_archive ( & location, |_| false ) . unwrap_or_else ( |e| {
@@ -108,7 +114,7 @@ impl<'a> ArchiveBuilder<'a> {
108
114
///
109
115
/// This ignores adding the bytecode from the rlib, and if LTO is enabled
110
116
/// then the object file also isn't added.
111
- pub fn add_rlib ( & mut self ,
117
+ fn add_rlib ( & mut self ,
112
118
rlib : & Path ,
113
119
name : & str ,
114
120
lto : bool ,
@@ -140,23 +146,8 @@ impl<'a> ArchiveBuilder<'a> {
140
146
} )
141
147
}
142
148
143
- fn add_archive < F > ( & mut self , archive : & Path , skip : F )
144
- -> io:: Result < ( ) >
145
- where F : FnMut ( & str ) -> bool + ' static
146
- {
147
- let archive = match ArchiveRO :: open ( archive) {
148
- Ok ( ar) => ar,
149
- Err ( e) => return Err ( io:: Error :: new ( io:: ErrorKind :: Other , e) ) ,
150
- } ;
151
- self . additions . push ( Addition :: Archive {
152
- archive,
153
- skip : Box :: new ( skip) ,
154
- } ) ;
155
- Ok ( ( ) )
156
- }
157
-
158
149
/// Adds an arbitrary file to this archive
159
- pub fn add_file ( & mut self , file : & Path ) {
150
+ fn add_file ( & mut self , file : & Path ) {
160
151
let name = file. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
161
152
self . additions . push ( Addition :: File {
162
153
path : file. to_path_buf ( ) ,
@@ -166,13 +157,13 @@ impl<'a> ArchiveBuilder<'a> {
166
157
167
158
/// Indicate that the next call to `build` should update all symbols in
168
159
/// the archive (equivalent to running 'ar s' over it).
169
- pub fn update_symbols ( & mut self ) {
160
+ fn update_symbols ( & mut self ) {
170
161
self . should_update_symbols = true ;
171
162
}
172
163
173
164
/// Combine the provided files, rlibs, and native libraries into a single
174
165
/// `Archive`.
175
- pub fn build ( & mut self ) {
166
+ fn build ( mut self ) {
176
167
let kind = self . llvm_archive_kind ( ) . unwrap_or_else ( |kind|
177
168
self . config . sess . fatal ( & format ! ( "Don't know how to build archive of type: {}" , kind) ) ) ;
178
169
@@ -181,6 +172,32 @@ impl<'a> ArchiveBuilder<'a> {
181
172
}
182
173
183
174
}
175
+ }
176
+
177
+ impl < ' a > LlvmArchiveBuilder < ' a > {
178
+ fn src_archive ( & mut self ) -> Option < & ArchiveRO > {
179
+ if let Some ( ref a) = self . src_archive {
180
+ return a. as_ref ( )
181
+ }
182
+ let src = self . config . src . as_ref ( ) ?;
183
+ self . src_archive = Some ( ArchiveRO :: open ( src) . ok ( ) ) ;
184
+ self . src_archive . as_ref ( ) . unwrap ( ) . as_ref ( )
185
+ }
186
+
187
+ fn add_archive < F > ( & mut self , archive : & Path , skip : F )
188
+ -> io:: Result < ( ) >
189
+ where F : FnMut ( & str ) -> bool + ' static
190
+ {
191
+ let archive = match ArchiveRO :: open ( archive) {
192
+ Ok ( ar) => ar,
193
+ Err ( e) => return Err ( io:: Error :: new ( io:: ErrorKind :: Other , e) ) ,
194
+ } ;
195
+ self . additions . push ( Addition :: Archive {
196
+ archive,
197
+ skip : Box :: new ( skip) ,
198
+ } ) ;
199
+ Ok ( ( ) )
200
+ }
184
201
185
202
fn llvm_archive_kind ( & self ) -> Result < ArchiveKind , & str > {
186
203
let kind = & * self . config . sess . target . target . options . archive_format ;
0 commit comments