@@ -26,6 +26,35 @@ use crate::errors::{
2626DlltoolFailImportLibrary , ErrorCallingDllTool , ErrorCreatingImportLibrary , ErrorWritingDEFFile ,
2727} ;
2828
29+ /// An item to be included in an import library.
30+ /// This is a slimmed down version of `COFFShortExport` from `ar-archive-writer`.
31+ pub struct ImportLibraryItem {
32+ /// The name to be exported.
33+ pub name : String ,
34+ /// The ordinal to be exported, if any.
35+ pub ordinal : Option < u16 > ,
36+ /// The original, decorated name if `name` is not decorated.
37+ pub symbol_name : Option < String > ,
38+ /// True if this is a data export, false if it is a function export.
39+ pub is_data : bool ,
40+ }
41+
42+ impl From < ImportLibraryItem > for COFFShortExport {
43+ fn from ( item : ImportLibraryItem ) -> Self {
44+ COFFShortExport {
45+ name : item. name ,
46+ ext_name : None ,
47+ symbol_name : item. symbol_name ,
48+ alias_target : None ,
49+ ordinal : item. ordinal . unwrap_or ( 0 ) ,
50+ noname : item. ordinal . is_some ( ) ,
51+ data : item. is_data ,
52+ private : false ,
53+ constant : false ,
54+ }
55+ }
56+ }
57+
2958pub trait ArchiveBuilderBuilder {
3059fn new_archive_builder < ' a > ( & self , sess : & ' a Session ) -> Box < dyn ArchiveBuilder + ' a > ;
3160
@@ -38,7 +67,7 @@ pub trait ArchiveBuilderBuilder {
3867& self ,
3968sess : & Session ,
4069lib_name : & str ,
41- import_name_and_ordinal_vector : Vec < ( String , Option < u16 > ) > ,
70+ items : Vec < ImportLibraryItem > ,
4271output_path : & Path ,
4372) {
4473if common:: is_mingw_gnu_toolchain ( & sess. target ) {
@@ -47,21 +76,16 @@ pub trait ArchiveBuilderBuilder {
4776// that loaded but crashed with an AV upon calling one of the imported
4877// functions. Therefore, use binutils to create the import library instead,
4978// by writing a .DEF file to the temp dir and calling binutils's dlltool.
50- create_mingw_dll_import_lib (
51- sess,
52- lib_name,
53- import_name_and_ordinal_vector,
54- output_path,
55- ) ;
79+ create_mingw_dll_import_lib ( sess, lib_name, items, output_path) ;
5680} else {
5781trace ! ( "creating import library" ) ;
5882trace ! ( " dll_name {:#?}" , lib_name) ;
5983trace ! ( " output_path {}" , output_path. display( ) ) ;
6084trace ! (
6185" import names: {}" ,
62- import_name_and_ordinal_vector
86+ items
6387. iter( )
64- . map( |( name, _ordinal ) | name. clone( ) )
88+ . map( |ImportLibraryItem { name, .. } | name. clone( ) )
6589. collect:: <Vec <_>>( )
6690. join( ", " ) ,
6791) ;
@@ -79,20 +103,7 @@ pub trait ArchiveBuilderBuilder {
79103. emit_fatal ( ErrorCreatingImportLibrary { lib_name, error : error. to_string ( ) } ) ,
80104} ;
81105
82- let exports = import_name_and_ordinal_vector
83- . iter ( )
84- . map ( |( name, ordinal) | COFFShortExport {
85- name : name. to_string ( ) ,
86- ext_name : None ,
87- symbol_name : None ,
88- alias_target : None ,
89- ordinal : ordinal. unwrap_or ( 0 ) ,
90- noname : ordinal. is_some ( ) ,
91- data : false ,
92- private : false ,
93- constant : false ,
94- } )
95- . collect :: < Vec < _ > > ( ) ;
106+ let exports = items. into_iter ( ) . map ( Into :: into) . collect :: < Vec < _ > > ( ) ;
96107let machine = match & * sess. target . arch {
97108"x86_64" => MachineTypes :: AMD64 ,
98109"x86" => MachineTypes :: I386 ,
@@ -160,16 +171,16 @@ pub trait ArchiveBuilderBuilder {
160171fn create_mingw_dll_import_lib (
161172sess : & Session ,
162173lib_name : & str ,
163- import_name_and_ordinal_vector : Vec < ( String , Option < u16 > ) > ,
174+ items : Vec < ImportLibraryItem > ,
164175output_path : & Path ,
165176) {
166177let def_file_path = output_path. with_extension ( "def" ) ;
167178
168179let def_file_content = format ! (
169180"EXPORTS\n {}" ,
170- import_name_and_ordinal_vector
181+ items
171182. into_iter( )
172- . map( |( name, ordinal) | {
183+ . map( |ImportLibraryItem { name, ordinal, .. } | {
173184match ordinal {
174185Some ( n) => format!( "{name} @{n} NONAME" ) ,
175186None => name,
0 commit comments