about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-05-29 18:03:55 +0000
committerbors <bors@rust-lang.org>2024-05-29 18:03:55 +0000
commite9b7aa08f7cd890dcebd36c198193707d5cd3770 (patch)
treeef1b51d063b393865cf955a990312aa3d0711900
parenta83f933a9da258cf037e3cab37cd486bfd861a7d (diff)
parentf34bbdecc4cd8e39470cbe2cefe96d4aed351da9 (diff)
downloadrust-e9b7aa08f7cd890dcebd36c198193707d5cd3770.tar.gz
rust-e9b7aa08f7cd890dcebd36c198193707d5cd3770.zip
Auto merge of #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 #121876
-rw-r--r--src/tools/run-make-support/src/rustc.rs6
-rw-r--r--src/tools/tidy/src/allowed_run_make_makefiles.txt5
-rw-r--r--tests/run-make/issue-85441/Makefile9
-rw-r--r--tests/run-make/windows-binary-no-external-deps/Makefile9
-rw-r--r--tests/run-make/windows-binary-no-external-deps/rmake.rs21
-rw-r--r--tests/run-make/windows-safeseh/Makefile19
-rw-r--r--tests/run-make/windows-safeseh/rmake.rs15
-rw-r--r--tests/run-make/windows-spawn/Makefile8
-rw-r--r--tests/run-make/windows-spawn/rmake.rs17
-rw-r--r--tests/run-make/windows-spawn/spawn.rs10
-rw-r--r--tests/run-make/windows-subsystem/Makefile6
-rw-r--r--tests/run-make/windows-ws2_32/empty.rs (renamed from tests/run-make/issue-85441/empty.rs)0
-rw-r--r--tests/run-make/windows-ws2_32/rmake.rs27
-rw-r--r--tests/run-make/windows-ws2_32/tcp.rs5
-rw-r--r--tests/ui/windows-subsystem/console.rs (renamed from tests/run-make/windows-subsystem/console.rs)1
-rw-r--r--tests/ui/windows-subsystem/windows-subsystem-invalid.rs (renamed from tests/ui/windows-subsystem-invalid.rs)0
-rw-r--r--tests/ui/windows-subsystem/windows-subsystem-invalid.stderr (renamed from tests/ui/windows-subsystem-invalid.stderr)0
-rw-r--r--tests/ui/windows-subsystem/windows.rs (renamed from tests/run-make/windows-subsystem/windows.rs)1
18 files changed, 97 insertions, 62 deletions
diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs
index b424ae3f421..5dde0f91fea 100644
--- a/src/tools/run-make-support/src/rustc.rs
+++ b/src/tools/run-make-support/src/rustc.rs
@@ -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`] of the finished process.
     #[track_caller]
     pub fn command_output(&mut self) -> ::std::process::Output {
diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index 75cd2b4c773..fac11cd1566 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -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
@@ -272,8 +271,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
diff --git a/tests/run-make/issue-85441/Makefile b/tests/run-make/issue-85441/Makefile
deleted file mode 100644
index 987d7f7d4a7..00000000000
--- a/tests/run-make/issue-85441/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
-# only-windows-msvc
-
-include ../tools.mk
-
-# Tests that WS2_32.dll is not unnecessarily linked, see issue #85441
-
-all:
-	$(RUSTC) empty.rs
-	objdump -p $(TMPDIR)/empty.exe | $(CGREP) -v -i "WS2_32.dll"
diff --git a/tests/run-make/windows-binary-no-external-deps/Makefile b/tests/run-make/windows-binary-no-external-deps/Makefile
deleted file mode 100644
index 8960020fed5..00000000000
--- a/tests/run-make/windows-binary-no-external-deps/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
-include ../tools.mk
-
-# only-windows
-
-PATH=$(SYSTEMROOT)/system32
-
-all:
-	$(RUSTC) hello.rs
-	$(TMPDIR)/hello.exe
diff --git a/tests/run-make/windows-binary-no-external-deps/rmake.rs b/tests/run-make/windows-binary-no-external-deps/rmake.rs
new file mode 100644
index 00000000000..6704fe04148
--- /dev/null
+++ b/tests/run-make/windows-binary-no-external-deps/rmake.rs
@@ -0,0 +1,21 @@
+//! Ensure that we aren't relying on any non-system DLLs when running
+//! a "hello world" application by setting `PATH` to `C:\Windows\System32`.
+//@ only-windows
+
+use run_make_support::{rustc, tmp_dir};
+use std::env;
+use std::path::PathBuf;
+use std::process::Command;
+
+fn main() {
+    rustc().input("hello.rs").run();
+
+    let windows_dir = env::var("SystemRoot").unwrap();
+    let system32: PathBuf = [&windows_dir, "System32"].iter().collect();
+    // Note: This does not use the support wrappers so that we can precisely control the PATH
+    let exe = tmp_dir().join("hello.exe");
+    let status = Command::new(exe).env("PATH", &system32).spawn().unwrap().wait().unwrap();
+    if !status.success() {
+        panic!("Command failed!\noutput status: `{status}`");
+    }
+}
diff --git a/tests/run-make/windows-safeseh/Makefile b/tests/run-make/windows-safeseh/Makefile
deleted file mode 100644
index d6a403961d7..00000000000
--- a/tests/run-make/windows-safeseh/Makefile
+++ /dev/null
@@ -1,19 +0,0 @@
-# only-windows
-# needs-rust-lld
-
-include ../tools.mk
-
-all: foo bar
-
-# Ensure that LLD can link when an .rlib contains a synthetic object
-# file referencing exported or used symbols.
-foo:
-	$(RUSTC) -C linker=rust-lld foo.rs
-
-# Ensure that LLD can link when /WHOLEARCHIVE: is used with an .rlib.
-# Previously, lib.rmeta was not marked as (trivially) SAFESEH-aware.
-bar: baz
-	$(RUSTC) -C linker=rust-lld -C link-arg=/WHOLEARCHIVE:libbaz.rlib bar.rs
-
-baz:
-	$(RUSTC) baz.rs
diff --git a/tests/run-make/windows-safeseh/rmake.rs b/tests/run-make/windows-safeseh/rmake.rs
new file mode 100644
index 00000000000..10e6b38aa8d
--- /dev/null
+++ b/tests/run-make/windows-safeseh/rmake.rs
@@ -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();
+}
diff --git a/tests/run-make/windows-spawn/Makefile b/tests/run-make/windows-spawn/Makefile
deleted file mode 100644
index b6cdb169bab..00000000000
--- a/tests/run-make/windows-spawn/Makefile
+++ /dev/null
@@ -1,8 +0,0 @@
-include ../tools.mk
-
-# only-windows
-
-all:
-	$(RUSTC) -o "$(TMPDIR)/hopefullydoesntexist bar.exe" hello.rs
-	$(RUSTC) spawn.rs
-	$(TMPDIR)/spawn.exe
diff --git a/tests/run-make/windows-spawn/rmake.rs b/tests/run-make/windows-spawn/rmake.rs
new file mode 100644
index 00000000000..fb9cf1e2149
--- /dev/null
+++ b/tests/run-make/windows-spawn/rmake.rs
@@ -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");
+}
diff --git a/tests/run-make/windows-spawn/spawn.rs b/tests/run-make/windows-spawn/spawn.rs
index c34da3d5fde..a9e86d1577e 100644
--- a/tests/run-make/windows-spawn/spawn.rs
+++ b/tests/run-make/windows-spawn/spawn.rs
@@ -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
+    )
 }
diff --git a/tests/run-make/windows-subsystem/Makefile b/tests/run-make/windows-subsystem/Makefile
deleted file mode 100644
index e3cf9181de4..00000000000
--- a/tests/run-make/windows-subsystem/Makefile
+++ /dev/null
@@ -1,6 +0,0 @@
-# ignore-cross-compile
-include ../tools.mk
-
-all:
-	$(RUSTC) windows.rs
-	$(RUSTC) console.rs
diff --git a/tests/run-make/issue-85441/empty.rs b/tests/run-make/windows-ws2_32/empty.rs
index f328e4d9d04..f328e4d9d04 100644
--- a/tests/run-make/issue-85441/empty.rs
+++ b/tests/run-make/windows-ws2_32/empty.rs
diff --git a/tests/run-make/windows-ws2_32/rmake.rs b/tests/run-make/windows-ws2_32/rmake.rs
new file mode 100644
index 00000000000..543f8594478
--- /dev/null
+++ b/tests/run-make/windows-ws2_32/rmake.rs
@@ -0,0 +1,27 @@
+//@ only-msvc
+
+// Tests that WS2_32.dll is not unnecessarily linked, see issue #85441
+
+use run_make_support::object::{self, read::Object};
+use run_make_support::{rustc, tmp_dir};
+use std::fs;
+
+fn main() {
+    rustc().input("empty.rs").run();
+    rustc().input("tcp.rs").run();
+
+    assert!(!links_ws2_32("empty.exe"));
+    assert!(links_ws2_32("tcp.exe"));
+}
+
+fn links_ws2_32(exe: &str) -> bool {
+    let path = tmp_dir().join(exe);
+    let binary_data = fs::read(path).unwrap();
+    let file = object::File::parse(&*binary_data).unwrap();
+    for import in file.imports().unwrap() {
+        if import.library().eq_ignore_ascii_case(b"WS2_32.dll") {
+            return true;
+        }
+    }
+    false
+}
diff --git a/tests/run-make/windows-ws2_32/tcp.rs b/tests/run-make/windows-ws2_32/tcp.rs
new file mode 100644
index 00000000000..3d0248c76d7
--- /dev/null
+++ b/tests/run-make/windows-ws2_32/tcp.rs
@@ -0,0 +1,5 @@
+use std::net::TcpListener;
+
+fn main() {
+    TcpListener::bind("127.0.0.1:80").unwrap();
+}
diff --git a/tests/run-make/windows-subsystem/console.rs b/tests/ui/windows-subsystem/console.rs
index 61a92eb6a9d..8f0ca2de370 100644
--- a/tests/run-make/windows-subsystem/console.rs
+++ b/tests/ui/windows-subsystem/console.rs
@@ -1,3 +1,4 @@
+//@ run-pass
 #![windows_subsystem = "console"]
 
 fn main() {}
diff --git a/tests/ui/windows-subsystem-invalid.rs b/tests/ui/windows-subsystem/windows-subsystem-invalid.rs
index c6a6dd00a92..c6a6dd00a92 100644
--- a/tests/ui/windows-subsystem-invalid.rs
+++ b/tests/ui/windows-subsystem/windows-subsystem-invalid.rs
diff --git a/tests/ui/windows-subsystem-invalid.stderr b/tests/ui/windows-subsystem/windows-subsystem-invalid.stderr
index 703f35c969c..703f35c969c 100644
--- a/tests/ui/windows-subsystem-invalid.stderr
+++ b/tests/ui/windows-subsystem/windows-subsystem-invalid.stderr
diff --git a/tests/run-make/windows-subsystem/windows.rs b/tests/ui/windows-subsystem/windows.rs
index 1138248f07d..65db0fec7a8 100644
--- a/tests/run-make/windows-subsystem/windows.rs
+++ b/tests/ui/windows-subsystem/windows.rs
@@ -1,3 +1,4 @@
+//@ run-pass
 #![windows_subsystem = "windows"]
 
 fn main() {}