Skip to content
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

Add arm64 to MSVC hosts #2887

Merged
merged 10 commits into from
Dec 13, 2022
Merged

Add arm64 to MSVC hosts #2887

merged 10 commits into from
Dec 13, 2022

Conversation

scaryrawr
Copy link
Member

This enables using native arm64 toolset

The following changes are proposed:

  • Add arm64 as a valid host for MSVC

The purpose of this change

Visual Studio 2022 17.4 Preview introduced native build tools on arm64. This change enables the vscode-cmake-tools to detect the native tools so we can build with it instead of emulating x86/x64 to run the non-native build tools.

image

@scaryrawr
Copy link
Member Author

Ah, it currently looks like cmake errors out at this time since it only expects x86 or amd64 for the host.

@scaryrawr
Copy link
Member Author

It looks like if I modify the %LOCALAPPDATA%\CMakeTools\cmake-tools-kits.json and remove the instances of:

"toolset": "host=arm64"

We stop passing in -T host=arm64 which works-ish for building and debugging... but not sure how to get this working correctly 😅. From cmake documentation, it looks like only host=x86 or host=x64 are valid options, and not host=arm64.

@elahehrashedi
Copy link
Contributor

Is this screenshot from an arm64 machine where you scan for kits?
if yes, do all 3 host compilers exists? the paths look something like this:

C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.34.31921\bin\Hostx64

@scaryrawr
Copy link
Member Author

Is this screenshot from an arm64 machine where you scan for kits? if yes, do all 3 host compilers exists? the paths look something like this:

C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.34.31921\bin\Hostx64

It is a screenshot from an arm64 machine where all 3 host compilers exist.

There appears to be an issue with the cmake command that gets ran when attempting to configure with an arm64 host. -T host=arm64 does not work as the only valid values are x86 or x64, so with just the changes to scan it won't work for building yet.

@elahehrashedi
Copy link
Contributor

Can you check your hard drives to see if all 3 host compilers exist? and share the paths here?
(I can't see the paths from the screenshot)

@bobbrow
Copy link
Member

bobbrow commented Dec 9, 2022

Looking at the source code for CMake, it looks like ARM64 is all capitalized (and case-sensitive). Can you try that instead of arm64?

https://github.com/Kitware/CMake/blob/af58b6d2ad9a000146e8db2b1c3c74b1a93456ef/Source/cmGlobalVisualStudio12Generator.cxx#L141

@scaryrawr
Copy link
Member Author

Can you check your hard drives to see if all 3 host compilers exist? and share the paths here? (I can't see the paths from the screenshot)

  • C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.35.32019\bin\HostARM64\ARM64\cl.exe
  • C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.35.32019\bin\HostARM64\x64\cl.exe
  • C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.35.32019\bin\HostARM64\x86\cl.exe

@scaryrawr
Copy link
Member Author

Looking at the source code for CMake, it looks like ARM64 is all capitalized (and case-sensitive). Can you try that instead of arm64?

https://github.com/Kitware/CMake/blob/af58b6d2ad9a000146e8db2b1c3c74b1a93456ef/Source/cmGlobalVisualStudio12Generator.cxx#L141

Thanks for digging into this @bobbrow ! I had to do another check to get it back to lower case (otherwise I was missing arm64 as both host and target), but it appears to be working and generate this as my cmake-tools-kits.json:

[
  {
    "name": "Clang 15.0.1 (GNU CLI) for MSVC 17.5.33103.201 (Visual Studio Enterprise 2022 Preview - amd64)",
    "visualStudio": "f64f9d0b",
    "visualStudioArchitecture": "x64",
    "compilers": {
      "C": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\Llvm\\x64\\bin\\clang.exe",
      "CXX": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\Llvm\\x64\\bin\\clang.exe"
    }
  },
  {
    "name": "Clang 15.0.1 (GNU CLI) for MSVC 17.5.33103.201 (Visual Studio Enterprise 2022 Preview - x86)",
    "visualStudio": "f64f9d0b",
    "visualStudioArchitecture": "x86",
    "compilers": {
      "C": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\Llvm\\bin\\clang.exe",
      "CXX": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\Llvm\\bin\\clang.exe"
    }
  },
  {
    "name": "Clang 15.0.1 (MSVC CLI) for MSVC 17.5.33103.201 (Visual Studio Enterprise 2022 Preview - amd64)",
    "visualStudio": "f64f9d0b",
    "visualStudioArchitecture": "x64",
    "preferredGenerator": {
      "name": "Visual Studio 17 2022",
      "platform": "x64",
      "toolset": "ClangCL,host=x64"
    },
    "compilers": {
      "C": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\Llvm\\x64\\bin\\clang-cl.exe",
      "CXX": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\Llvm\\x64\\bin\\clang-cl.exe"
    }
  },
  {
    "name": "Clang 15.0.1 (MSVC CLI) for MSVC 17.5.33103.201 (Visual Studio Enterprise 2022 Preview - x86)",
    "visualStudio": "f64f9d0b",
    "visualStudioArchitecture": "x86",
    "preferredGenerator": {
      "name": "Visual Studio 17 2022",
      "platform": "win32",
      "toolset": "ClangCL,host=x86"
    },
    "compilers": {
      "C": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\Llvm\\bin\\clang-cl.exe",
      "CXX": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\Llvm\\bin\\clang-cl.exe"
    }
  },
  {
    "name": "Visual Studio Enterprise 2022 Preview - amd64",
    "visualStudio": "f64f9d0b",
    "visualStudioArchitecture": "x64",
    "preferredGenerator": {
      "name": "Visual Studio 17 2022",
      "platform": "x64",
      "toolset": "host=x64"
    }
  },
  {
    "name": "Visual Studio Enterprise 2022 Preview - amd64_arm64",
    "visualStudio": "f64f9d0b",
    "visualStudioArchitecture": "x64",
    "preferredGenerator": {
      "name": "Visual Studio 17 2022",
      "platform": "arm64",
      "toolset": "host=x64"
    }
  },
  {
    "name": "Visual Studio Enterprise 2022 Preview - amd64_x86",
    "visualStudio": "f64f9d0b",
    "visualStudioArchitecture": "x64",
    "preferredGenerator": {
      "name": "Visual Studio 17 2022",
      "platform": "win32",
      "toolset": "host=x64"
    }
  },
  {
    "name": "Visual Studio Enterprise 2022 Preview - arm64",
    "visualStudio": "f64f9d0b",
    "visualStudioArchitecture": "ARM64",
    "preferredGenerator": {
      "name": "Visual Studio 17 2022",
      "platform": "arm64",
      "toolset": "host=ARM64"
    }
  },
  {
    "name": "Visual Studio Enterprise 2022 Preview - arm64_amd64",
    "visualStudio": "f64f9d0b",
    "visualStudioArchitecture": "ARM64",
    "preferredGenerator": {
      "name": "Visual Studio 17 2022",
      "platform": "x64",
      "toolset": "host=ARM64"
    }
  },
  {
    "name": "Visual Studio Enterprise 2022 Preview - arm64_x86",
    "visualStudio": "f64f9d0b",
    "visualStudioArchitecture": "ARM64",
    "preferredGenerator": {
      "name": "Visual Studio 17 2022",
      "platform": "win32",
      "toolset": "host=ARM64"
    }
  },
  {
    "name": "Visual Studio Enterprise 2022 Preview - x86",
    "visualStudio": "f64f9d0b",
    "visualStudioArchitecture": "x86",
    "preferredGenerator": {
      "name": "Visual Studio 17 2022",
      "platform": "win32",
      "toolset": "host=x86"
    }
  },
  {
    "name": "Visual Studio Enterprise 2022 Preview - x86_amd64",
    "visualStudio": "f64f9d0b",
    "visualStudioArchitecture": "x86",
    "preferredGenerator": {
      "name": "Visual Studio 17 2022",
      "platform": "x64",
      "toolset": "host=x86"
    }
  },
  {
    "name": "Visual Studio Enterprise 2022 Preview - x86_arm64",
    "visualStudio": "f64f9d0b",
    "visualStudioArchitecture": "x86",
    "preferredGenerator": {
      "name": "Visual Studio 17 2022",
      "platform": "arm64",
      "toolset": "host=x86"
    }
  }
]

@scaryrawr
Copy link
Member Author

Ah, the test failure appears to be because arm64 as a host was added in Visual Studio 2022 17.4 and running against 2019 where arm64 is an invalid option.

@bobbrow
Copy link
Member

bobbrow commented Dec 9, 2022

The test appears to be failing for something else, but there are a lot of errors printing out during Kit scanning that should be addressed before we take this PR. It should probably be addressed in tryCreateNewVCEnvironment in kit.ts. It has access to the VSInstallation info, so I think you need to do a version check there before treating ARM64 as a valid host arch.

@bobbrow
Copy link
Member

bobbrow commented Dec 9, 2022

The test appears to be failing for something else, but there are a lot of errors printing out during Kit scanning that should be addressed before we take this PR. It should probably be addressed in tryCreateNewVCEnvironment in kit.ts. It has access to the VSInstallation info, so I think you need to do a version check there before treating ARM64 as a valid host arch.

The commit you just pushed works too, though I'd like to see if we can get a more accurate version number to test against. I believe we have APIs for that. Give me a minute.

@bobbrow
Copy link
Member

bobbrow commented Dec 9, 2022

The commit you just pushed works too, though I'd like to see if we can get a more accurate version number to test against. I believe we have APIs for that. Give me a minute.

There is a parseVersion function in util.ts but it expects a 3-part version number. That function could be modified to accept a 2-part version number and then you could use it to get the version number instead of parseInt which is kind of a hack that was never cleaned up.

Copy link
Member

@bobbrow bobbrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks so much for helping out! I'll follow up with an entry in the changelog to make sure you are recognized for your help.

@bobbrow bobbrow enabled auto-merge (squash) December 13, 2022 17:43
@bobbrow bobbrow merged commit 8510f59 into microsoft:main Dec 13, 2022
@bobbrow bobbrow added this to the 1.13 milestone Dec 13, 2022
bobbrow added a commit that referenced this pull request Dec 13, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jan 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants