-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Use vswhere to find MSVC tools
#6120
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
base: main
Are you sure you want to change the base?
Conversation
| } | ||
|
|
||
| if useXcrun { | ||
| #if os(Windows) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is #if os(Windows) check enough, or do we need to gate on host triple too?
| /// Only use search paths, do not fall back to `xcrun` or `vswhere`. | ||
| let useXcrun: Bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still undecided if we want to rename the variable. I didn't do this at the point because neither have I got a short and clear name (useExternalTool sounds verbose and confusing), nor am I going to make vswhere the default like xcrun is now. It can be prioritized in later pitches.
| } | ||
| } | ||
|
|
||
| if useXcrun { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to introduce this approach as a fall-back from the beginning, and then makes it the default (like Clang does) if everything is working as expected.
compnerd
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly feel that this is the wrong way to handle this. If the install location changes this breaks. If I install outside of ProgramFiles(x86) this breaks. This has a bigger issue where we now are divergent from clang - clang has its own logic for selecting the VSCode version, which we must match or run the risk in mixing pieces incorrectly.
At the very least, this should be using clang to locate the tools, not vswhere.
|
I believe you have very deep misunderstandings on how
|
| return tool | ||
| } | ||
| #endif | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes the behaviour different when targeting Windows from Windows and Windows from another environment just making things more complicated and confusing for users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what useXcrun is already doing for Darwin to Darwin case, which I believe is reasonable — just like xcrun is only available on macOS, Visual Studio is basically a Windows thing.
I'd really rather that you would stop with the personal attacks. This seems to be a repetitive thing and really does not help create a pleasant environment.
Would you care to elaborate how it is "more powerful and robust"? Other than it is controlled by Microsoft and they can coordinate changes, I don't see how it is any more robust. Use in the installer is one thing, use in the tooling is another.
Is this documented and stated as a public API? The alternative is to use the Visual Studio COM APIs, which are documented public API (and avoids the path issues).
Sounds like you agree - typically. The problem case is where they do not agree, and if that happens, we get into a state that is difficult to diagnose. I think that honoring
What this says to me is that the |
I believe I didn't use offensive words here, and if you feel offended I sincerely apologize. For me, Swift is a general-purpose tool, and I'm always trying to lower the barrier of using Swift in general cases. Edge cases are important, but I just don't think a feature can be in a perfect stage when it first gets in the mainstream. That's not software engineering in these days.
I'll try to explain how Clang handles MSVC detection. Since that's going to be long, see the following comment.
Basically that's how
Will be mentioned in the following comment.
I believe it's not. Like you already mentioned, requiring |
|
Now let's dive in how Clang detects MSVC. Visual Studio has a refreshed interface since its 2017 release, and older ones are called "Legacy Instances". Swift has never supported legacy Visual Studio — and I suppose it never will. Clang detects MSVC from the following functions in order:
|
|
@stevapple Is it possible to exhaustively enumerate all the cases where your approach would differ from Clang and demonstrate that they can be diagnosed? |
|
@xwu I could only talk about the latest Clang implementation, which is already, exhaustively I believe, elaborated in #6120 (comment). Do you have any question? Since Clang is evolving itself, the behavior may change, so using Clang API should be better, but I didn't know how to do that in SwiftPM easily. I'd like to first introduce a solution to make sure Swift 5.8 release won't break our clients. |
|
Adding a potential solution that might be intersting instead of vswhere. This way, we can reduce one more dependencies and implement it directly (it's around 500 lines without any dependancies). Let me know if it could help @compnerd @stevapple |
|
@dafedidi I’m sorry but it seems such solution would not make things better… To use it we need to handle COM calls from Swift (which is possible though SwiftCOM but that’s another dependency), and it’s basically re-implementing a less-robust As I had stated, |
|
@dafedidi - I think that using the COM interfaces would definitely be something I would be in favour of. We already do that in the installer. But that is a well documented interface that has guaranteed stability unlike executing a "random" executable and parsing the output. |
Use
vswheretool to find MSVC tools. (Partially address #5771)Motivation:
After #5720, SwiftPM gains implicit dependency of
linkon Windows, but cannot detect it from the context without opts-in like Developer command prompt.Although the installation guide never claims that non-developer environment is supported, SwiftPM actually works since it's ported. Some automation workflows and tools like Swift for Visual Studio Code already depends on the behavior. Breaking the compatibility makes huge pain for the Swift on Windows ecosystem.
Modifications:
UserToolchain.findToolis taught to callvswhereon Windows and now knows about MSVC installation.UserToolchain.determineLibrarianandUserToolchain.determineSwiftCompilersgets new arguments to help determine the context.\UserToolchain.useXcrunis reused forvswherebecause they're much of serving the same purpose.Result:
SwiftPM will be usable (again) from non-developer shells like Windows Powershell.