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
This commit is contained in:
commit
e9b7aa08f7
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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"
|
@ -1,9 +0,0 @@
|
||||
include ../tools.mk
|
||||
|
||||
# only-windows
|
||||
|
||||
PATH=$(SYSTEMROOT)/system32
|
||||
|
||||
all:
|
||||
$(RUSTC) hello.rs
|
||||
$(TMPDIR)/hello.exe
|
21
tests/run-make/windows-binary-no-external-deps/rmake.rs
Normal file
21
tests/run-make/windows-binary-no-external-deps/rmake.rs
Normal file
@ -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}`");
|
||||
}
|
||||
}
|
@ -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
|
15
tests/run-make/windows-safeseh/rmake.rs
Normal file
15
tests/run-make/windows-safeseh/rmake.rs
Normal file
@ -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();
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
include ../tools.mk
|
||||
|
||||
# only-windows
|
||||
|
||||
all:
|
||||
$(RUSTC) -o "$(TMPDIR)/hopefullydoesntexist bar.exe" hello.rs
|
||||
$(RUSTC) spawn.rs
|
||||
$(TMPDIR)/spawn.exe
|
17
tests/run-make/windows-spawn/rmake.rs
Normal file
17
tests/run-make/windows-spawn/rmake.rs
Normal file
@ -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");
|
||||
}
|
@ -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
|
||||
)
|
||||
}
|
||||
|
@ -1,6 +0,0 @@
|
||||
# ignore-cross-compile
|
||||
include ../tools.mk
|
||||
|
||||
all:
|
||||
$(RUSTC) windows.rs
|
||||
$(RUSTC) console.rs
|
27
tests/run-make/windows-ws2_32/rmake.rs
Normal file
27
tests/run-make/windows-ws2_32/rmake.rs
Normal file
@ -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
|
||||
}
|
5
tests/run-make/windows-ws2_32/tcp.rs
Normal file
5
tests/run-make/windows-ws2_32/tcp.rs
Normal file
@ -0,0 +1,5 @@
|
||||
use std::net::TcpListener;
|
||||
|
||||
fn main() {
|
||||
TcpListener::bind("127.0.0.1:80").unwrap();
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
//@ run-pass
|
||||
#![windows_subsystem = "console"]
|
||||
|
||||
fn main() {}
|
@ -1,3 +1,4 @@
|
||||
//@ run-pass
|
||||
#![windows_subsystem = "windows"]
|
||||
|
||||
fn main() {}
|
Loading…
x
Reference in New Issue
Block a user