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