Skip to content

Commit 9e818e8

Browse files
azchohfiChrisDenton
authored andcommitted
build(windows): skip the startup delay-load list in test builds
Builds with the `test` feature also link rustup-init's empty test and bench harnesses, which don't import the DLLs in the startup delay-load list, so `/WX` turns the unused `/delayload` (LNK4199) into a link error. Only add the list when the `test` feature is off, and revert the `test = false` / `bench = false` workaround from 958542d.
1 parent 47cbeb3 commit 9e818e8

2 files changed

Lines changed: 11 additions & 15 deletions

File tree

‎Cargo.toml‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,6 @@ wildcard_imports = "warn"
163163
name = "rustup"
164164
path = "src/lib.rs"
165165

166-
[[bin]]
167-
name = "rustup-init"
168-
path = "src/bin/rustup-init.rs"
169-
# The binary has no unit tests or benchmarks. Its empty test and bench harnesses
170-
# would otherwise be linked with the binary's delay-load list (see `build.rs`) but
171-
# without the code that imports those DLLs, which `/WX` turns into a link error
172-
# (LNK4199).
173-
test = false
174-
bench = false
175-
176166
[profile.release]
177167
codegen-units = 1
178168
lto = true

‎build.rs‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,17 @@ fn main() {
7474
// `rustc` etc. started through rustup is a separate process on Windows, and
7575
// each of these DLLs (with what it pulls in, such as gdi32 for user32) costs
7676
// start-up time when it is loaded eagerly.
77-
let delay_load_for_startup = [
78-
"user32", "shell32", "ole32", "oleaut32", "crypt32", "secur32", "ws2_32",
79-
];
80-
for dll in delay_load_for_startup {
81-
println!("cargo::rustc-link-arg-bin=rustup-init=/delayload:{dll}.dll");
77+
//
78+
// Builds with the `test` feature (CI's test runs) skip this: they also link
79+
// the binary's empty test and bench harnesses, which don't import these
80+
// DLLs, so `/WX` would turn the unused `/delayload` into a link error.
81+
if env::var_os("CARGO_FEATURE_TEST").is_none() {
82+
let delay_load_for_startup = [
83+
"user32", "shell32", "ole32", "oleaut32", "crypt32", "secur32", "ws2_32",
84+
];
85+
for dll in delay_load_for_startup {
86+
println!("cargo::rustc-link-arg-bin=rustup-init=/delayload:{dll}.dll");
87+
}
8288
}
8389
// When using delayload, it's necessary to also link delayimp.lib
8490
// https://learn.microsoft.com/en-us/cpp/build/reference/dependentloadflag?view=msvc-170

0 commit comments

Comments
 (0)