@@ -87,6 +87,7 @@ impl LinkerInfo {
8787/// used to dispatch on whether a GNU-like linker (generally `ld.exe`) or an
8888/// MSVC linker (e.g., `link.exe`) is being used.
8989pub trait Linker {
90+ fn cmd ( & mut self ) -> & mut Command ;
9091 fn link_dylib ( & mut self , lib : Symbol ) ;
9192 fn link_rust_dylib ( & mut self , lib : Symbol , path : & Path ) ;
9293 fn link_framework ( & mut self , framework : Symbol ) ;
@@ -111,7 +112,6 @@ pub trait Linker {
111112 fn no_default_libraries ( & mut self ) ;
112113 fn build_dylib ( & mut self , out_filename : & Path ) ;
113114 fn build_static_executable ( & mut self ) ;
114- fn args ( & mut self , args : & [ String ] ) ;
115115 fn export_symbols ( & mut self , tmpdir : & Path , crate_type : CrateType ) ;
116116 fn subsystem ( & mut self , subsystem : & str ) ;
117117 fn group_start ( & mut self ) ;
@@ -121,6 +121,16 @@ pub trait Linker {
121121 fn finalize ( & mut self ) -> Command ;
122122}
123123
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+
124134pub struct GccLinker < ' a > {
125135 cmd : Command ,
126136 sess : & ' a Session ,
@@ -208,6 +218,9 @@ impl<'a> GccLinker<'a> {
208218}
209219
210220impl < ' a > Linker for GccLinker < ' a > {
221+ fn cmd ( & mut self ) -> & mut Command {
222+ & mut self . cmd
223+ }
211224 fn link_dylib ( & mut self , lib : Symbol ) {
212225 self . hint_dynamic ( ) ;
213226 self . cmd . arg ( format ! ( "-l{}" , lib) ) ;
@@ -251,9 +264,6 @@ impl<'a> Linker for GccLinker<'a> {
251264 fn build_static_executable ( & mut self ) {
252265 self . cmd . arg ( "-static" ) ;
253266 }
254- fn args ( & mut self , args : & [ String ] ) {
255- self . cmd . args ( args) ;
256- }
257267
258268 fn link_rust_dylib ( & mut self , lib : Symbol , _path : & Path ) {
259269 self . hint_dynamic ( ) ;
@@ -545,15 +555,15 @@ pub struct MsvcLinker<'a> {
545555}
546556
547557impl < ' a > Linker for MsvcLinker < ' a > {
558+ fn cmd ( & mut self ) -> & mut Command {
559+ & mut self . cmd
560+ }
548561 fn link_rlib ( & mut self , lib : & Path ) {
549562 self . cmd . arg ( lib) ;
550563 }
551564 fn add_object ( & mut self , path : & Path ) {
552565 self . cmd . arg ( path) ;
553566 }
554- fn args ( & mut self , args : & [ String ] ) {
555- self . cmd . args ( args) ;
556- }
557567
558568 fn build_dylib ( & mut self , out_filename : & Path ) {
559569 self . cmd . arg ( "/DLL" ) ;
@@ -778,6 +788,9 @@ pub struct EmLinker<'a> {
778788}
779789
780790impl < ' a > Linker for EmLinker < ' a > {
791+ fn cmd ( & mut self ) -> & mut Command {
792+ & mut self . cmd
793+ }
781794 fn include_path ( & mut self , path : & Path ) {
782795 self . cmd . arg ( "-L" ) . arg ( path) ;
783796 }
@@ -837,10 +850,6 @@ impl<'a> Linker for EmLinker<'a> {
837850 // noop
838851 }
839852
840- fn args ( & mut self , args : & [ String ] ) {
841- self . cmd . args ( args) ;
842- }
843-
844853 fn framework_path ( & mut self , _path : & Path ) {
845854 bug ! ( "frameworks are not supported on Emscripten" )
846855 }
@@ -992,6 +1001,10 @@ impl<'a> WasmLd<'a> {
9921001}
9931002
9941003impl < ' a > Linker for WasmLd < ' a > {
1004+ fn cmd ( & mut self ) -> & mut Command {
1005+ & mut self . cmd
1006+ }
1007+
9951008 fn link_dylib ( & mut self , lib : Symbol ) {
9961009 self . cmd . arg ( "-l" ) . sym_arg ( lib) ;
9971010 }
@@ -1030,10 +1043,6 @@ impl<'a> Linker for WasmLd<'a> {
10301043
10311044 fn build_static_executable ( & mut self ) { }
10321045
1033- fn args ( & mut self , args : & [ String ] ) {
1034- self . cmd . args ( args) ;
1035- }
1036-
10371046 fn link_rust_dylib ( & mut self , lib : Symbol , _path : & Path ) {
10381047 self . cmd . arg ( "-l" ) . sym_arg ( lib) ;
10391048 }
@@ -1162,6 +1171,10 @@ pub struct PtxLinker<'a> {
11621171}
11631172
11641173impl < ' a > Linker for PtxLinker < ' a > {
1174+ fn cmd ( & mut self ) -> & mut Command {
1175+ & mut self . cmd
1176+ }
1177+
11651178 fn link_rlib ( & mut self , path : & Path ) {
11661179 self . cmd . arg ( "--rlib" ) . arg ( path) ;
11671180 }
@@ -1182,10 +1195,6 @@ impl<'a> Linker for PtxLinker<'a> {
11821195 self . cmd . arg ( "--bitcode" ) . arg ( path) ;
11831196 }
11841197
1185- fn args ( & mut self , args : & [ String ] ) {
1186- self . cmd . args ( args) ;
1187- }
1188-
11891198 fn optimize ( & mut self ) {
11901199 match self . sess . lto ( ) {
11911200 Lto :: Thin | Lto :: Fat | Lto :: ThinLocal => {
0 commit comments