@@ -87,6 +87,7 @@ impl LinkerInfo {
87
87
/// used to dispatch on whether a GNU-like linker (generally `ld.exe`) or an
88
88
/// MSVC linker (e.g., `link.exe`) is being used.
89
89
pub trait Linker {
90
+ fn cmd ( & mut self ) -> & mut Command ;
90
91
fn link_dylib ( & mut self , lib : Symbol ) ;
91
92
fn link_rust_dylib ( & mut self , lib : Symbol , path : & Path ) ;
92
93
fn link_framework ( & mut self , framework : Symbol ) ;
@@ -111,7 +112,6 @@ pub trait Linker {
111
112
fn no_default_libraries ( & mut self ) ;
112
113
fn build_dylib ( & mut self , out_filename : & Path ) ;
113
114
fn build_static_executable ( & mut self ) ;
114
- fn args ( & mut self , args : & [ String ] ) ;
115
115
fn export_symbols ( & mut self , tmpdir : & Path , crate_type : CrateType ) ;
116
116
fn subsystem ( & mut self , subsystem : & str ) ;
117
117
fn group_start ( & mut self ) ;
@@ -121,6 +121,16 @@ pub trait Linker {
121
121
fn finalize ( & mut self ) -> Command ;
122
122
}
123
123
124
+ impl dyn Linker + ' _ {
125
+ pub fn arg ( & mut self , arg : impl AsRef < OsStr > ) {
126
+ self . cmd ( ) . arg ( arg) ;
127
+ }
128
+
129
+ pub fn args ( & mut self , args : impl IntoIterator < Item : AsRef < OsStr > > ) {
130
+ self . cmd ( ) . args ( args) ;
131
+ }
132
+ }
133
+
124
134
pub struct GccLinker < ' a > {
125
135
cmd : Command ,
126
136
sess : & ' a Session ,
@@ -208,6 +218,9 @@ impl<'a> GccLinker<'a> {
208
218
}
209
219
210
220
impl < ' a > Linker for GccLinker < ' a > {
221
+ fn cmd ( & mut self ) -> & mut Command {
222
+ & mut self . cmd
223
+ }
211
224
fn link_dylib ( & mut self , lib : Symbol ) {
212
225
self . hint_dynamic ( ) ;
213
226
self . cmd . arg ( format ! ( "-l{}" , lib) ) ;
@@ -251,9 +264,6 @@ impl<'a> Linker for GccLinker<'a> {
251
264
fn build_static_executable ( & mut self ) {
252
265
self . cmd . arg ( "-static" ) ;
253
266
}
254
- fn args ( & mut self , args : & [ String ] ) {
255
- self . cmd . args ( args) ;
256
- }
257
267
258
268
fn link_rust_dylib ( & mut self , lib : Symbol , _path : & Path ) {
259
269
self . hint_dynamic ( ) ;
@@ -545,15 +555,15 @@ pub struct MsvcLinker<'a> {
545
555
}
546
556
547
557
impl < ' a > Linker for MsvcLinker < ' a > {
558
+ fn cmd ( & mut self ) -> & mut Command {
559
+ & mut self . cmd
560
+ }
548
561
fn link_rlib ( & mut self , lib : & Path ) {
549
562
self . cmd . arg ( lib) ;
550
563
}
551
564
fn add_object ( & mut self , path : & Path ) {
552
565
self . cmd . arg ( path) ;
553
566
}
554
- fn args ( & mut self , args : & [ String ] ) {
555
- self . cmd . args ( args) ;
556
- }
557
567
558
568
fn build_dylib ( & mut self , out_filename : & Path ) {
559
569
self . cmd . arg ( "/DLL" ) ;
@@ -778,6 +788,9 @@ pub struct EmLinker<'a> {
778
788
}
779
789
780
790
impl < ' a > Linker for EmLinker < ' a > {
791
+ fn cmd ( & mut self ) -> & mut Command {
792
+ & mut self . cmd
793
+ }
781
794
fn include_path ( & mut self , path : & Path ) {
782
795
self . cmd . arg ( "-L" ) . arg ( path) ;
783
796
}
@@ -837,10 +850,6 @@ impl<'a> Linker for EmLinker<'a> {
837
850
// noop
838
851
}
839
852
840
- fn args ( & mut self , args : & [ String ] ) {
841
- self . cmd . args ( args) ;
842
- }
843
-
844
853
fn framework_path ( & mut self , _path : & Path ) {
845
854
bug ! ( "frameworks are not supported on Emscripten" )
846
855
}
@@ -992,6 +1001,10 @@ impl<'a> WasmLd<'a> {
992
1001
}
993
1002
994
1003
impl < ' a > Linker for WasmLd < ' a > {
1004
+ fn cmd ( & mut self ) -> & mut Command {
1005
+ & mut self . cmd
1006
+ }
1007
+
995
1008
fn link_dylib ( & mut self , lib : Symbol ) {
996
1009
self . cmd . arg ( "-l" ) . sym_arg ( lib) ;
997
1010
}
@@ -1030,10 +1043,6 @@ impl<'a> Linker for WasmLd<'a> {
1030
1043
1031
1044
fn build_static_executable ( & mut self ) { }
1032
1045
1033
- fn args ( & mut self , args : & [ String ] ) {
1034
- self . cmd . args ( args) ;
1035
- }
1036
-
1037
1046
fn link_rust_dylib ( & mut self , lib : Symbol , _path : & Path ) {
1038
1047
self . cmd . arg ( "-l" ) . sym_arg ( lib) ;
1039
1048
}
@@ -1162,6 +1171,10 @@ pub struct PtxLinker<'a> {
1162
1171
}
1163
1172
1164
1173
impl < ' a > Linker for PtxLinker < ' a > {
1174
+ fn cmd ( & mut self ) -> & mut Command {
1175
+ & mut self . cmd
1176
+ }
1177
+
1165
1178
fn link_rlib ( & mut self , path : & Path ) {
1166
1179
self . cmd . arg ( "--rlib" ) . arg ( path) ;
1167
1180
}
@@ -1182,10 +1195,6 @@ impl<'a> Linker for PtxLinker<'a> {
1182
1195
self . cmd . arg ( "--bitcode" ) . arg ( path) ;
1183
1196
}
1184
1197
1185
- fn args ( & mut self , args : & [ String ] ) {
1186
- self . cmd . args ( args) ;
1187
- }
1188
-
1189
1198
fn optimize ( & mut self ) {
1190
1199
match self . sess . lto ( ) {
1191
1200
Lto :: Thin | Lto :: Fat | Lto :: ThinLocal => {
0 commit comments