-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Fall back to MSVC link.exe detection if env looks "misconfigured" #43069
Comments
I would think that erroring on a bad configuration instead of attempting to fix it would be a better approach. Instead of auto-reconfiguring, it would be better to have flag in cargo/rustc to auto-fix if user is lazy. P.s. I'm talking about general case, not very complex configuration that are attempting to build both x64 and x32 binaries/libs |
@DoumanAsh in general I'd agree, yes, but in practice it seems like it's very common to have a misconfigured environment and it'd be relatively easy for us to detect it as well. Because this is so common it implies to me that we want a better user experience than erroring-out, and because it's easy to detect that implies to me that it's feasible to do this. To be clear I don't think Gecko is the only one running into this. If you start up an MSVC shell you're in the same situation where you otherwise wouldn't be able cross-compile. Put another way, if you have MSVC env vars, it's impossible to cross-compile and this is just opening up the possibility to do so. |
Wouldn't it be better to actually recommend users to use clean environment so that Rust would auto-detect everything?
Yes, but if user wants auto-configuration, wouldn't it make more sense to not initiate MSVC env vars? I believe user configuration should take precedence over rust/cargo own, after all it is what user wanted. |
At the very least, if we do implement this fall back, there should be a big loud warning that Rust has detected the environment is configured for the wrong architecture and will attempt to detect stuff itself. I'm opposed to rustc silently ignoring the configured environment. |
Not always, no. If there are multiple installations of visual studio then env vars are the only way to force rustc to use a particular one.
Of course. I'm only advocating when we clearly detect a failure mode that we do something different. We could even run what's configured first and only if that fails see if it's a known reason why it failed, only then falling back to other detection. There's a lot of possibilities here. |
In this case wouldn't be nice to have option to configure VC Studio/build tools installation for use? Well as long as it is not enforced and user will be well-informed it is good. |
Yes it's possible. I would rather we not spiral this issue into new env vars and/or configuration option bikesheds. |
This sounds quite a bit like the reason we have Please correct me if I'm not understanding the issue, but it seems like we could use the model introduced there to allow specific configuration rather than doing hard-coded fallbacks. In this case, using the same "most specific to least specific" variable fallback for the This would require that folks needing specific configuration export different That said: using environment vars here always feels a bit awkward. Ideally we'd somehow tie them into the target (as some sort of variables), but that potentially needs some work improving how target specification works (to allow extending with these variables to work). |
This was long ago addressed in cc-rs (which Rust uses for vs detection) by looking for |
Build systems like Firefox tend to want to configure MSVC ahead of time to ensure that compiles use the right compiler/linker. This means that the various env vars corresponding to the
link.exe
invocation will be set before rustc is invoked. This in turn currently means that rustc will blindly use this configuration for all invocations of the linker, even if it's actually wrong.One situation where this becomes a problem is when you're cross compiling. For example you may have an
x86_64-pc-windows-msvc
host compiler and then you're compiling toi686-pc-windows-msvc
. This means that the environment specifies a linker that knows how to create 32-bit executables, but you may need to create 64-bit shared libraries as part of the build process (procedural macros).The compiler should detect this situation and help out. If the environment looks clearly invalid for the given target, we should assume that this situation is happening and basically scrub the environment. The compiler would fall back to its own internal detection which should correctly locate a linker.
The text was updated successfully, but these errors were encountered: