Skip to content

Commit 4c50674

Browse files
committed
Test wholearchive on rust staticlib
1 parent 6de928d commit 4c50674

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-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
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 std::path::Path;
8+
9+
use run_make_support::{cc, env_var, extra_c_flags, rustc};
10+
11+
fn main() {
12+
// FIXME: Make this test either work with or ignore LLVM.
13+
if false {
14+
return;
15+
}
16+
// Build the staticlib
17+
rustc().crate_type("staticlib").input("static.rs").output("static.lib").run();
18+
// Create an empty obj file (using the C compiler)
19+
// Then use it to link in the staticlib using `/WHOLEARCHIVE` and produce a DLL.
20+
// We test for `cl.exe` to ensure we're using MSVC's tools and not the LLVM equivalents.
21+
22+
if env_var("CC").ends_with("cl.exe") {
23+
cc().input("c.c")
24+
.args([
25+
"-MT",
26+
"-link",
27+
"-WHOLEARCHIVE:./static.lib",
28+
"-dll",
29+
"-def:dll.def",
30+
"-out:dll.dll",
31+
])
32+
.args(extra_c_flags())
33+
.run();
34+
}
35+
36+
// As a sanity check, make sure it works without /WHOLEARCHIVE
37+
cc().input("c.c")
38+
.args(["-MT", "-link", "./static.lib", "-dll", "-def:dll.def", "-out:dll2.dll"])
39+
.args(extra_c_flags())
40+
.run();
41+
}
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)