Skip to content

Commit

Permalink
Add test for MSVC WHOLEARCHIVE
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDenton committed Aug 16, 2024
1 parent c396e36 commit c9451ac
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/run-make/msvc-wholearchive/c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// This page is intentionally left blank
4 changes: 4 additions & 0 deletions tests/run-make/msvc-wholearchive/dll.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
LIBRARY dll
EXPORTS
hello
number
22 changes: 22 additions & 0 deletions tests/run-make/msvc-wholearchive/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//@ only-msvc
// Reason: this is testing the MSVC linker

// This is a regression test for #129020
// It ensures we can link a rust staticlib into DLL using the MSVC linker

use run_make_support::run::cmd;
use run_make_support::rustc;

fn main() {
// Build the staticlib
rustc().crate_type("staticlib").input("static.rs").output("static.lib").run();
// Create an empty obj file (using the C compiler)
// Then use it to link in the staticlib using `/WHOLEARCHIVE` and produce a DLL.
// We call link.exe directly because this test is only for MSVC and not their LLVM equivalents
cmd("cl.exe").args(&["c.c", "-nologo", "-c", "-MT"]).run();
cmd("link.exe")
.args(&["c", "/WHOLEARCHIVE:./static.lib", "/dll", "/def:dll.def", "/out:dll.dll"])
// Import libs
.args(&["libcmt.lib", "kernel32.lib", "ws2_32.lib", "ntdll.lib", "userenv.lib"])
.run();
}
9 changes: 9 additions & 0 deletions tests/run-make/msvc-wholearchive/static.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[no_mangle]
pub extern "C" fn hello() {
println!("Hello world!");
}

#[no_mangle]
pub extern "C" fn number() -> u32 {
42
}

0 comments on commit c9451ac

Please sign in to comment.