-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
recognize $PATHEXT on windows for cargo subcommands #10455
Comments
Interesting! I didn't know this before, so I searched it in rust-lang/rust and found some existing issues:
As far as I understand it, the biggest problem is that at this time If we want to utilize As a reference, here is the code finding the external commands in cargo: Lines 158 to 164 in 0a3f2b4
Footnotes |
Thanks for the detailed response! It seems you're correct that Obviously integrating this to the stdlib is out of scope and frankly, doesn't make a lot of sense. What if we had a cargo configuration key for subcommand lookup extensions? I can see this used only on Windows but it might be desirable. Let me know what you think. |
Oh, here is how one would configure custom interpreters for file extensions on the command line ( It's a two-step process. I'll demonstrate a trick I use to run shell scripts with
First we associate an extension with a tag of sorts: C:\> assoc .sh=shell.script With the "tag" configured, we add a handler for it: C:\> ftype shell.script=C:\system32\wsl.exe "%1" "%*" Actually, it's 3 steps, at least on the command line. PS C:\> $env:PATHEXT += ";.sh" Now, on powershell, shell scripts under Makes one appreciate shebangs a lot, doesn't it :D. |
I've done some experimentation. It looks like For these to work, I assume we would have to inspect the registry, which can be done but probably not worth it. Still though, batch files ( |
The proper way to execute an non-exe file is to use The way it searches file associations for the executable to use could also be implemented manually (see docs for registry keys, etc) but that's complex enough that it should almost certainly be tested as a third party crate before deciding whether to incorporate it into standard library. So this could be done but unfortunately the standard library isn't going to be too much help at this time. |
I agree. How about at least supporting extensions I have tested with I would be interested in implementing it myself, if that's fine. |
This is undocumented behaviour that just so happens to work. The MSDN docs say you should instead do this:
The other issue is passing additional arguments. Argument parsing works differently when running |
@insomnimus We'd be up for supporting what |
I've created an issue on the rust repo where I've tried to outline what's needed to properly support this (see rust-lang/rust#94743). For |
Regarding the fresh CVE-2024-24576 and the following discussion in rust-lang/rust#123728, I wonder if we should close this as “not supported”. See also the documentation in |
I second this. rust-lang/rust#94743 was rejected and others expressed dependence on what the standard library chooses to do. |
Problem
Currently on Windows, external cargo subcommands must have the
.exe
extension for cargo to recognize them.However,
.exe
files are not the only executable extensions as you already know.Proposed Solution
What many don't know is, there's a standardized environment variable Windows uses to determine if files can be executed from
$PATH
, which is also pre-populated by Windows:$PATHEXT
.The contents of
$PATHEXT
might look like this:The user is free to extend this value by adding custom extensions, and the "interpreter" is likewise configurable through some built-in cmd.exe commands or the Windows registry.
On Linux or MacOSX file extensions play no role so the user can write their cargo extensions in a bash script with a shebang and set the executable bit for cargo to recognize it (assuming the file is named
cargo-*
and available under$PATH
).Similar can be accomplished by respecting the value of
$PATHEXT
on Windows, or, not specifying*.exe
since programs with an extension contained in$PATHEXT
don't require the extension to be specified.Notes
No response
The text was updated successfully, but these errors were encountered: