11use std:: fs:: File ;
22use std:: path:: { Path , PathBuf } ;
33
4- use rustc_codegen_ssa:: back:: archive:: ArchiveBuilder ;
4+ use rustc_codegen_ssa:: back:: archive:: { ArchiveBuilder , ArchiveBuilderBuilder } ;
55use rustc_session:: Session ;
66
77use rustc_session:: cstore:: DllImport ;
@@ -21,41 +21,56 @@ enum ArchiveEntry {
2121 File ( PathBuf ) ,
2222}
2323
24- pub struct ArArchiveBuilder < ' a > {
25- config : ArchiveConfig < ' a > ,
26- src_archives : Vec < ( PathBuf , ar:: Archive < File > ) > ,
27- // Don't use `HashMap` here, as the order is important. `rust.metadata.bin` must always be at
28- // the end of an archive for linkers to not get confused.
29- entries : Vec < ( String , ArchiveEntry ) > ,
30- }
24+ pub struct ArArchiveBuilderBuilder ;
3125
32- impl < ' a > ArchiveBuilder < ' a > for ArArchiveBuilder < ' a > {
33- fn new ( sess : & ' a Session ) -> Self {
26+ impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
27+ fn new_archive_builder < ' a > ( & self , sess : & ' a Session ) -> Box < dyn ArchiveBuilder < ' a > + ' a > {
3428 let config = ArchiveConfig {
3529 sess,
3630 use_native_ar : false ,
3731 // FIXME test for linux and System V derivatives instead
3832 use_gnu_style_archive : sess. target . options . archive_format == "gnu" ,
3933 } ;
4034
41- ArArchiveBuilder {
35+ Box :: new ( ArArchiveBuilder {
4236 config,
4337 src_archives : vec ! [ ] ,
4438 entries : vec ! [ ] ,
45- }
39+ } )
4640 }
4741
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 ! ( ) ;
50+ }
51+ }
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 > {
4862 fn add_file ( & mut self , file : & Path ) {
4963 self . entries . push ( (
5064 file. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ,
5165 ArchiveEntry :: File ( file. to_owned ( ) ) ,
5266 ) ) ;
5367 }
5468
55- fn add_archive < F > ( & mut self , archive_path : & Path , mut skip : F ) -> std:: io:: Result < ( ) >
56- where
57- F : FnMut ( & str ) -> bool + ' static ,
58- {
69+ fn add_archive (
70+ & mut self ,
71+ archive_path : & Path ,
72+ mut skip : Box < dyn FnMut ( & str ) -> bool + ' static > ,
73+ ) -> std:: io:: Result < ( ) > {
5974 let mut archive = ar:: Archive :: new ( std:: fs:: File :: open ( & archive_path) ?) ;
6075 let archive_index = self . src_archives . len ( ) ;
6176
@@ -75,7 +90,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
7590 Ok ( ( ) )
7691 }
7792
78- fn build ( mut self , output : & Path ) -> bool {
93+ fn build ( mut self : Box < Self > , output : & Path ) -> bool {
7994 use std:: process:: Command ;
8095
8196 fn add_file_using_ar ( archive : & Path , file : & Path ) {
@@ -171,13 +186,4 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
171186
172187 any_members
173188 }
174-
175- fn create_dll_import_lib (
176- _sess : & Session ,
177- _lib_name : & str ,
178- _dll_imports : & [ DllImport ] ,
179- _tmpdir : & Path ,
180- ) -> PathBuf {
181- unimplemented ! ( ) ;
182- }
183189}
0 commit comments