Skip to content

Conversation

lambdageek
Copy link
Contributor

@lambdageek lambdageek commented Sep 17, 2025

In some situations cc::windows_registry::find_msvc_tool("link.exe") returns a Tool with an empty environment (without the Windows SDK tools in the PATH). This happens if link.exe itself was found on the PATH, for example if you're in a VS Developer Command Prompt.

Update the find_resource_compiler to more closely follow how cc::windows_registry does it: first try to find "rc.exe" on the PATH and only if that fails (and also if "link.exe" isn't on the PATH), try to locate it indirectly via find_msvc_tool("link.exe")

There's also the related PR: #46663 which provides a way for bootstrap to override the resource compiler that will be used. This PR does not conflict with that one - if bootstrap provides a resource compiler, that one will be used, otherwise we land in the logic in this PR

Ideally we could update cc (or rather use its find-msvc-tools crate) to a version that can find rc.exe itself - that is possible in rust-lang/cc-rs#1553 which is not released yet

Addresses #146018 (comment)

Fixes: #146693

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 17, 2025

r? @SparrowLii

rustbot has assigned @SparrowLii.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rust-log-analyzer

This comment has been minimized.

@lambdageek lambdageek marked this pull request as draft September 17, 2025 22:52
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 17, 2025
@lambdageek
Copy link
Contributor Author

Going to try to understand #146693 a bit more before calling it fixed

In some situations `cc::windows_registry::find_msvc_tool("link.exe")` returns a
`Tool` with an empty environment (without the Windows SDK tools in the
PATH).  This happens if link.exe itself was found on the PATH, for
example if you're in a VS Developer Command Prompt.

Update the `find_resource_compiler` to more closely follow how
`cc::windows_registry` does it: first try to find "rc.exe" on the PATH
and only if that fails (and also if "link.exe" isn't on the PATH), try
to locate it indirectly via `find_msvc_tool("link.exe")`
@lambdageek lambdageek changed the title Try to find windows resource compiler on PATH as a fallback Try to find the Windows resource compiler on the PATH first Sep 18, 2025
@rustbot rustbot added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Sep 18, 2025
@lambdageek lambdageek marked this pull request as ready for review September 18, 2025 20:41
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 18, 2025
@lambdageek
Copy link
Contributor Author

Ok, AFAICT in local testing this should fix #146693. Once rust-lang/cc-rs#1553 is in a released crate and we pick it up, all of this will get much simpler. But this will at least unblock downstream folks

@workingjubilee workingjubilee removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Sep 18, 2025
@NobodyXu
Copy link
Contributor

rust-lang/cc-rs#1553 has released

@lambdageek
Copy link
Contributor Author

Closing in favor of #146784

@lambdageek lambdageek closed this Sep 19, 2025
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rustc failed to locate rc.exe on VS2022 Command Prompt, causing panic
6 participants