Skip to content

Commit

Permalink
Auto merge of rust-lang#125613 - ChrisDenton:windows-recipie, r=jieyouxu
Browse files Browse the repository at this point in the history
Use `rmake` for `windows-` run-make tests

Convert some Makefile tests to recipes.

I renamed "issue-85441" to "windows-ws2_32" as I think it's slightly more descriptive. EDIT: `llvm-readobj` seems to work for reading DLL imports so I've used that instead of `objdump`.

cc rust-lang#121876
  • Loading branch information
bors committed May 28, 2024
2 parents da159eb + ad5dce5 commit 4b42964
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 62 deletions.
6 changes: 6 additions & 0 deletions src/tools/run-make-support/src/llvm_readobj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ impl LlvmReadobj {
self
}

/// Pass `--coff-imports` to display the Windows DLL imports
pub fn coff_imports(&mut self) -> &mut Self {
self.cmd.arg("--coff-imports");
self
}

/// Get the [`Output`][::std::process::Output] of the finished process.
#[track_caller]
pub fn command_output(&mut self) -> ::std::process::Output {
Expand Down
6 changes: 6 additions & 0 deletions src/tools/run-make-support/src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ impl Rustc {
self
}

/// Specify the linker
pub fn linker(&mut self, linker: &str) -> &mut Self {
self.cmd.arg(format!("-Clinker={linker}"));
self
}

/// Get the [`Output`][::std::process::Output] of the finished process.
#[track_caller]
pub fn command_output(&mut self) -> ::std::process::Output {
Expand Down
5 changes: 0 additions & 5 deletions src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ run-make/issue-83112-incr-test-moved-file/Makefile
run-make/issue-84395-lto-embed-bitcode/Makefile
run-make/issue-85019-moved-src-dir/Makefile
run-make/issue-85401-static-mir/Makefile
run-make/issue-85441/Makefile
run-make/issue-88756-default-output/Makefile
run-make/issue-97463-abi-param-passing/Makefile
run-make/jobserver-error/Makefile
Expand Down Expand Up @@ -275,8 +274,4 @@ run-make/volatile-intrinsics/Makefile
run-make/wasm-exceptions-nostd/Makefile
run-make/wasm-override-linker/Makefile
run-make/weird-output-filenames/Makefile
run-make/windows-binary-no-external-deps/Makefile
run-make/windows-safeseh/Makefile
run-make/windows-spawn/Makefile
run-make/windows-subsystem/Makefile
run-make/x86_64-fortanix-unknown-sgx-lvi/Makefile
9 changes: 0 additions & 9 deletions tests/run-make/issue-85441/Makefile

This file was deleted.

9 changes: 0 additions & 9 deletions tests/run-make/windows-binary-no-external-deps/Makefile

This file was deleted.

15 changes: 15 additions & 0 deletions tests/run-make/windows-binary-no-external-deps/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//@ only-windows

// Ensure that we aren't relying on any non-system DLLs when compiling and running
// a "hello world" application by setting `PATH` to `C:\Windows\System32`.

use run_make_support::{run, rustc};
use std::env;
use std::path::PathBuf;

fn main() {
let windows_dir = env::var("SystemRoot").unwrap();
let system32: PathBuf = [&windows_dir, "System32"].iter().collect();
rustc().input("hello.rs").env("PATH", system32).run();
run("hello");
}
19 changes: 0 additions & 19 deletions tests/run-make/windows-safeseh/Makefile

This file was deleted.

15 changes: 15 additions & 0 deletions tests/run-make/windows-safeseh/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//@ only-windows
//@ needs-rust-lld

use run_make_support::rustc;

fn main() {
// Ensure that LLD can link when an .rlib contains a synthetic object
// file referencing exported or used symbols.
rustc().input("foo.rs").linker("rust-lld").run();

// Ensure that LLD can link when /WHOLEARCHIVE: is used with an .rlib.
// Previously, lib.rmeta was not marked as (trivially) SAFESEH-aware.
rustc().input("baz.rs").run();
rustc().input("bar.rs").linker("rust-lld").link_arg("/WHOLEARCHIVE:libbaz.rlib").run();
}
8 changes: 0 additions & 8 deletions tests/run-make/windows-spawn/Makefile

This file was deleted.

17 changes: 17 additions & 0 deletions tests/run-make/windows-spawn/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@ only-windows

use run_make_support::{run, rustc, tmp_dir};

// On Windows `Command` uses `CreateProcessW` to run a new process.
// However, in the past std used to not pass in the application name, leaving
// `CreateProcessW` to use heuristics to guess the intended name from the
// command line string. Sometimes this could go very wrong.
// E.g. in Rust 1.0 `Command::new("foo").arg("bar").spawn()` will try to launch
// `foo bar.exe` if foo.exe does not exist. Which is clearly not desired.

fn main() {
let out_dir = tmp_dir();
rustc().input("hello.rs").output(out_dir.join("hopefullydoesntexist bar.exe")).run();
rustc().input("spawn.rs").run();
run("spawn");
}
10 changes: 4 additions & 6 deletions tests/run-make/windows-spawn/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ use std::process::Command;

fn main() {
// Make sure it doesn't try to run "hopefullydoesntexist bar.exe".
assert_eq!(Command::new("hopefullydoesntexist")
.arg("bar")
.spawn()
.unwrap_err()
.kind(),
ErrorKind::NotFound);
assert_eq!(
Command::new("hopefullydoesntexist").arg("bar").spawn().unwrap_err().kind(),
ErrorKind::NotFound
)
}
6 changes: 0 additions & 6 deletions tests/run-make/windows-subsystem/Makefile

This file was deleted.

File renamed without changes.
13 changes: 13 additions & 0 deletions tests/run-make/windows-ws2_32/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//@ only-msvc

// Tests that WS2_32.dll is not unnecessarily linked, see issue #85441

use run_make_support::{llvm_readobj, rustc, tmp_dir};

fn main() {
rustc().input("empty.rs").run();
let empty = tmp_dir().join("empty.exe");
let output = llvm_readobj().input(empty).coff_imports().run();
let output = String::from_utf8(output.stdout).unwrap();
assert!(!output.to_ascii_uppercase().contains("WS2_32.DLL"));
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ run-pass
#![windows_subsystem = "console"]

fn main() {}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ run-pass
#![windows_subsystem = "windows"]

fn main() {}

0 comments on commit 4b42964

Please sign in to comment.