Skip to content

Commit 7de7c95

Browse files
committed
fix: Include windows.lib in manual mutest-driver UI test invocations
When running UI tests we invoke mutest-driver directly, rather than through Cargo, which means we have to add `windows.lib` to the linker search path manually. See rust-lang/rust#99466 for more details.
1 parent fadcf68 commit 7de7c95

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ version = "0.0.0"
66
edition = "2021"
77

88
[dependencies]
9+
cargo_metadata = "0.18"
910
clap = { version = "4", features = ["cargo"] }
1011
similar = { version = "2", features = ["inline"] }

tests/src/main.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,23 @@ fn run_test(path: &Path, aux_dir_path: &Path, root_dir: &Path, opts: &Opts, resu
250250
mutest_subcommand.unwrap_or("build")
251251
};
252252

253+
// HACK: We invoke mutest-driver directly, rather than through Cargo, which means
254+
// we have to add `windows.lib` to the linker search path manually.
255+
// See https://github.com/rust-lang/rust/issues/99466.
256+
#[cfg(windows)]
257+
let windows_lib = {
258+
// FIXME: Include all available `windows-targets` platform variants.
259+
#[cfg(all(target_arch = "x86_64", target_env = "msvc"))]
260+
const WINDOWS_IMPORT_LIB: &str = "windows_x86_64_msvc";
261+
#[cfg(all(target_arch = "aarch64", target_env = "msvc"))]
262+
const WINDOWS_IMPORT_LIB: &str = "windows_aarch64_msvc";
263+
264+
let metadata_cmd = cargo_metadata::MetadataCommand::new();
265+
let metadata = metadata_cmd.exec().expect("could not retrieve Cargo metadata");
266+
let windows_package = metadata.packages.iter().find(|package| package.name == WINDOWS_IMPORT_LIB).expect("could not retrieve windows.lib import package from manifest");
267+
windows_package.manifest_path.parent().expect("invalid windows.lib import package manifest path").join("lib")
268+
};
269+
253270
let mut aux = false;
254271
for directive in &directives {
255272
let Some(aux_build) = directive.strip_prefix("aux-build:").map(str::trim) else { continue; };
@@ -268,6 +285,9 @@ fn run_test(path: &Path, aux_dir_path: &Path, root_dir: &Path, opts: &Opts, resu
268285

269286
cmd.args(["--out-dir", AUX_OUT_DIR]);
270287

288+
#[cfg(windows)]
289+
cmd.args(["-L", windows_lib.as_str()]);
290+
271291
if opts.verbosity >= 1 {
272292
eprintln!("running {cmd:?}");
273293
}
@@ -313,6 +333,9 @@ fn run_test(path: &Path, aux_dir_path: &Path, root_dir: &Path, opts: &Opts, resu
313333

314334
cmd.env("MUTEST_SEARCH_PATH", "target/release");
315335

336+
#[cfg(windows)]
337+
cmd.args(["-L", windows_lib.as_str()]);
338+
316339
let rustc_flags = directives.iter().filter_map(|d| d.strip_prefix("rustc-flags:").map(str::trim))
317340
.flat_map(|flags| flags.split(" ").filter(|flag| !flag.is_empty()));
318341
cmd.args(rustc_flags);

0 commit comments

Comments
 (0)