Skip to content

Commit 3b4de45

Browse files
committed
Add test for MSVC WHOLEARCHIVE
1 parent c396e36 commit 3b4de45

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

tests/run-make/msvc-wholearchive/c.c

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// This page is intentionally left blank
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
LIBRARY dll
2+
EXPORTS
3+
hello
4+
number
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ only-msvc
2+
// Reason: this is testing the MSVC linker
3+
4+
// This is a regression test for #129020
5+
// It ensures we can link a rust staticlib into DLL using the MSVC linker
6+
7+
use run_make_support::run::cmd;
8+
use run_make_support::rustc;
9+
10+
fn main() {
11+
// BUild the staticlib
12+
rustc().crate_type("staticlib").input("static.rs").output("static.lib").run();
13+
// Create an empty obj file (using the C compiler)
14+
// Then use it to link in the staticlib using `/WHOLEARCHIVE` and produce a DLL.
15+
// We call link.exe directly because this test is only for MSVC and not their LLVM equivalents
16+
cmd("cl.exe").args(&["c.c", "-nologo", "-c", "-MT"]).run();
17+
cmd("link.exe")
18+
.args(&["c", "/WHOLEARCHIVE:./static.lib", "/dll", "/def:dll.def", "/out:dll.dll"])
19+
// Import libs
20+
.args(&["libcmt.lib", "kernel32.lib", "ws2_32.lib", "ntdll.lib", "userenv.lib"])
21+
.run();
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#[no_mangle]
2+
pub extern "C" fn hello() {
3+
println!("Hello world!");
4+
}
5+
6+
#[no_mangle]
7+
pub extern "C" fn number() -> u32 {
8+
42
9+
}

0 commit comments

Comments
 (0)