Description
On Windows, when the total length of -L
search paths exceeds about 32k characters, rustc
fails to load proc macro DLLs with the message:
error: LoadLibraryExW failed (retried 5 times)
--> user.rs:2:1
|
2 | extern crate procmacro;
| ^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
WinDbg suggests that the error returned is
LastErrorValue: (Win32) 0x8 (8) - Not enough memory resources are available to process this command.
LastStatusValue: (NTSTATUS) 0xc0000017 - {Not Enough Quota} Not enough virtual memory or paging file quota is available to complete the specified operation.
I noticed that the search paths get added to the PATH
environment variable (not sure where), but environment variables have a limit of 32,767 characters. So my guess is that an overly full environment causes LoadLibraryExW to fail.
Repro gist: https://gist.github.com/goffrie/4fd3553a5417fda17d78e0f8a7252335
Run the commands in repro.ps1. Basically we just need an argfile to run rustc with a very long list of search paths, and then importing proc-macros fails.
This scenario is not likely when using Cargo, but rules_rust for Bazel generates one -L
per transitive crate dependency which makes this not super difficult to hit.
Meta
rustc --version --verbose
:
rustc 1.69.0 (84c898d65 2023-04-16)
binary: rustc
commit-hash: 84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc
commit-date: 2023-04-16
host: x86_64-pc-windows-msvc
release: 1.69.0
LLVM version: 15.0.7