Skip to content

Commit e9b7aa0

Browse files
committed
Auto merge of rust-lang#125613 - ChrisDenton:windows-recipie, r=jieyouxu
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
2 parents a83f933 + f34bbde commit e9b7aa0

File tree

18 files changed

+97
-62
lines changed

18 files changed

+97
-62
lines changed

src/tools/run-make-support/src/rustc.rs

+6
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ impl Rustc {
203203
self
204204
}
205205

206+
/// Specify the linker
207+
pub fn linker(&mut self, linker: &str) -> &mut Self {
208+
self.cmd.arg(format!("-Clinker={linker}"));
209+
self
210+
}
211+
206212
/// Get the [`Output`] of the finished process.
207213
#[track_caller]
208214
pub fn command_output(&mut self) -> ::std::process::Output {

src/tools/tidy/src/allowed_run_make_makefiles.txt

-5
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ run-make/issue-83112-incr-test-moved-file/Makefile
116116
run-make/issue-84395-lto-embed-bitcode/Makefile
117117
run-make/issue-85019-moved-src-dir/Makefile
118118
run-make/issue-85401-static-mir/Makefile
119-
run-make/issue-85441/Makefile
120119
run-make/issue-88756-default-output/Makefile
121120
run-make/issue-97463-abi-param-passing/Makefile
122121
run-make/jobserver-error/Makefile
@@ -272,8 +271,4 @@ run-make/volatile-intrinsics/Makefile
272271
run-make/wasm-exceptions-nostd/Makefile
273272
run-make/wasm-override-linker/Makefile
274273
run-make/weird-output-filenames/Makefile
275-
run-make/windows-binary-no-external-deps/Makefile
276-
run-make/windows-safeseh/Makefile
277-
run-make/windows-spawn/Makefile
278-
run-make/windows-subsystem/Makefile
279274
run-make/x86_64-fortanix-unknown-sgx-lvi/Makefile

tests/run-make/issue-85441/Makefile

-9
This file was deleted.

tests/run-make/windows-binary-no-external-deps/Makefile

-9
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! Ensure that we aren't relying on any non-system DLLs when running
2+
//! a "hello world" application by setting `PATH` to `C:\Windows\System32`.
3+
//@ only-windows
4+
5+
use run_make_support::{rustc, tmp_dir};
6+
use std::env;
7+
use std::path::PathBuf;
8+
use std::process::Command;
9+
10+
fn main() {
11+
rustc().input("hello.rs").run();
12+
13+
let windows_dir = env::var("SystemRoot").unwrap();
14+
let system32: PathBuf = [&windows_dir, "System32"].iter().collect();
15+
// Note: This does not use the support wrappers so that we can precisely control the PATH
16+
let exe = tmp_dir().join("hello.exe");
17+
let status = Command::new(exe).env("PATH", &system32).spawn().unwrap().wait().unwrap();
18+
if !status.success() {
19+
panic!("Command failed!\noutput status: `{status}`");
20+
}
21+
}

tests/run-make/windows-safeseh/Makefile

-19
This file was deleted.
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ only-windows
2+
//@ needs-rust-lld
3+
4+
use run_make_support::rustc;
5+
6+
fn main() {
7+
// Ensure that LLD can link when an .rlib contains a synthetic object
8+
// file referencing exported or used symbols.
9+
rustc().input("foo.rs").linker("rust-lld").run();
10+
11+
// Ensure that LLD can link when /WHOLEARCHIVE: is used with an .rlib.
12+
// Previously, lib.rmeta was not marked as (trivially) SAFESEH-aware.
13+
rustc().input("baz.rs").run();
14+
rustc().input("bar.rs").linker("rust-lld").link_arg("/WHOLEARCHIVE:libbaz.rlib").run();
15+
}

tests/run-make/windows-spawn/Makefile

-8
This file was deleted.

tests/run-make/windows-spawn/rmake.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ only-windows
2+
3+
use run_make_support::{run, rustc, tmp_dir};
4+
5+
// On Windows `Command` uses `CreateProcessW` to run a new process.
6+
// However, in the past std used to not pass in the application name, leaving
7+
// `CreateProcessW` to use heuristics to guess the intended name from the
8+
// command line string. Sometimes this could go very wrong.
9+
// E.g. in Rust 1.0 `Command::new("foo").arg("bar").spawn()` will try to launch
10+
// `foo bar.exe` if foo.exe does not exist. Which is clearly not desired.
11+
12+
fn main() {
13+
let out_dir = tmp_dir();
14+
rustc().input("hello.rs").output(out_dir.join("hopefullydoesntexist bar.exe")).run();
15+
rustc().input("spawn.rs").run();
16+
run("spawn");
17+
}

tests/run-make/windows-spawn/spawn.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ use std::process::Command;
33

44
fn main() {
55
// Make sure it doesn't try to run "hopefullydoesntexist bar.exe".
6-
assert_eq!(Command::new("hopefullydoesntexist")
7-
.arg("bar")
8-
.spawn()
9-
.unwrap_err()
10-
.kind(),
11-
ErrorKind::NotFound);
6+
assert_eq!(
7+
Command::new("hopefullydoesntexist").arg("bar").spawn().unwrap_err().kind(),
8+
ErrorKind::NotFound
9+
)
1210
}

tests/run-make/windows-subsystem/Makefile

-6
This file was deleted.
File renamed without changes.
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//@ only-msvc
2+
3+
// Tests that WS2_32.dll is not unnecessarily linked, see issue #85441
4+
5+
use run_make_support::object::{self, read::Object};
6+
use run_make_support::{rustc, tmp_dir};
7+
use std::fs;
8+
9+
fn main() {
10+
rustc().input("empty.rs").run();
11+
rustc().input("tcp.rs").run();
12+
13+
assert!(!links_ws2_32("empty.exe"));
14+
assert!(links_ws2_32("tcp.exe"));
15+
}
16+
17+
fn links_ws2_32(exe: &str) -> bool {
18+
let path = tmp_dir().join(exe);
19+
let binary_data = fs::read(path).unwrap();
20+
let file = object::File::parse(&*binary_data).unwrap();
21+
for import in file.imports().unwrap() {
22+
if import.library().eq_ignore_ascii_case(b"WS2_32.dll") {
23+
return true;
24+
}
25+
}
26+
false
27+
}

tests/run-make/windows-ws2_32/tcp.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use std::net::TcpListener;
2+
3+
fn main() {
4+
TcpListener::bind("127.0.0.1:80").unwrap();
5+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//@ run-pass
12
#![windows_subsystem = "console"]
23

34
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//@ run-pass
12
#![windows_subsystem = "windows"]
23

34
fn main() {}

0 commit comments

Comments
 (0)