From 97e7ac8d748779d04ab1c230abb59f4473a227ed Mon Sep 17 00:00:00 2001 From: Billy O'Neal Date: Thu, 2 Sep 2021 12:33:21 -0700 Subject: [PATCH] [vcpkg] Repair msbuild damage and workaround the way we integrate on VS2015. (#19767) * Repair msbuild damage and workaround the way we integrate on VS2015. This is a fix for a pile of issues discovered by https://github.com/microsoft/vcpkg/pull/18906 * VS 2015 has a bug that the $(VcpkgInstalledDir)\ dance we do to get a trailing slash is not applied correctly when VcpkgInstalledDir was edited in the same property group attempting to add the trailing slash. * We need a trailing slash on VcpkgInstalledDir at all times, but https://github.com/microsoft/vcpkg/pull/16173 damaged this by removing it from TreatAsLocalProperty. Add the right TreatAsLocalPropertys back. Add all such slash defenses to the top of the file just beneath, eliminating need to call Path::Combine and friends by following msbuild "directory properties have a trailing slash" convention. * Move VcpkgOSTarget and VcpkgPlatformTarget into the .targets, as they aren't intended to be overridable by users and don't appear in our selection dialog box(es). * Don't bother avoiding setting vcpkg properties when VcpkgEnabled is off; after all, VcpkgEnabled is itself a vcpkg property :). I left attempts to skip creating items since creating items can hit the disk. * Add _Z to several internal msbuild variables. * Move VcpkgApplocalDeps to the .props since it's a user setting. * Don't unconditionally use $(TLogLocation) because it is not set on 2015, and also it's per-project. * Fixed typo in docs "VcpkgInstalledDirectory", and document the limitation that it doesn't work in 2015. * In manifest mode, put the installed tree in a subdirectory including the triplet to make changing configurations faster. Known limitations: * If you change vcpkg.json without changing any .cpp files, we don't rebuild the dependencies even though we should. I don't know how to fix this but it doesn't appear to be a regression. * Fix .tlog handling. * Further defend against modified properties on VS2015. * Document more VS2015 limitations. * Remove TreatAsLocalProperty comment. --- docs/users/manifests.md | 18 ++- scripts/buildsystems/msbuild/vcpkg.props | 17 +- scripts/buildsystems/msbuild/vcpkg.targets | 179 +++++++++++++-------- 3 files changed, 131 insertions(+), 83 deletions(-) diff --git a/docs/users/manifests.md b/docs/users/manifests.md index ae0ee7eedca613..0018ff375d4007 100644 --- a/docs/users/manifests.md +++ b/docs/users/manifests.md @@ -441,7 +441,7 @@ See the `--feature-flags=` command line option for more information. ## MSBuild Integration To use manifests with MSBuild, first you need to use an [existing integration method](integration.md#with-msbuild). -Then, simply add a vcpkg.json above your project file (such as in the root of your source repository) and set the +Then, add a vcpkg.json above your project file (such as in the root of your source repository) and set the property `VcpkgEnableManifest` to `true`. You can set this property via the IDE in `Project Properties -> Vcpkg -> Use Vcpkg Manifest`. @@ -453,9 +453,21 @@ Note: It is critical that all project files in a single build consuming the same you need to use different triplets for different projects in your solution, they must consume from different `vcpkg.json` files. +### Known issues + +* Visual Studio 2015 does not correctly track edits to the `vcpkg.json` and `vcpkg-configuration.json` files, and will +not respond to changes unless a `.cpp` is edited. + ### MSBuild Properties -These properties can be defined via the VS GUI under `Project Properties -> Vcpkg` or via a common `.props` file. +When using Visual Studio 2015 integration, these properties can be set in your project file before the + + + +line, which unfortunately requires manual editing of the `.vcxproj` or passing on the msbuild command line with `/p:`. +With 2017 or later integration, These properties can additionally be set via the Visual Studio GUI under +`Project Properties -> Vcpkg` or via a common `.props` file imported between `Microsoft.Cpp.props` and +`Microsoft.Cpp.targets`. #### `VcpkgEnabled` (Use Vcpkg) @@ -495,7 +507,7 @@ vcpkg.json files will be ignored. This will default to true in the future. This property can be set to "false" to disable automatic dependency restoration on project build. Dependencies can be manually restored via the vcpkg command line. -#### `VcpkgInstalledDirectory` (Installed Directory) +#### `VcpkgInstalledDir` (Installed Directory) This property defines the location where headers and binaries are consumed from. In manifest mode, this directory is created and populated based on your manifest. diff --git a/scripts/buildsystems/msbuild/vcpkg.props b/scripts/buildsystems/msbuild/vcpkg.props index 788ba107b53d69..9a01beb5ade60f 100644 --- a/scripts/buildsystems/msbuild/vcpkg.props +++ b/scripts/buildsystems/msbuild/vcpkg.props @@ -1,34 +1,21 @@ - - - - windows - uwp - - - - - $(Platform) - x86 - - true true $(Configuration) false - $([System.IO.Path]::Combine($(MSBuildThisFileDirectory), '..\..\..')) + $([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\..')) true false + true false true $([MSbuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), vcpkg.json)) - diff --git a/scripts/buildsystems/msbuild/vcpkg.targets b/scripts/buildsystems/msbuild/vcpkg.targets index 7653c4e91f58a2..98fde24f126348 100644 --- a/scripts/buildsystems/msbuild/vcpkg.targets +++ b/scripts/buildsystems/msbuild/vcpkg.targets @@ -1,53 +1,91 @@ - + - - - - $([System.IO.Path]::Combine($(VcpkgRoot), 'scripts\buildsystems\msbuild\vcpkg-general.xml')) - - - - - - -static - $(VcpkgPlatformTarget)-$(VcpkgOSTarget)$(VcpkgLinkage) + - $([System.IO.Path]::Combine($(VcpkgRoot), 'installed')) - $([System.IO.Path]::Combine($(VcpkgManifestRoot), 'vcpkg_installed')) - $(VcpkgInstalledDir)\ + + <_ZVcpkgRoot>$(VcpkgRoot) + <_ZVcpkgManifestRoot>$(VcpkgManifestRoot) + <_ZVcpkgInstalledDir>$(VcpkgInstalledDir) + - <_ZVcpkgCurrentInstalledDir>$([System.IO.Path]::Combine($(VcpkgInstalledDir), $(VcpkgTriplet))) - <_ZVcpkgCurrentInstalledDir Condition="!$(_ZVcpkgCurrentInstalledDir.EndsWith('\'))">$(_ZVcpkgCurrentInstalledDir)\ + + + <_ZVcpkgRoot Condition="!$(_ZVcpkgRoot.EndsWith('\'))">$(_ZVcpkgRoot)\ + <_ZVcpkgManifestRoot Condition="'$(_ZVcpkgManifestRoot)' != '' and !$(_ZVcpkgManifestRoot.EndsWith('\'))">$(_ZVcpkgManifestRoot)\ + <_ZVcpkgInstalledDir Condition="'$(_ZVcpkgInstalledDir)' != '' and !$(_ZVcpkgInstalledDir.EndsWith('\'))">$(_ZVcpkgInstalledDir)\ + - Debug - Release + + + windows + uwp + - debug\ - true + + $(Platform) + x86 + - <_ZVcpkgHostTripletParameter Condition="'$(VcpkgHostTriplet)' != ''">"--host-triplet=$(VcpkgHostTriplet)" - <_ZVcpkgExecutable>$([System.IO.Path]::Combine($(VcpkgRoot), 'vcpkg.exe')) + + <_ZVcpkgLinkage /> + <_ZVcpkgLinkage Condition="'$(VcpkgUseStatic)' == 'true'">-static + $(VcpkgPlatformTarget)-$(VcpkgOSTarget)$(_ZVcpkgLinkage) + + + VcpkgTriplet=$(VcpkgTriplet):$(ProjectStateLine) - - + + + + + <_ZVcpkgInstalledDir Condition="'$(_ZVcpkgInstalledDir)' == ''">$(_ZVcpkgManifestRoot)vcpkg_installed\$(VcpkgTriplet)\ + + + + + <_ZVcpkgInstalledDir Condition="'$(_ZVcpkgInstalledDir)' == ''">$(_ZVcpkgRoot)installed\ + + + + + + <_ZVcpkgCurrentInstalledDir>$(_ZVcpkgInstalledDir)\$(VcpkgTriplet)\ + <_ZVcpkgNormalizedConfiguration Condition="$(VcpkgConfiguration.StartsWith('Debug'))">Debug + <_ZVcpkgNormalizedConfiguration Condition="$(VcpkgConfiguration.StartsWith('Release')) or '$(VcpkgConfiguration)' == 'RelWithDebInfo' or '$(VcpkgConfiguration)' == 'MinSizeRel'">Release + + <_ZVcpkgConfigSubdir Condition="'$(_ZVcpkgNormalizedConfiguration)' == 'Debug'">debug\ + <_ZVcpkgExecutable>$(_ZVcpkgRoot)vcpkg.exe + + + + + $(_ZVcpkgRoot)scripts\buildsystems\msbuild\vcpkg-general.xml + + + Project + - %(AdditionalDependencies);$(_ZVcpkgCurrentInstalledDir)$(VcpkgConfigSubdir)lib\*.lib - %(AdditionalLibraryDirectories);$(_ZVcpkgCurrentInstalledDir)$(VcpkgConfigSubdir)lib;$(_ZVcpkgCurrentInstalledDir)$(VcpkgConfigSubdir)lib\manual-link + %(AdditionalDependencies);$(_ZVcpkgCurrentInstalledDir)$(_ZVcpkgConfigSubdir)lib\*.lib + %(AdditionalLibraryDirectories);$(_ZVcpkgCurrentInstalledDir)$(_ZVcpkgConfigSubdir)lib;$(_ZVcpkgCurrentInstalledDir)$(_ZVcpkgConfigSubdir)lib\manual-link %(AdditionalIncludeDirectories);$(_ZVcpkgCurrentInstalledDir)include @@ -59,9 +97,9 @@ - + Condition="'$(VcpkgEnableManifest)' == 'true' and '$(_ZVcpkgManifestRoot)' == ''" /> + @@ -70,41 +108,52 @@ + Importance="High" Condition="'$(VcpkgEnabled)' == 'true' and '$(_ZVcpkgNormalizedConfiguration)' == ''"/> - - <_ZVcpkgManifestFileLocation>$(VcpkgManifestRoot)vcpkg.json - <_ZVcpkgConfigurationFileLocation>$(VcpkgManifestRoot)vcpkg-configuration.json - - <_ZVcpkgTLogFileLocation>$(TLogLocation)VcpkgInstallManifest$(VcpkgTriplet).$(VcpkgHostTriplet).read.1u.tlog - <_ZVcpkgMSBuildStampFile>$(VcpkgInstalledDir).msbuildstamp-$(VcpkgTriplet).$(VcpkgHostTriplet).stamp + + + + <_ZVcpkgHostTripletParameter>"--host-triplet=$(VcpkgHostTriplet)" + <_ZVcpkgHostTripletSuffix>$(VcpkgHostTriplet). + + + + + <_ZVcpkgHostTripletParameter /> + <_ZVcpkgHostTripletSuffix /> + + + + + + <_ZVcpkgManifestFileLocation>$(_ZVcpkgManifestRoot)vcpkg.json + <_ZVcpkgConfigurationFileLocation>$(_ZVcpkgManifestRoot)vcpkg-configuration.json + <_ZVcpkgMSBuildStampFile>$(_ZVcpkgInstalledDir).msbuildstamp-$(VcpkgTriplet).$(_ZVcpkgHostTripletSuffix)stamp + <_ZVcpkgInstallManifestDependenciesInputs Include="$(_ZVcpkgManifestFileLocation)"/> <_ZVcpkgInstallManifestDependenciesInputs Include="$(_ZVcpkgConfigurationFileLocation)" Condition="Exists('$(_ZVcpkgConfigurationFileLocation)')"/> - - <_ZVcpkgInstallManifestDependenciesOutputs Include="$(_ZVcpkgTLogFileLocation)"/> - <_ZVcpkgInstallManifestDependenciesOutputs Include="$(_ZVcpkgMSBuildStampFile)"/> - - - - <_ZVcpkgItemToDelete Include="$(TLogLocation)VcpkgInstallManifest*.read.1u.tlog" /> - <_ZVcpkgItemToDelete Include="$(VcpkgInstalledDir).msbuildstamp-*" /> - - - + + + <_ZVcpkgTLogFileLocation>$(TLogLocation)VcpkgInstallManifest$(VcpkgTriplet).$(_ZVcpkgHostTripletSuffix)read.1u.tlog + + + + + - @@ -118,40 +167,40 @@ Condition="'$(VcpkgEnabled)' == 'true' and '$(VcpkgApplocalDeps)' == 'true' and '$(LinkSkippedExecution)' != 'true'"> - <_VcpkgAppLocalPowerShellCommonArguments>-ExecutionPolicy Bypass -noprofile -File "$(MSBuildThisFileDirectory)applocal.ps1" "$(TargetPath)" "$(_ZVcpkgCurrentInstalledDir)$(VcpkgConfigSubdir)bin" "$(TLogLocation)$(ProjectName).write.1u.tlog" "$(IntDir)vcpkg.applocal.log" + <_ZVcpkgAppLocalPowerShellCommonArguments>-ExecutionPolicy Bypass -noprofile -File "$(MSBuildThisFileDirectory)applocal.ps1" "$(TargetPath)" "$(_ZVcpkgCurrentInstalledDir)$(_ZVcpkgConfigSubdir)bin" "$(TLogLocation)$(ProjectName).write.1u.tlog" "$(IntDir)vcpkg.applocal.log" + PropertyName="_ZVcpkgAppLocalExitCode" /> + Condition="$(_ZVcpkgAppLocalExitCode) == 9009" /> + Condition="$(_ZVcpkgAppLocalExitCode) == 9009"> + PropertyName="_ZVcpkgAppLocalExitCode" /> - + + Condition="$(_ZVcpkgAppLocalExitCode) == 0"> - - + +