From cfa67e97f134670eddb3678df4c58af632bc3f41 Mon Sep 17 00:00:00 2001 From: aiongg Date: Wed, 18 Nov 2026 18:51:43 +0000 Subject: [PATCH] Delay-load opengl32.dll on Windows MSVC (#15444) wgpu's GL backend (glutin_wgl_sys) puts opengl32.dll in the import table of every binary that links wgpu, and a process that has loaded it takes about 60 ms longer to exit. That is every Windows test process and every app exit on DX12 or Vulkan. Delay-load it from the workspace's .cargo/config.toml, the one place that reaches every package's binaries (a build script's link arguments reach only its own package). Cargo joins these flags with the CARGO_TARGET__RUSTFLAGS set by CI and the Windows packaging script. The print DLLs keep their delay-loads in the app's and CLI's build.rs, since the exe must start without them whatever invokes cargo. --- .cargo/config.toml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.cargo/config.toml b/.cargo/config.toml index 5592118f6c..11a0baa22e 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,14 @@ [alias] xtask = "run -p xtask --" + +# wgpu's GL backend (glutin_wgl_sys) imports opengl32.dll, so every binary that links wgpu loads +# it at start, and a process that has loaded it takes about 60 ms longer to exit (#15444): every +# test process and every app exit on DX12 or Vulkan. Delay-loaded, it loads on the first WGL +# call, which only the GL backend makes. Here rather than in a build script, because a link +# argument from a build script reaches only its own package's binaries, and every package whose +# binaries link wgpu would need one. Cargo joins these with `CARGO_TARGET__RUSTFLAGS` +# (CI, packaging); only `RUSTFLAGS` replaces them. The print DLLs' delay-loads stay in the app's +# and CLI's build.rs: without those the exe doesn't start on some Windows images (#5884), so +# they must hold for any cargo invocation, also one that never reads this file. +[target.'cfg(all(windows, target_env = "msvc"))'] +rustflags = ["-Clink-arg=/DELAYLOAD:opengl32.dll", "-Clink-arg=delayimp.lib"]