88// Reason: the compiled binary is executed.
99//@ ignore-wasm
1010// Reason: WASM does not support dynamic libraries
11- //@ ignore-msvc
12- //FIXME(Oneirical): Getting this to work on MSVC requires passing libcmt.lib to CC,
13- // which is not trivial to do.
14- // Tracking issue: https://github.com/rust-lang/rust/issues/128602
15- // Discussion: https://github.com/rust-lang/rust/pull/128407#discussion_r1702439172
1611
17- use run_make_support:: { cc, regex, run, rustc} ;
12+ use run_make_support:: { cc, is_msvc , regex, run, rustc, static_lib_name } ;
1813
1914fn main ( ) {
2015 rustc ( ) . arg ( "-Cprefer-dynamic" ) . input ( "bar.rs" ) . run ( ) ;
@@ -29,9 +24,13 @@ fn main() {
2924 let re = regex:: Regex :: new ( r#"note: native-static-libs:\s*(.+)"# ) . unwrap ( ) ;
3025 let libs = re. find ( & libs) . unwrap ( ) . as_str ( ) . trim ( ) ;
3126 // remove the note
32- let ( _, library_search_paths ) = libs. split_once ( "note: native-static-libs: " ) . unwrap ( ) ;
27+ let ( _, native_link_args ) = libs. split_once ( "note: native-static-libs: " ) . unwrap ( ) ;
3328 // divide the command-line arguments in a vec
34- let library_search_paths = library_search_paths. split ( ' ' ) . collect :: < Vec < & str > > ( ) ;
35- cc ( ) . input ( "foo.c" ) . arg ( "-lfoo" ) . args ( library_search_paths) . out_exe ( "foo" ) . run ( ) ;
29+ let mut native_link_args = native_link_args. split ( ' ' ) . collect :: < Vec < & str > > ( ) ;
30+ if is_msvc ( ) {
31+ // For MSVC pass the arguments on to the linker.
32+ native_link_args. insert ( 0 , "-link" ) ;
33+ }
34+ cc ( ) . input ( "foo.c" ) . input ( static_lib_name ( "foo" ) ) . args ( native_link_args) . out_exe ( "foo" ) . run ( ) ;
3635 run ( "foo" ) ;
3736}
0 commit comments