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

Visual Studio 2022に対応する #1755

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/compiletests.targets
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<SetEnv name="platform" value="$(Platform)" prefix="false" />
<SetEnv name="configuration" value="$(Configuration)" prefix="false" />
<SetEnv name="NUM_VSVERSION" value="$(VsVersion)" prefix="false" />
<SetEnv name="ARG_VSVERSION" value="$(VsVersion)" prefix="false" />

This comment was marked as duplicate.

berryzplus marked this conversation as resolved.
Show resolved Hide resolved
<Exec Command="$(MSBuildThisFileDirectory)compiletests.run.cmd &quot;$(CompileTestBuildDir)&quot;" ConsoleToMSBuild="true" />
</Target>
<Target Name="AppendCleanTargetsForCompileTest" BeforeTargets="CoreClean">
Expand Down
11 changes: 7 additions & 4 deletions tools/find-tools.bat
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,9 @@ exit /b
::
:: ARG_VSVERSION
:: latest => the latest version of installed Visual Studio
:: 2017 => Visual Studio 2017
:: 2019 => Visual Studio 2019
:: 15 => Visual Studio 2017
:: 16 => Visual Studio 2019
:: 2017 or 15 => Visual Studio 2017
:: 2019 or 16 => Visual Studio 2019
:: 2022 or 17 => Visual Studio 2022
Copy link
Contributor

Choose a reason for hiding this comment

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

ここのコメント修正はどちらでもよいです。

visual studio 的に「バージョン」とは 17.0 のことで 2022 は「商標」にあたります。
ここで指定するのはバージョンなので、2桁を前にしたほうが良いように思います。(対応不要

Copy link

@ghost ghost Jan 4, 2022

Choose a reason for hiding this comment

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

そもそも

  ::     2017 => Visual Studio 2017
  ::     2019 => Visual Studio 2019
+ ::     2022 => Visual Studio 2022
  ::     15   => Visual Studio 2017
  ::     16   => Visual Studio 2019
+ ::     17   => Visual Studio 2022

とすればよかったような気もします。

:: ---------------------------------------------------------------------------------------------------------------------
:msbuild
:: convert productLineVersion to Internal Major Version
Expand All @@ -167,6 +166,8 @@ exit /b
set NUM_VSVERSION=15
) else if "%ARG_VSVERSION%" == "2019" (
set NUM_VSVERSION=16
) else if "%ARG_VSVERSION%" == "2022" (
set NUM_VSVERSION=17
) else if "%ARG_VSVERSION%" == "latest" (
call :check_latest_installed_vsversion
) else (
Expand All @@ -185,6 +186,8 @@ exit /b
set CMAKE_G_PARAM=Visual Studio 15 2017
) else if "%NUM_VSVERSION%" == "16" (
set CMAKE_G_PARAM=Visual Studio 16 2019
) else if "%NUM_VSVERSION%" == "17" (
set CMAKE_G_PARAM=Visual Studio 17 2022
) else (
call :set_cmake_gparam_automatically
)
Copy link

@ghost ghost Jan 4, 2022

Choose a reason for hiding this comment

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

235行目ですが、ここに「17^」を追加する必要がある気がします。

for /f "usebackq delims=" %%d in (`"%CMD_VSWHERE%" -requires Microsoft.Component.MSBuild -property installationPath -version [15^,16^)`) do (

Copy link
Contributor

Choose a reason for hiding this comment

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

👆の部分は、利用できるMsBuildのパスを列挙する部分です。
ここを修正しないとPRの目的が達成されないのではないかと思います。

vs2019のMsBuildは、vs2022を使ったビルドができる仕様なので、
結果オーライになると予想されますが、vs2022しか入れない端末でのビルドができないんじゃないかと思いました。

Copy link

@ghost ghost Jan 8, 2022

Choose a reason for hiding this comment

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

VS2019/VS2022が混在した環境で実行し、vswhereにどんな引数が入るか確認してみました。
引数指定なしの場合

find-tools.bat
vswhere -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -version [15,16\)
vswhere -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationVersion -latest
vswhere -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe -version [17,18\)
|- CMD_MSBUILD=C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe
|- CMAKE_G_PARAM=Visual Studio 17 2022
end

引数に「15」を与えた場合(※実行した環境にVS2017はインストールされていない)

find-tools.bat
vswhere -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -version [15,16)`
vswhere -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationVersion -latest`
vswhere -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe -version [17,18)`
|- CMD_MSBUILD=C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe
|- CMAKE_G_PARAM=Visual Studio 17 2022
end

引数に「16」を与えた場合

find-tools.bat
vswhere -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -version [16,17)
vswhere -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe -version [16,17)
|- CMD_MSBUILD=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe
|- CMAKE_G_PARAM=Visual Studio 16 2019
end

引数に「17」を与えた場合

find-tools.bat
vswhere -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -version [17,18)
vswhere -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe -version [17,18)
|- CMD_MSBUILD=C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe
|- CMAKE_G_PARAM=Visual Studio 17 2022
end

探索ロジックがまずビルドツールを「指定したバージョンが利用できるか調べ、できなければ最新のものを選ぶ」ようになっており、MSBuildは「ビルドツールの探索で決定したバージョンのものを探す」ようになっているようなので、find-tools.batの実行結果からは問題なく見えています。

しかし、find_msbuild_legacyで実行されるvswhereの呼び出し箇所は、逆に「利用できる一番古いもの」という動作になりそうな気がします(上記と同じ環境で実行しました)。

> vswhere -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationVersion -latest
17.0.32014.148

> vswhere -requires Microsoft.Component.MSBuild -property installationPath -version [15,17)
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community

ビルドツールの探索と同じく、指定バージョンのものが見つからなければ利用可能な最新のものを選ぶようにして良いのではないかと思うのですが。

> vswhere -requires Microsoft.Component.MSBuild -property installationPath -latest
C:\Program Files\Microsoft Visual Studio\2022\Community

Copy link

Choose a reason for hiding this comment

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

単独環境はこうなりました。

VS2017のみ

> vswhere -requires Microsoft.Component.MSBuild -property installationPath -version [15,16`)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise

> vswhere -requires Microsoft.Component.MSBuild -property installationPath -version [15,17`)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise

VS2019のみ

> vswhere -requires Microsoft.Component.MSBuild -property installationPath -version [15,16`)

> vswhere -requires Microsoft.Component.MSBuild -property installationPath -version [15,17`)
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise

VS2022のみ

> vswhere -requires Microsoft.Component.MSBuild -property installationPath -version [15,16`)

> vswhere -requires Microsoft.Component.MSBuild -property installationPath -version [15,17`)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

vswhere -versionを使って抽出するには

VS2017のみ
vswhere -requires Microsoft.Component.MSBuild -property installationPath -version [15,16)
VS2019のみ
vswhere -requires Microsoft.Component.MSBuild -property installationPath -version [16,17)
VS2022のみ
vswhere -requires Microsoft.Component.MSBuild -property installationPath -version [17,18)
VS2017とVS2019
vswhere -requires Microsoft.Component.MSBuild -property installationPath -version [15,17)

となります。
1つだけ指定のメジャーバージョンを見つけるにはこう書くようです。

vswhere -version [x,x+1)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:find_msbuild_legacyについてですが
改めて見直してみたところ、将来のVisual Studioのバージョンで
Msbuild.exeのパスが変更された場合などを想定しているように思います

Copy link

Choose a reason for hiding this comment

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

find_msbuild_legacyまで到達するシチュエーションが本当にありうるかは不明です。
.vsconfigに書いたコンポーネントのインストールが済んでいることを前提とすれば到達しなさそう。
だとしたら変更しなくても支障ないかも。

Expand Down
6 changes: 6 additions & 0 deletions vcx-props/vcxcompat.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@
<PropertyGroup Label="Globals" Condition="'$(VisualStudioVersion)' == '16.0'">
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<PropertyGroup Label="Globals" Condition="'$(VisualStudioVersion)' == '17.0'">
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
berryzplus marked this conversation as resolved.
Show resolved Hide resolved
<PropertyGroup Label="Configuration" Condition="'$(VisualStudioVersion)' == '15.0'">
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(VisualStudioVersion)' == '16.0'">
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(VisualStudioVersion)' == '17.0'">
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
berryzplus marked this conversation as resolved.
Show resolved Hide resolved
</Project>