about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-08-09 05:52:16 +0200
committerGitHub <noreply@github.com>2024-08-09 05:52:16 +0200
commit521e75412f6b4186a5d43f0489012872fea94fb7 (patch)
tree70a34cfd0d4d71871bb79716c87c7ef5b954d8d4
parent408baccd0dbda23763ce9c4451d3881099fed80f (diff)
parent8725f7ee4c4af1c961464117aa9f643bae859924 (diff)
downloadrust-521e75412f6b4186a5d43f0489012872fea94fb7.tar.gz
rust-521e75412f6b4186a5d43f0489012872fea94fb7.zip
Rollup merge of #128823 - ChrisDenton:staticlib, r=jieyouxu
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
-rw-r--r--tests/run-make/staticlib-dylib-linkage/rmake.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/tests/run-make/staticlib-dylib-linkage/rmake.rs b/tests/run-make/staticlib-dylib-linkage/rmake.rs
index 415491bb8ee..8dd1ac0ffbd 100644
--- a/tests/run-make/staticlib-dylib-linkage/rmake.rs
+++ b/tests/run-make/staticlib-dylib-linkage/rmake.rs
@@ -8,13 +8,8 @@
 // Reason: the compiled binary is executed.
 //@ ignore-wasm
 // Reason: WASM does not support dynamic libraries
-//@ ignore-msvc
-//FIXME(Oneirical): Getting this to work on MSVC requires passing libcmt.lib to CC,
-// which is not trivial to do.
-// Tracking issue: https://github.com/rust-lang/rust/issues/128602
-// Discussion: https://github.com/rust-lang/rust/pull/128407#discussion_r1702439172
 
-use run_make_support::{cc, regex, run, rustc};
+use run_make_support::{cc, is_msvc, regex, run, rustc, static_lib_name};
 
 fn main() {
     rustc().arg("-Cprefer-dynamic").input("bar.rs").run();
@@ -29,9 +24,13 @@ fn main() {
     let re = regex::Regex::new(r#"note: native-static-libs:\s*(.+)"#).unwrap();
     let libs = re.find(&libs).unwrap().as_str().trim();
     // remove the note
-    let (_, library_search_paths) = libs.split_once("note: native-static-libs: ").unwrap();
+    let (_, native_link_args) = libs.split_once("note: native-static-libs: ").unwrap();
     // divide the command-line arguments in a vec
-    let library_search_paths = library_search_paths.split(' ').collect::<Vec<&str>>();
-    cc().input("foo.c").arg("-lfoo").args(library_search_paths).out_exe("foo").run();
+    let mut native_link_args = native_link_args.split(' ').collect::<Vec<&str>>();
+    if is_msvc() {
+        // For MSVC pass the arguments on to the linker.
+        native_link_args.insert(0, "-link");
+    }
+    cc().input("foo.c").input(static_lib_name("foo")).args(native_link_args).out_exe("foo").run();
     run("foo");
 }