Auto merge of #125613 - ChrisDenton:windows-recipie, r=jieyouxu · rust-lang/rust@e9b7aa0 (original) (raw)

File tree

18 files changed

lines changed

18 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -203,6 +203,12 @@ impl Rustc {
203 203 self
204 204 }
205 205
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 +
206 212 /// Get the [`Output`] of the finished process.
207 213 #[track_caller]
208 214 pub fn command_output(&mut self) -> ::std::process::Output {
Original file line number Diff line number Diff line change
@@ -116,7 +116,6 @@ run-make/issue-83112-incr-test-moved-file/Makefile
116 116 run-make/issue-84395-lto-embed-bitcode/Makefile
117 117 run-make/issue-85019-moved-src-dir/Makefile
118 118 run-make/issue-85401-static-mir/Makefile
119 -run-make/issue-85441/Makefile
120 119 run-make/issue-88756-default-output/Makefile
121 120 run-make/issue-97463-abi-param-passing/Makefile
122 121 run-make/jobserver-error/Makefile
@@ -272,8 +271,4 @@ run-make/volatile-intrinsics/Makefile
272 271 run-make/wasm-exceptions-nostd/Makefile
273 272 run-make/wasm-override-linker/Makefile
274 273 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
279 274 run-make/x86_64-fortanix-unknown-sgx-lvi/Makefile
Original file line number Diff line number Diff 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 +}
Original file line number Diff line number Diff 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 +}
Original file line number Diff line number Diff 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 +}
Original file line number Diff line number Diff line change
@@ -3,10 +3,8 @@ use std::process::Command;
3 3
4 4 fn main() {
5 5 // 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 +)
12 10 }

File renamed without changes.

Original file line number Diff line number Diff 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 +}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1 +use std:🥅:TcpListener;
2 +
3 +fn main() {
4 +TcpListener::bind("127.0.0.1:80").unwrap();
5 +}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
1 +//@ run-pass
1 2 #![windows_subsystem = "console"]
2 3
3 4 fn main() {}

File renamed without changes.

File renamed without changes.

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