build(msbuild): share fingerprinted vcpkg dependencies

This commit is contained in:
Eduardo Dantas 2026-08-12 23:53:36 -03:00
parent 061f3f537e
commit 9ee2d3470e
3 changed files with 89 additions and 2 deletions

1
.gitignore vendored
View file

@ -333,3 +333,4 @@ android/.gradle/
android/build/
luajit-src/
CMakeUserPresets.json
vc18/.canary-shared-cache/

View file

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="CanaryConfigureLocalVcpkgFallback"
BeforeTargets="VcpkgInstallManifestDependencies"
Condition="'$(CanarySharedVcpkgActive)'!='true'">
<SetEnv Name="VCPKG_ROOT" Value="$(VcpkgRoot)" Prefix="false" />
<ItemGroup>
<_CanaryVcpkgManifestFeature Include="$(CanaryVcpkgManifestFeatures)" Condition="'$(CanaryVcpkgManifestFeatures)'!=''" />
<_CanaryVcpkgOverlayPort Include="$(CanaryVcpkgOverlayPorts)" Condition="'$(CanaryVcpkgOverlayPorts)'!=''" />
<_CanaryVcpkgOverlayTriplet Include="$(CanaryVcpkgOverlayTriplets)" Condition="'$(CanaryVcpkgOverlayTriplets)'!=''" />
<_CanaryVcpkgInstallOption Include="$(CanaryVcpkgInstallOptions)" Condition="'$(CanaryVcpkgInstallOptions)'!=''" />
</ItemGroup>
<PropertyGroup>
<_CanaryVcpkgFeatureFlagOptions Condition="'$(CanaryVcpkgFeatureFlags)'!=''">--feature-flags=$([System.String]::Copy('$(CanaryVcpkgFeatureFlags)').Replace(';', ','))</_CanaryVcpkgFeatureFlagOptions>
<_CanaryVcpkgManifestFeatureOptions>@(_CanaryVcpkgManifestFeature->'--x-feature=%(Identity)', ' ')</_CanaryVcpkgManifestFeatureOptions>
<_CanaryVcpkgNoDefaultFeatureOptions Condition="'$(CanaryVcpkgManifestNoDefaultFeatures)'=='1' Or '$(CanaryVcpkgManifestNoDefaultFeatures)'=='ON' Or '$(CanaryVcpkgManifestNoDefaultFeatures)'=='TRUE' Or '$(CanaryVcpkgManifestNoDefaultFeatures)'=='YES'">--x-no-default-features</_CanaryVcpkgNoDefaultFeatureOptions>
<_CanaryVcpkgOverlayPortOptions>@(_CanaryVcpkgOverlayPort->'&quot;--overlay-ports=%(Identity)&quot;', ' ')</_CanaryVcpkgOverlayPortOptions>
<_CanaryVcpkgOverlayTripletOptions>@(_CanaryVcpkgOverlayTriplet->'&quot;--overlay-triplets=%(Identity)&quot;', ' ')</_CanaryVcpkgOverlayTripletOptions>
<_CanaryVcpkgInstallOptions>@(_CanaryVcpkgInstallOption, ' ')</_CanaryVcpkgInstallOptions>
<VcpkgAdditionalInstallOptions>$(_CanaryVcpkgFeatureFlagOptions) $(_CanaryVcpkgManifestFeatureOptions) $(_CanaryVcpkgNoDefaultFeatureOptions) $(_CanaryVcpkgOverlayPortOptions) $(_CanaryVcpkgOverlayTripletOptions) $(_CanaryVcpkgInstallOptions) &quot;--x-buildtrees-root=$(MSBuildProjectDirectory)\.vcpkg-buildtrees\$(Configuration)-$(Platform)&quot; &quot;--x-packages-root=$(MSBuildProjectDirectory)\.vcpkg-packages\$(Configuration)-$(Platform)&quot;</VcpkgAdditionalInstallOptions>
</PropertyGroup>
</Target>
<Target Name="CanarySetSharedVcpkgEnvironment"
BeforeTargets="VcpkgTripletSelection;VcpkgInstallManifestDependencies"
Condition="'$(CanarySharedVcpkgActive)'=='true'">
<Error Text="The shared Solution cache contract does not pin a Visual Studio instance. Regenerate SharedVcpkgCache.props."
Condition="'$(CanaryVcpkgVisualStudioPath)'==''" />
<Error Text="The shared Solution cache contract does not pin its dependency CMake tool. Regenerate SharedVcpkgCache.props."
Condition="'$(CanaryVcpkgDependencyCMakeDirectory)'==''" />
<Error Text="The shared Solution cache contract does not identify its cache root. Regenerate SharedVcpkgCache.props."
Condition="'$(CanarySharedCacheRoot)'==''" />
<SetEnv Name="CANARY_VCPKG_VISUAL_STUDIO_PATH"
Value="$(CanaryVcpkgVisualStudioPath)"
Prefix="false" />
<SetEnv Name="VCPKG_VISUAL_STUDIO_PATH"
Value="$(CanaryVcpkgVisualStudioPath)"
Prefix="false" />
<SetEnv Name="VCPKG_ROOT"
Value="$(VcpkgRoot)"
Prefix="false" />
<SetEnv Name="PATH"
Value="$(CanaryVcpkgDependencyCMakeDirectory);$(PATH)"
Prefix="false" />
</Target>
<Target Name="CanaryValidateSharedVcpkgCache"
BeforeTargets="VcpkgInstallManifestDependencies;PrepareForBuild"
DependsOnTargets="CanarySetSharedVcpkgEnvironment"
Condition="'$(CanarySharedVcpkgActive)'=='true'">
<Error Text="The shared Solution cache requires vcpkg manifest integration to remain enabled."
Condition="'$(VcpkgEnabled)'!='true' Or '$(VcpkgEnableManifest)'!='true' Or '$(VcpkgManifestInstall)'!='true'" />
<Error Text="The evaluated vcpkg manifest root differs from the generated dependency contract. Regenerate SharedVcpkgCache.props or remove the override."
Condition="'$(VcpkgManifestRoot)'!='$(CanarySharedVcpkgExpectedManifestRoot)'" />
<Error Text="The evaluated vcpkg target triplet differs from the generated dependency contract. Regenerate SharedVcpkgCache.props or remove the override."
Condition="'$(VcpkgTriplet)'!='$(CanarySharedVcpkgExpectedTargetTriplet)'" />
<Error Text="The evaluated vcpkg host triplet differs from the generated dependency contract. Regenerate SharedVcpkgCache.props or remove the override."
Condition="'$(VcpkgHostTriplet)'!='$(CanarySharedVcpkgExpectedHostTriplet)'" />
<Error Text="The evaluated vcpkg link configuration differs from the generated consumer contract. Regenerate SharedVcpkgCache.props or remove the override."
Condition="'$(VcpkgConfiguration)'!='$(CanarySharedVcpkgExpectedConfiguration)'" />
<Error Text="The evaluated platform toolset differs from the generated consumer contract. Regenerate SharedVcpkgCache.props or remove the override."
Condition="'$(PlatformToolset)'!='$(CanarySharedVcpkgExpectedToolset)'" />
<Error Text="The evaluated Windows SDK differs from the generated consumer contract. Regenerate SharedVcpkgCache.props or remove the override."
Condition="'$(WindowsTargetPlatformVersion)'!='$(CanarySharedVcpkgExpectedSDK)'" />
<Error Text="The evaluated vcpkg install options differ from the generated dependency contract. Regenerate SharedVcpkgCache.props or remove the override."
Condition="'$(VcpkgAdditionalInstallOptions)'!='$(CanarySharedVcpkgExpectedInstallOptions)'" />
<SetEnv Name="CANARY_SHARED_VCPKG_ACTUAL_MANIFEST_ROOT" Value="$(VcpkgManifestRoot)" Prefix="false" />
<SetEnv Name="CANARY_SHARED_VCPKG_ACTUAL_TARGET_TRIPLET" Value="$(VcpkgTriplet)" Prefix="false" />
<SetEnv Name="CANARY_SHARED_VCPKG_ACTUAL_HOST_TRIPLET" Value="$(VcpkgHostTriplet)" Prefix="false" />
<SetEnv Name="CANARY_SHARED_VCPKG_ACTUAL_CONFIGURATION" Value="$(VcpkgConfiguration)" Prefix="false" />
<SetEnv Name="CANARY_SHARED_VCPKG_ACTUAL_TOOLSET" Value="$(PlatformToolset)" Prefix="false" />
<SetEnv Name="CANARY_SHARED_VCPKG_ACTUAL_SDK" Value="$(WindowsTargetPlatformVersion)" Prefix="false" />
<SetEnv Name="CANARY_SHARED_VCPKG_ACTUAL_INSTALL_OPTIONS" Value="$(VcpkgAdditionalInstallOptions)" Prefix="false" />
<Exec WorkingDirectory="$(VcpkgManifestRoot)"
Command="pwsh.exe -NoLogo -NoProfile -NonInteractive -File &quot;$(VcpkgManifestRoot)\tools\configure_shared_solution_cache.ps1&quot; -ValidateOnly -Configuration &quot;$(Configuration)&quot; -Platform &quot;$(Platform)&quot; -ProjectFile &quot;$(MSBuildProjectFullPath)&quot; -CacheRoot &quot;$(CanarySharedCacheRoot)&quot; -VcpkgRoot &quot;$(VcpkgRoot)&quot; -VisualStudioPath &quot;$(CanaryVcpkgVisualStudioPath)&quot; -CMakePath &quot;$(CanaryVcpkgDependencyCMakeDirectory)\cmake.exe&quot; -MSBuildPath &quot;$(MSBuildToolsPath)\MSBuild.exe&quot; -ExpectedDependencyFingerprint &quot;$(CanarySharedVcpkgDependencyFingerprint)&quot; -ExpectedConsumerFingerprint &quot;$(CanarySharedVcpkgConsumerFingerprint)&quot; -ExpectedInstalledRoot &quot;$(VcpkgInstalledDir)&quot;" />
</Target>
</Project>

View file

@ -71,6 +71,12 @@
<EnableUnitySupport>true</EnableUnitySupport>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<PropertyGroup Label="VcpkgBootstrap">
<VcpkgRoot Condition="'$(VcpkgRoot)'=='' and '$(VCPKG_ROOT)'!=''">$(VCPKG_ROOT)</VcpkgRoot>
<VcpkgRoot Condition="'$(VcpkgRoot)'=='' and Exists('$(MSBuildThisFileDirectory)..\vcpkg\scripts\buildsystems\msbuild\vcpkg.props')">$(MSBuildThisFileDirectory)..\vcpkg</VcpkgRoot>
<VcpkgRoot Condition="'$(VcpkgRoot)'=='' and Exists('$(MSBuildThisFileDirectory)..\..\..\vcpkg\scripts\buildsystems\msbuild\vcpkg.props')">$(MSBuildThisFileDirectory)..\..\..\vcpkg</VcpkgRoot>
</PropertyGroup>
<Import Project="$(VcpkgRoot)\scripts\buildsystems\msbuild\vcpkg.props" Condition="'$(VcpkgPropsImported)'!='true' and '$(VcpkgRoot)'!='' and Exists('$(VcpkgRoot)\scripts\buildsystems\msbuild\vcpkg.props')" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<Import Project="settings.props" />
@ -168,6 +174,8 @@
<VcpkgTriplet>x64-windows-static</VcpkgTriplet>
<VcpkgInstalledDir>$(MSBuildProjectDirectory)\..\vcpkg_installed\msbuild-x64-debug</VcpkgInstalledDir>
</PropertyGroup>
<Import Project="$(MSBuildProjectDirectory)\.canary-shared-cache\SharedVcpkgCache.props"
Condition="'$(CanarySharedVcpkgDisable)'!='true' and Exists('$(MSBuildProjectDirectory)\.canary-shared-cache\SharedVcpkgCache.props')" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PreprocessorDefinitions>$(PREPROCESSOR_DEFS);_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@ -750,11 +758,11 @@
<Message Text="RunProtoCompile value: $(RunProtoCompile)" Importance="high" />
</Target>
<PropertyGroup Condition="'$(RunProtoCompile)'=='true'">
<ProtocPath>$(VcpkgInstalledDir)\$(VcpkgTriplet)\tools\protobuf\protoc.exe</ProtocPath>
<ProtocPath>$(VcpkgInstalledDir)\$(VcpkgHostTriplet)\tools\protobuf\protoc.exe</ProtocPath>
<ProtoPath>$(SourcePath)protobuf</ProtoPath>
</PropertyGroup>
<PropertyGroup Condition="'$(RunProtoCompile)'=='false'">
<ProtocPath>$(VcpkgInstalledDir)\$(VcpkgTriplet)\tools\protobuf\protoc.exe</ProtocPath>
<ProtocPath>$(VcpkgInstalledDir)\$(VcpkgHostTriplet)\tools\protobuf\protoc.exe</ProtocPath>
<ProtoPath>$(SourcePath)protobuf</ProtoPath>
</PropertyGroup>
<ItemGroup>
@ -776,5 +784,6 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VcpkgRoot)\scripts\buildsystems\msbuild\vcpkg.targets" Condition="'$(_ZVcpkgRoot)'=='' and '$(VcpkgRoot)'!='' and Exists('$(VcpkgRoot)\scripts\buildsystems\msbuild\vcpkg.targets')" />
<Import Project="SharedVcpkgCache.targets" />
</ImportGroup>
</Project>