|
124 | 124 |
|
125 | 125 | <!-- |
126 | 126 | vcpkg integration. Set globally (not per-project) so that import order is |
127 | | - guaranteed to be BEFORE Microsoft.Cpp.targets — this matters because |
128 | | - vcpkg's MSBuild integration registers a target (VcpkgInstallManifestDependencies) |
129 | | - that ClCompile must depend on, and that hook only takes effect when |
130 | | - vcpkg.props is loaded before the C++ targets. PowerToys has projects |
131 | | - that import deps/spdlog.props after Microsoft.Cpp.targets, so putting |
132 | | - vcpkg setup in spdlog.props loaded that way failed to wire include paths. |
| 127 | + guaranteed to be BEFORE Microsoft.Cpp.targets — vcpkg.props registers a |
| 128 | + target (VcpkgInstallManifestDependencies) that ClCompile must depend on, |
| 129 | + and that hook only takes effect when vcpkg.props is loaded before the |
| 130 | + C++ targets. PowerToys has projects that import deps/spdlog.props after |
| 131 | + Microsoft.Cpp.targets, so a per-project opt-in via spdlog.props (the |
| 132 | + earlier attempt) silently broke include-path wiring for those projects. |
| 133 | +
|
| 134 | + Trade-off: every C++ project now invokes `vcpkg install` once at build |
| 135 | + time, even if it doesn't consume spdlog. With binary cache enabled this |
| 136 | + is ~0.5 s/project on cache hits. The manifest declares only spdlog, so |
| 137 | + the cost is fixed and bounded; non-spdlog projects just carry an unused |
| 138 | + include path. |
133 | 139 |
|
134 | 140 | Three-tier VcpkgRoot fallback matching microsoft/terminal's pattern: |
135 | 141 | 1. $(VCPKG_ROOT) env var (CI sets via .pipelines/v2/templates/steps-install-vcpkg.yml; |
136 | 142 | local dev sets via tools/build/build-essentials.ps1). |
137 | 143 | 2. $(VsInstallRoot)\VC\vcpkg (vcpkg shipped with Visual Studio). |
138 | 144 | 3. $(RepoRoot)deps\vcpkg (gitignored runtime-cloned fallback). |
139 | 145 |
|
140 | | - The vcpkg manifest at the repo root declares only spdlog, so non-spdlog |
141 | | - C++ projects pay only the vcpkg install latency (~0.5 s on cache hits) |
142 | | - and an unused include path. With binary cache enabled this is negligible. |
| 146 | + VcpkgInstalledDir is platform-scoped (not configuration-scoped); vcpkg |
| 147 | + already separates debug/release artifacts inside the same triplet |
| 148 | + directory ($triplet/lib vs $triplet/debug/lib). Splitting per-platform |
| 149 | + keeps parallel x64/arm64 builds from racing on the same install lock. |
143 | 150 | --> |
144 | 151 | <PropertyGroup Label="vcpkg"> |
145 | 152 | <VcpkgEnabled>true</VcpkgEnabled> |
|
151 | 158 | <!-- vcpkg validates triplets case-sensitively; PowerToys uses ARM64 capital-case. --> |
152 | 159 | <VcpkgPlatformTarget Condition="'$(Platform)' == 'ARM64'">arm64</VcpkgPlatformTarget> |
153 | 160 | <VcpkgApplocalDeps>false</VcpkgApplocalDeps> |
154 | | - <VcpkgInstalledDir>$(MSBuildThisFileDirectory)$(Platform)\$(Configuration)\vcpkg_installed\</VcpkgInstalledDir> |
| 161 | + <VcpkgInstalledDir>$(MSBuildThisFileDirectory)vcpkg_installed\$(Platform)\</VcpkgInstalledDir> |
155 | 162 | <VcpkgRoot Condition="'$(VcpkgRoot)' == ''">$(VCPKG_ROOT)</VcpkgRoot> |
156 | 163 | <VcpkgRoot Condition="'$(VcpkgRoot)' == '' and '$(VsInstallRoot)' != ''">$(VsInstallRoot)\VC\vcpkg</VcpkgRoot> |
157 | 164 | <VcpkgRoot Condition="'$(VcpkgRoot)' == '' or !Exists('$(VcpkgRoot)\vcpkg.exe')">$(MSBuildThisFileDirectory)deps\vcpkg</VcpkgRoot> |
158 | 165 | <CAExcludePath>$(CAExcludePath);$(VcpkgInstalledDir)</CAExcludePath> |
159 | 166 | <VCPkgLocalAppDataDisabled>true</VCPkgLocalAppDataDisabled> |
160 | 167 | </PropertyGroup> |
| 168 | + <!-- |
| 169 | + Fail fast with a clear message if vcpkg is enabled but vcpkg.props |
| 170 | + cannot be found at the resolved VcpkgRoot. Without this the build |
| 171 | + silently skips vcpkg integration and surfaces later as missing |
| 172 | + <spdlog/*> includes or unresolved spdlog::* link errors, which are |
| 173 | + much harder to root-cause. |
| 174 | + --> |
| 175 | + <Target Name="PowerToysEnsureVcpkgAvailable" |
| 176 | + BeforeTargets="PrepareForBuild" |
| 177 | + Condition="'$(MSBuildProjectExtension)' == '.vcxproj' and '$(VcpkgEnabled)' == 'true' and !Exists('$(VcpkgRoot)\scripts\buildsystems\msbuild\vcpkg.props')"> |
| 178 | + <Error Text="vcpkg is required to build this project but vcpkg.props was not found at '$(VcpkgRoot)\scripts\buildsystems\msbuild\vcpkg.props'. |
| 179 | +
|
| 180 | +Resolve via one of: |
| 181 | + 1) Install the Visual Studio component 'Microsoft.VisualStudio.Component.Vcpkg' (in the VS Installer, under Desktop development with C++), or |
| 182 | + 2) Set the VCPKG_ROOT environment variable to an existing bootstrapped vcpkg checkout, or |
| 183 | + 3) Run tools\build\build-essentials.cmd at least once to clone+bootstrap a local vcpkg into deps\vcpkg." /> |
| 184 | + </Target> |
161 | 185 | <Import Project="$(VcpkgRoot)\scripts\buildsystems\msbuild\vcpkg.props" |
162 | 186 | Condition="'$(MSBuildProjectExtension)' == '.vcxproj' and Exists('$(VcpkgRoot)\scripts\buildsystems\msbuild\vcpkg.props')" /> |
163 | 187 |
|
|
0 commit comments