-
Notifications
You must be signed in to change notification settings - Fork 127
[native_toolchain_c] Fix #3327 native_toolchain_c vswhere selection #3328
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
Open
Chaos02
wants to merge
2
commits into
dart-lang:main
Choose a base branch
from
Chaos02:fix/native-toolchain-c-vswhere-requires-3327-clean
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,15 +38,35 @@ final Tool vswhere = Tool( | |
| ), | ||
| ); | ||
|
|
||
| /// Visual Studio. | ||
| /// A Visual Studio installation that ships the MSVC tools for x86/x64. | ||
| /// | ||
| /// Resolved via [vswhere] requiring | ||
| /// `Microsoft.VisualStudio.Component.VC.Tools.x86.x64`, which filters out | ||
| /// installs that lack the C++ toolchain (e.g. SSMS) even when their | ||
| /// `installationVersion` would otherwise win `vswhere -latest`. | ||
| /// | ||
| /// https://visualstudio.microsoft.com/ | ||
| final Tool visualStudio = Tool( | ||
| name: 'Visual Studio', | ||
| defaultResolver: VisualStudioResolver(), | ||
| ); | ||
|
|
||
| /// The C/C++ Optimizing Compiler. | ||
| /// A Visual Studio installation that ships the MSVC tools for arm64. | ||
| /// | ||
| /// Resolved via [vswhere] requiring | ||
| /// `Microsoft.VisualStudio.Component.VC.Tools.arm64`. May resolve a | ||
| /// different installation than [visualStudio] when not every VS instance on | ||
| /// the machine has the arm64 cross toolchain installed. | ||
| /// | ||
| /// https://visualstudio.microsoft.com/ | ||
| final Tool visualStudioArm64 = Tool( | ||
| name: 'Visual Studio', | ||
| defaultResolver: VisualStudioResolverArm64(), | ||
| ); | ||
|
|
||
| /// The C/C++ Optimizing Compiler installation for targeting x86/x64. | ||
| /// | ||
| /// Resolved relative to [visualStudio]. | ||
| final Tool msvc = Tool( | ||
| name: 'MSVC', | ||
| defaultResolver: PathVersionResolver( | ||
|
|
@@ -58,6 +78,22 @@ final Tool msvc = Tool( | |
| ), | ||
| ); | ||
|
|
||
| /// The C/C++ Optimizing Compiler installation for targeting arm64. | ||
| /// | ||
| /// Resolved relative to [visualStudioArm64], which may point at a different | ||
| /// VS installation than [msvc] when only some installs have the arm64 | ||
| /// cross toolchain. | ||
| final Tool msvcArm64 = Tool( | ||
| name: 'MSVC', | ||
| defaultResolver: PathVersionResolver( | ||
| wrappedResolver: RelativeToolResolver( | ||
| toolName: 'MSVC', | ||
| wrappedResolver: visualStudioArm64.defaultResolver!, | ||
| relativePath: Uri(path: './VC/Tools/MSVC/*/'), | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
| Tool vcvars(ToolInstance toolInstance) { | ||
| final tool = toolInstance.tool; | ||
| assert(tool == cl || tool == msvcLink || tool == lib); | ||
|
|
@@ -241,7 +277,10 @@ Tool _msvcTool({ | |
| final targetArchName = _msvcArchNames[targetArchitecture]!; | ||
| ToolResolver resolver = RelativeToolResolver( | ||
| toolName: executableName, | ||
| wrappedResolver: msvc.defaultResolver!, | ||
| wrappedResolver: switch (targetArchitecture) { | ||
| .arm64 => msvcArm64.defaultResolver!, | ||
| _ => msvc.defaultResolver!, | ||
| }, | ||
| relativePath: Uri( | ||
| path: 'bin/Host$hostArchName/$targetArchName/$executableName', | ||
| ), | ||
|
|
@@ -256,22 +295,75 @@ Tool _msvcTool({ | |
| return Tool(name: executableName, defaultResolver: resolver); | ||
| } | ||
|
|
||
| /// Resolves Visual Studio installations that ship the arm64 MSVC tools. | ||
| /// | ||
| /// Same as [VisualStudioResolver] but requires the | ||
| /// `Microsoft.VisualStudio.Component.VC.Tools.arm64` component. On machines | ||
| /// with multiple VS installations these resolvers may pick different | ||
| /// installs. | ||
| class VisualStudioResolverArm64 extends VisualStudioResolver { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extending doesn't seem the right pattern if the x64 and arm64 are next to each other. Can the VisualStudioResolver get a targetArchitecture param instead? |
||
| @override | ||
| Future<List<ToolInstance>> resolve(ToolResolvingContext context) async => | ||
| resolveArch(context, 'arm64'); | ||
| } | ||
|
|
||
| /// Resolves Visual Studio installations that ship the x86/x64 MSVC tools. | ||
| /// | ||
| /// Runs [vswhere] with `-latest -requires | ||
| /// Microsoft.VisualStudio.Component.VC.Tools.x86.x64`. The `-requires` | ||
| /// filter is necessary because tools like SSMS share the VS installer and | ||
| /// can outrank Visual Studio under `-latest` when sorted by version alone | ||
| /// (see https://github.com/dart-lang/native/issues/3327). | ||
| class VisualStudioResolver implements ToolResolver { | ||
| @override | ||
| Future<List<ToolInstance>> resolve(ToolResolvingContext context) async { | ||
| Future<List<ToolInstance>> resolve(ToolResolvingContext context) async => | ||
| resolveArch(context, 'x86.x64'); | ||
|
|
||
| Future<List<ToolInstance>> resolveArch( | ||
| ToolResolvingContext context, | ||
| String pkgArchSuffix, | ||
| ) async { | ||
| final vswhereInstances = await vswhere.defaultResolver!.resolve(context); | ||
| final logger = context.logger; | ||
|
|
||
| final result = <ToolInstance>[]; | ||
| for (final vswhereInstance in vswhereInstances.take(1)) { | ||
| final vswhereResult = await runProcess( | ||
| executable: vswhereInstance.uri, | ||
| arguments: ['-format', 'json', '-utf8', '-latest', '-products', '*'], | ||
| arguments: [ | ||
| '-format', | ||
| 'json', | ||
| '-utf8', | ||
| '-latest', | ||
| '-products', | ||
| '*', | ||
| '-requires', | ||
| 'Microsoft.VisualStudio.Component.VC.Tools.$pkgArchSuffix', | ||
| ], | ||
| logger: logger, | ||
| ); | ||
| final instances = parseVswhere(vswhereResult.stdout, logger); | ||
| result.addAll(instances); | ||
| } | ||
| if (result.isEmpty) { | ||
| logger?.warning( | ||
| 'No Visual Studio installation found with the requested ' | ||
| 'Microsoft.VisualStudio.Component.VC.Tools.$pkgArchSuffix component.', | ||
| ); | ||
| logger?.info('You can install the missing package via'); | ||
| for (final vsWhere in vswhereInstances) { | ||
| final vsInstallerUri = vsWhere.uri | ||
| .resolve('../vs_installer.exe') | ||
| .toFilePath(); | ||
| logger?.warning( // highlight command for user | ||
| '` $vsInstallerUri install --add ', | ||
| 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64`', | ||
| ); | ||
| if (vswhereInstances.length > 1 && vswhereInstances.last != vsWhere) { | ||
| logger?.info('or'); | ||
| } | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
final Tool visualStudioX64? I don't think we export this variable outside the package, so it would not be breaking anything?And name
Visual Studio (x64)? Or does changing the name break things?