Skip to content

Commit a51e9c2

Browse files
committed
Auto merge of #128823 - ChrisDenton:staticlib, r=<try>
run-make: enable msvc for staticlib-dylib-linkage `-Zstaticlib-allow-rdylib-deps` on MSVC returns things like `/LIBPATH:R:\rust\build\x86_64-pc-windows-msvc\test\run-make\staticlib-dylib-linkage\rmake_out`. That is a linker argument rather than a `cc` argument. Which makes sense because rustc interacts directly with the linker on MSVC targets. So we need to tell the C compiler to pass on the arguments to the linker. try-job: x86_64-msvc try-job: i686-msvc
2 parents 9337f7a + 8725f7e commit a51e9c2

File tree

1 file changed

+8
-9
lines changed
  • tests/run-make/staticlib-dylib-linkage

1 file changed

+8
-9
lines changed

tests/run-make/staticlib-dylib-linkage/rmake.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@
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

1914
fn 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

Comments
 (0)