mirror of
https://github.com/mehah/otclient
synced 2026-08-15 16:29:06 -04:00
build(cache): share vcpkg dependencies across CMake and Visual Studio (#1800)
Add shared vcpkg dependency cache for CMake and Visual Studio builds This commit adds a content addressed vcpkg dependency cache that can be reused across compatible Git worktrees independent forks CMake presets and Visual Studio Solution builds. The goal is to reduce repeated dependency installation and rebuild time while keeping build outputs isolated per worktree. The cache only shares dependency artifacts that are proven compatible through a complete dependency contract. Project build outputs such as object files PCH files PDB files generated sources intermediate files and executables remain local to each checkout. The shared cache is opt in. When the cache is not configured or when the resolver cannot prove that reuse is safe both CMake and Visual Studio fall back to local worktree specific vcpkg roots. Main behavior added • Shares vcpkg downloads globally • Shares vcpkg binary packages globally • Shares expanded vcpkg installed trees only when the dependency fingerprint matches • Shares vcpkg buildtrees and packages only when the dependency fingerprint matches • Keeps CMake build trees local to each worktree • Keeps Visual Studio output directories local to each worktree • Keeps generated files intermediate files executables PCH files PDB files and object files local • Allows compatible Git worktrees to reuse dependency artifacts • Allows compatible forks to reuse dependency artifacts • Allows compatible CMake presets and Visual Studio configurations to converge on the same dependency cache • Falls back to local vcpkg storage when shared cache safety cannot be verified CMake integration The new CMake shared cache module runs before project initialization and resolves the vcpkg dependency contract before the normal configure flow continues. The resolver validates the manifest registries overlays triplets features vcpkg revision compiler toolset SDK and cache implementation before selecting fingerprinted dependency roots. This prevents incompatible configurations from sharing the same expanded dependency tree. If the CMake version is too old for the shared cache module and shared cache variables are present the build warns and continues with build local vcpkg storage instead. CMake preset changes • Removes hardcoded VCPKG_INSTALLED_DIR values from presets • Lets the shared cache resolver select the installed root when safe • Keeps local fallback behavior available • Replaces the previous preset binary source override with clean packages and clean buildtrees options • Prevents Visual Studio CMake presets from inheriting Ninja compiler overrides where they should not • Keeps CMake build outputs under their configured build preset directories Visual Studio integration The Visual Studio bridge uses the same dependency resolver as CMake. It evaluates each Solution configuration through MSBuild, generates a machine local ignored SharedVcpkgCache props file and revalidates the complete contract before vcpkg manifest installation. Different Visual Studio configurations receive separate consumer fingerprints. They can still share an expanded dependency tree when their dependency inputs are identical, but their consumer contracts remain separate so MSBuild specific details cannot corrupt CMake or another Solution configuration. The Visual Studio project now imports vcpkg props more reliably, supports the generated shared cache props, and validates the generated contract through SharedVcpkgCache targets before dependency installation and build preparation. Visual Studio changes included • Adds SharedVcpkgCache targets • Adds generated SharedVcpkgCache props support • Adds vcpkg bootstrap property resolution from VCPKG ROOT • Keeps local fallback when the shared Solution cache is inactive • Validates manifest root target triplet host triplet configuration toolset SDK and install options before using the shared cache • Pins the Visual Studio instance used by vcpkg for the shared Solution contract • Requires the dependency CMake tool used by the generated contract • Revalidates the generated contract before vcpkg manifest install • Uses fingerprinted installed buildtrees and packages roots for compatible Solution builds • Keeps Solution outputs local Shared cache safety boundaries The shared cache is intentionally conservative. It only activates when the environment and contract can be fully validated. Safety rules enforced • The shared pool must be on a verified local fixed filesystem • The shared pool must live outside every registered checkout • UNC paths are rejected for the shared cache root • Reparse points and symlink escapes are rejected in sensitive paths • Mutable dependency roots are isolated by full contract fingerprint • vcpkg and shared cache operation locks protect mutable cache operations • Existing authenticated VCPKG BINARY SOURCES values are preserved • Existing authenticated binary source values are never printed • Existing authenticated binary source values are never persisted by the helper • Cleanup fails closed when validation is incomplete • Cleanup refuses to run while build related processes are active • Cleanup validates repositories configure trees generated contracts paths identities and locks before removing transient data • CI containers runtime data deployment paths and release behavior remain unchanged unless shared cache is explicitly enabled PowerShell tooling This commit adds setup audit cleanup repository registration and Solution contract generation tools. The main shared cache setup script configures the cache root registers the current Git repository family manages relevant user environment variables configures vcpkg downloads and binary cache locations updates managed sccache base directories and can invoke the Solution bridge when applicable. The Solution cache script evaluates MSBuild properties resolves the shared dependency contract through the CMake resolver writes the generated props file and supports audit only and validate only modes. Both PowerShell tools require PowerShell 7 2 and run under strict mode. Tooling added • tools configure shared build cache ps1 • tools configure shared solution cache ps1 • setup mode for shared cache configuration • audit only mode for validating existing shared cache state • guarded transient vcpkg cleanup • guarded fingerprint specific transient cleanup • repository registration and unregister support • generated Solution props creation • generated Solution props validation • generated Solution props audit • MSBuild property based contract evaluation • local fixed filesystem validation • active build process protection before cleanup Protobuf and Solution build fixes This branch also includes follow up fixes around protobuf generation and Solution build behavior. Protobuf and Solution changes • Fixes Solution protobuf generation by using one normalized absolute proto root • Uses the host triplet protoc path for protobuf generation • Adds incremental inputs and outputs to the ProtoCompile target • Excludes generated protobuf compile items when protobuf support is disabled • Keeps protobuf generated source handling tied to RunProtoCompile • Lets both CMake and Solution builds honor configured global vcpkg binary sources • Avoids leaking Ninja compiler overrides into Visual Studio CMake presets Documentation and repository updates • Adds shared build cache documentation • Documents setup and migration flow • Documents CMake and Visual Studio integration • Documents cache contract rules • Documents concurrency and locking behavior • Documents fallback behavior • Documents recovery and cleanup procedures • Documents cross fork compatibility rules • Updates README with shared cache guidance • Updates gitignore for generated local shared cache files • Updates CI path filters so vcpkg configuration overlay and cache related changes trigger the correct workflows Validation performed • PowerShell parser validation for both cache tools • PowerShell 5 1 prerequisite failure verified • CMake preset validation • JSON validation • Visual Studio project XML validation • Evaluated MSBuild property and item checks • Checked protobuf enabled mode • Checked protobuf disabled mode • Local shared cache Solution build validation • GitHub Actions Windows CMake matrix • GitHub Actions Windows Solution matrix Overall this commit adds a safe content addressed shared dependency cache for OTClient builds. It lets compatible CMake and Visual Studio configurations reuse expensive vcpkg dependency artifacts while keeping all build outputs local and falling back to worktree local storage whenever the shared contract cannot be fully validated.
This commit is contained in:
parent
1f5df26144
commit
44a980b07e
11 changed files with 5661 additions and 31 deletions
14
.github/workflows/ci.yml
vendored
14
.github/workflows/ci.yml
vendored
|
|
@ -16,6 +16,8 @@ on:
|
|||
- "tools/**"
|
||||
- "vc18/**"
|
||||
- "vcpkg.json"
|
||||
- "vcpkg-configuration.json"
|
||||
- "overlay-ports/**"
|
||||
- "CMakeLists.txt"
|
||||
- "CMakePresets.json"
|
||||
- "Dockerfile"
|
||||
|
|
@ -47,6 +49,8 @@ on:
|
|||
- "tools/**"
|
||||
- "vc18/**"
|
||||
- "vcpkg.json"
|
||||
- "vcpkg-configuration.json"
|
||||
- "overlay-ports/**"
|
||||
- "CMakeLists.txt"
|
||||
- "CMakePresets.json"
|
||||
- "Dockerfile"
|
||||
|
|
@ -97,6 +101,8 @@ jobs:
|
|||
- "cmake/**"
|
||||
- "vc18/**"
|
||||
- "vcpkg.json"
|
||||
- "vcpkg-configuration.json"
|
||||
- "overlay-ports/**"
|
||||
- "CMakeLists.txt"
|
||||
- "CMakePresets.json"
|
||||
- ".yamllint.yaml"
|
||||
|
|
@ -110,6 +116,8 @@ jobs:
|
|||
- "src/**"
|
||||
- "cmake/**"
|
||||
- "vcpkg.json"
|
||||
- "vcpkg-configuration.json"
|
||||
- "overlay-ports/**"
|
||||
- "CMakeLists.txt"
|
||||
- "CMakePresets.json"
|
||||
- ".github/workflows/ci.yml"
|
||||
|
|
@ -120,6 +128,8 @@ jobs:
|
|||
- "cmake/**"
|
||||
- "CMakeLists.txt"
|
||||
- "vcpkg.json"
|
||||
- "vcpkg-configuration.json"
|
||||
- "overlay-ports/**"
|
||||
- "build_luajit_android.sh"
|
||||
- "setup_android_deps.sh"
|
||||
- ".github/workflows/ci.yml"
|
||||
|
|
@ -130,6 +140,8 @@ jobs:
|
|||
- "src/**"
|
||||
- "cmake/**"
|
||||
- "vcpkg.json"
|
||||
- "vcpkg-configuration.json"
|
||||
- "overlay-ports/**"
|
||||
- "CMakeLists.txt"
|
||||
- "CMakePresets.json"
|
||||
- ".yamllint.yaml"
|
||||
|
|
@ -142,6 +154,8 @@ jobs:
|
|||
- "src/**"
|
||||
- "cmake/**"
|
||||
- "vcpkg.json"
|
||||
- "vcpkg-configuration.json"
|
||||
- "overlay-ports/**"
|
||||
- "CMakeLists.txt"
|
||||
- ".yamllint.yaml"
|
||||
- ".github/workflows/ci.yml"
|
||||
|
|
|
|||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -332,3 +332,5 @@ android/app/.cxx/
|
|||
android/.gradle/
|
||||
android/build/
|
||||
luajit-src/
|
||||
CMakeUserPresets.json
|
||||
**/.canary-shared-cache/
|
||||
|
|
|
|||
|
|
@ -36,6 +36,12 @@ if (VCPKG_TARGET_ANDROID)
|
|||
include_directories(Android_INCLUDES)
|
||||
endif()
|
||||
|
||||
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.19)
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/SharedBuildCache.cmake")
|
||||
elseif(DEFINED ENV{CANARY_SHARED_CACHE_ROOT} OR DEFINED CANARY_SHARED_CACHE_ROOT)
|
||||
message(WARNING "Shared build caching requires CMake 3.19 or newer; using build-local vcpkg storage.")
|
||||
endif()
|
||||
|
||||
# *****************************************************************************
|
||||
# Project otclient
|
||||
# *****************************************************************************
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
},
|
||||
"CMAKE_COLOR_DIAGNOSTICS": "ON",
|
||||
"SPEED_UP_BUILD_UNITY": "ON",
|
||||
"VCPKG_INSTALL_OPTIONS": "--binarysource=clear;--binarysource=files,$env{VCPKG_ROOT}/binary-cache,readwrite"
|
||||
"VCPKG_INSTALL_OPTIONS": "--clean-packages-after-build;--clean-buildtrees-after-build"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
@ -28,10 +28,11 @@
|
|||
"description": "Windows release build with Ninja and vcpkg",
|
||||
"cacheVariables": {
|
||||
"BUILD_STATIC_LIBRARY": "ON",
|
||||
"CMAKE_C_COMPILER": "cl.exe",
|
||||
"CMAKE_CXX_COMPILER": "cl.exe",
|
||||
"VCPKG_TARGET_TRIPLET": "x64-windows-static-release",
|
||||
"VCPKG_HOST_TRIPLET": "x64-windows",
|
||||
"VCPKG_OVERLAY_TRIPLETS": "${sourceDir}/cmake/triplets",
|
||||
"VCPKG_INSTALLED_DIR": "${sourceDir}/vcpkg_installed/windows-release",
|
||||
"VCPKG_BUILD_TYPE": "release",
|
||||
"VCPKG_PLATFORM_TOOLSET": "v145",
|
||||
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
|
||||
|
|
@ -65,7 +66,6 @@
|
|||
"BUILD_STATIC_LIBRARY": "OFF",
|
||||
"VCPKG_TARGET_TRIPLET": "x64-windows-test-release",
|
||||
"VCPKG_HOST_TRIPLET": "x64-windows",
|
||||
"VCPKG_INSTALLED_DIR": "${sourceDir}/vcpkg_installed/windows-release-asan",
|
||||
"OTCLIENT_BUILD_TESTS": "ON",
|
||||
"VCPKG_MANIFEST_FEATURES": "tests"
|
||||
}
|
||||
|
|
@ -83,7 +83,6 @@
|
|||
"SPEED_UP_BUILD_UNITY": "OFF",
|
||||
"VCPKG_TARGET_TRIPLET": "x64-windows",
|
||||
"VCPKG_HOST_TRIPLET": "x64-windows",
|
||||
"VCPKG_INSTALLED_DIR": "${sourceDir}/vcpkg_installed/windows-debug",
|
||||
"VCPKG_BUILD_TYPE": "debug",
|
||||
"OTCLIENT_BUILD_TESTS": "OFF"
|
||||
}
|
||||
|
|
@ -96,7 +95,6 @@
|
|||
"cacheVariables": {
|
||||
"VCPKG_TARGET_TRIPLET": "x64-windows-test-debug",
|
||||
"VCPKG_HOST_TRIPLET": "x64-windows",
|
||||
"VCPKG_INSTALLED_DIR": "${sourceDir}/vcpkg_installed/windows-tests",
|
||||
"VCPKG_MANIFEST_FEATURES": "tests",
|
||||
"OTCLIENT_BUILD_TESTS": "ON"
|
||||
}
|
||||
|
|
@ -110,7 +108,9 @@
|
|||
"binaryDir": "${sourceDir}/build/${presetName}",
|
||||
"cacheVariables": {
|
||||
"ASAN_ENABLED": "ON",
|
||||
"TOGGLE_PRE_COMPILED_HEADER": "OFF"
|
||||
"TOGGLE_PRE_COMPILED_HEADER": "OFF",
|
||||
"CMAKE_C_COMPILER": null,
|
||||
"CMAKE_CXX_COMPILER": null
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
@ -122,7 +122,6 @@
|
|||
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
|
||||
"VCPKG_TARGET_TRIPLET": "x64-linux",
|
||||
"VCPKG_HOST_TRIPLET": "x64-linux",
|
||||
"VCPKG_INSTALLED_DIR": "${sourceDir}/vcpkg_installed/linux-release",
|
||||
"VCPKG_BUILD_TYPE": "release",
|
||||
"OPTIONS_ENABLE_CCACHE": "ON",
|
||||
"OTCLIENT_BUILD_TESTS": "OFF"
|
||||
|
|
@ -145,7 +144,6 @@
|
|||
"ASAN_ENABLED": "OFF",
|
||||
"TOGGLE_PRE_COMPILED_HEADER": "OFF",
|
||||
"SPEED_UP_BUILD_UNITY": "OFF",
|
||||
"VCPKG_INSTALLED_DIR": "${sourceDir}/vcpkg_installed/linux-debug",
|
||||
"VCPKG_BUILD_TYPE": "debug",
|
||||
"VCPKG_MANIFEST_FEATURES": "tests",
|
||||
"OTCLIENT_BUILD_TESTS": "ON"
|
||||
|
|
@ -165,7 +163,6 @@
|
|||
"CMAKE_C_FLAGS_RELEASE": "-O2 -DNDEBUG",
|
||||
"VCPKG_TARGET_TRIPLET": "arm64-osx",
|
||||
"VCPKG_HOST_TRIPLET": "arm64-osx",
|
||||
"VCPKG_INSTALLED_DIR": "${sourceDir}/vcpkg_installed/macos-release",
|
||||
"VCPKG_BUILD_TYPE": "release",
|
||||
"OTCLIENT_BUILD_TESTS": "OFF"
|
||||
},
|
||||
|
|
@ -186,7 +183,6 @@
|
|||
"ASAN_ENABLED": "ON",
|
||||
"BUILD_STATIC_LIBRARY": "OFF",
|
||||
"SPEED_UP_BUILD_UNITY": "OFF",
|
||||
"VCPKG_INSTALLED_DIR": "${sourceDir}/vcpkg_installed/macos-debug",
|
||||
"VCPKG_BUILD_TYPE": "debug",
|
||||
"VCPKG_MANIFEST_FEATURES": "tests",
|
||||
"OTCLIENT_BUILD_TESTS": "ON"
|
||||
|
|
|
|||
|
|
@ -514,6 +514,9 @@ This is a fork of edubart's OTClient. The objective of this fork is to develop a
|
|||
## <a id="compiling"></a>🔨 Compiling
|
||||
If you are interested in compiling this project, visit the **[Wiki](https://github.com/mehah/otclient/wiki)**.
|
||||
|
||||
For content-addressed vcpkg reuse across CMake presets, Visual Studio Solutions,
|
||||
worktrees, and compatible forks, see the [shared build cache guide](docs/development/shared-build-cache.md).
|
||||
|
||||
---
|
||||
|
||||
## <a id="docker"></a>🐳 Docker
|
||||
|
|
|
|||
3026
cmake/SharedBuildCache.cmake
Normal file
3026
cmake/SharedBuildCache.cmake
Normal file
File diff suppressed because it is too large
Load diff
298
docs/development/shared-build-cache.md
Normal file
298
docs/development/shared-build-cache.md
Normal file
|
|
@ -0,0 +1,298 @@
|
|||
# Shared build cache for worktrees and forks
|
||||
|
||||
Related native-code repositories can share expensive reusable artifacts across Git worktrees and independent forks without sharing mutable CMake build trees. The shared pool must live on a local filesystem outside every source and build hierarchy, so removing one checkout cannot remove another checkout's dependencies.
|
||||
|
||||
## Cache ownership
|
||||
|
||||
| Layer | Ownership | Reason |
|
||||
| --- | --- | --- |
|
||||
| CMake and Solution outputs | One per worktree and build system | CMake/Ninja state, MSBuild intermediate directories, objects, PCH/PDB files, generated files, and executables contain consumer-specific paths. |
|
||||
| vcpkg binary cache | Global | vcpkg addresses binary packages by their package ABI. Different manifests and baselines can reuse a package when its ABI is identical. |
|
||||
| vcpkg downloads | Global | Sources and tools are reusable download assets. |
|
||||
| `VCPKG_INSTALLED_DIR` | One per complete dependency fingerprint | Any worktree or independent fork with the same contract uses the same installed tree. Different contracts receive different trees. |
|
||||
| vcpkg `buildtrees` and `packages` | One per fingerprint, transient | Compatible installs serialize on one installed-root lock. Incompatible installs cannot stage or clean each other's files. |
|
||||
| sccache storage | Global per user or machine | Compiler outputs are content-addressed. Exact source roots in `SCCACHE_BASEDIRS` normalize equivalent paths across checkouts. |
|
||||
|
||||
MSVC precompiled headers remain worktree-local. Current sccache releases report compilations using `/Fp` or `/Yc` as non-cacheable, so `SCCACHE_BASEDIRS` benefits only eligible units and tools. Do not share `.pch` files or remove PCH flags merely to force cache hits; use `sccache --show-stats` to distinguish this expected limitation from a path-normalization regression.
|
||||
|
||||
Never junction, symlink, or otherwise share an entire `build` or `vcpkg_installed` directory manually. Do not place the pool inside a primary worktree.
|
||||
|
||||
## Windows setup
|
||||
|
||||
The setup and Solution helpers require PowerShell 7.2 or newer. Invoke them with `pwsh`, not Windows PowerShell 5.1.
|
||||
|
||||
From a worktree in each independent Git repository that should participate, run:
|
||||
|
||||
```powershell
|
||||
pwsh -File tools/configure_shared_build_cache.ps1
|
||||
```
|
||||
|
||||
The Solution bridge requires MSBuild 17.8 or newer because it queries evaluated project properties without compiling. If the machine has more than one Visual Studio/MSBuild installation, select the supported executable that actually opens or builds the Solutions:
|
||||
|
||||
```powershell
|
||||
pwsh -File tools/configure_shared_build_cache.ps1 -SolutionMSBuildPath <path-to-MSBuild.exe>
|
||||
```
|
||||
|
||||
The helper persists that choice as `CANARY_SOLUTION_MSBUILD_PATH` and uses it whenever it regenerates Solution contracts. The exact MSBuild executable is a consumer input, so switching to another installation requires regenerating the `.props`; the neutral dependency fingerprint and expanded vcpkg tree can still remain identical.
|
||||
|
||||
The first invocation creates a machine-local repository registry below the shared cache root. Later invocations add the current repository's Git common directory. Every invocation re-enumerates all registered repositories and their worktrees, so `SCCACHE_BASEDIRS` and cache audits cover the complete set instead of replacing one fork with another.
|
||||
|
||||
For backward compatibility, the default shared root is a `canary-build-cache` directory beside the active `VCPKG_ROOT`. Override it with the same short, local path in every participating repository when needed:
|
||||
|
||||
```powershell
|
||||
pwsh -File tools/configure_shared_build_cache.ps1 -CacheRoot <cache-root>
|
||||
```
|
||||
|
||||
The helper:
|
||||
|
||||
- persists `CANARY_SHARED_CACHE_ROOT` for the current Windows user;
|
||||
- verifies that the pool and its existing ancestors are on a ready local fixed volume without reparse points, persists `CANARY_SHARED_CACHE_LOCAL_FILESYSTEM_VERIFIED=ON`, and binds that proof to the exact path in `CANARY_SHARED_CACHE_VERIFIED_ROOT`;
|
||||
- registers the current independent Git repository and discovers all its worktrees;
|
||||
- preserves an existing vcpkg binary-cache configuration or creates a local file backend when absent;
|
||||
- never persists or prints an existing `VCPKG_BINARY_SOURCES`, because it may contain credentials;
|
||||
- makes the vcpkg downloads directory explicit and global;
|
||||
- does not persist or change `VCPKG_ROOT`; the active project or tool manager owns the vcpkg executable;
|
||||
- pins the Visual Studio instance selected by vcpkg in the compatibility variable `CANARY_VCPKG_VISUAL_STUDIO_PATH`; the CMake module exports the standard vcpkg variable only to its configure process;
|
||||
- manages `SCCACHE_BASEDIRS` as the union of every registered worktree root plus pre-existing unmanaged entries;
|
||||
- creates cache directories and, when the repository carries the Solution bridge, prepares its ignored generated `.props`; it does not configure CMake or compile the project.
|
||||
|
||||
Restart open terminals and long-running development applications after setup. Restart an existing sccache server only after active builds finish. Run the helper after adding, moving, or removing worktrees.
|
||||
|
||||
Audit all registered repositories without mutation:
|
||||
|
||||
```powershell
|
||||
pwsh -File tools/configure_shared_build_cache.ps1 -AuditOnly
|
||||
```
|
||||
|
||||
Remove the current repository family from the machine-local registry before retiring it:
|
||||
|
||||
```powershell
|
||||
pwsh -File tools/configure_shared_build_cache.ps1 -UnregisterCurrentRepository
|
||||
```
|
||||
|
||||
This updates the managed sccache roots but does not delete the repository or any cache data.
|
||||
|
||||
Remove only the legacy transient directories below the active `VCPKG_ROOT` with:
|
||||
|
||||
```powershell
|
||||
pwsh -File tools/configure_shared_build_cache.ps1 -CleanTransientVcpkg
|
||||
```
|
||||
|
||||
The helper refuses cleanup while build-related processes are active and holds the vcpkg root lock during deletion. It preserves installed trees, downloads, binary packages, and fingerprint-specific pools. Cleanup mode does not register repositories, persist environment variables, create the shared layout, detect compilers, or regenerate Solution contracts.
|
||||
|
||||
To reclaim only the disposable `buildtrees` and `packages` data for one known schema-v3 pool, pass its full dependency SHA-256:
|
||||
|
||||
```text
|
||||
pwsh -File tools/configure_shared_build_cache.ps1 -CleanSharedFingerprintTransients <full-dependency-fingerprint>
|
||||
```
|
||||
|
||||
This narrower cleanup validates the full-hash identity metadata, confines both targets to the verified local cache root, holds the registry operation lock and that installed tree's vcpkg lock, and refuses to run while build processes are active. It never removes the expanded installed tree, metadata, downloads, or binary cache, and it performs no setup side effects. Because it does not prune persistent data, it remains suitable when the global consumer audit is incomplete; pruning an installed fingerprint still requires the complete audit described below.
|
||||
|
||||
## Non-Windows setup
|
||||
|
||||
Set `CANARY_SHARED_CACHE_ROOT` to one short local path outside every participating checkout. After independently verifying that exact path is on a local filesystem with reliable lock and rename semantics, set `CANARY_SHARED_CACHE_LOCAL_FILESYSTEM_VERIFIED=ON` and set `CANARY_SHARED_CACHE_VERIFIED_ROOT` to the same absolute path. Repeat the verification whenever the root changes. Keep downloads, the vcpkg binary cache, and sccache global. Build the `SCCACHE_BASEDIRS` list from the exact roots emitted by `git worktree list` for every independent repository, separated by `:`.
|
||||
|
||||
Do not use a network filesystem for mutable installed or transient pools. Its locking and rename semantics may not be strong enough for concurrent vcpkg operations.
|
||||
|
||||
## Normal configure and build
|
||||
|
||||
Continue using repository presets:
|
||||
|
||||
```text
|
||||
cmake --preset <configure-preset>
|
||||
cmake --build --preset <build-preset>
|
||||
```
|
||||
|
||||
`cmake/SharedBuildCache.cmake` runs before the first `project()` call. When it can prove the complete installation contract, it selects:
|
||||
|
||||
```text
|
||||
<cache-root>/vcpkg-installed/v3/<dependency-fingerprint>
|
||||
<cache-root>/vcpkg-buildtrees/v3/<dependency-fingerprint>
|
||||
<cache-root>/vcpkg-packages/v3/<dependency-fingerprint>
|
||||
```
|
||||
|
||||
The first directory is persistent. The latter two are transient and are cleaned after successful dependency builds by the preset's vcpkg options.
|
||||
|
||||
If sharing cannot be proven, a fresh configure uses `<binary-dir>/vcpkg_installed`, `<binary-dir>/vcpkg-buildtrees`, and `<binary-dir>/vcpkg-packages`. This fallback prefers duplication over mixing incompatible binaries and cannot collide with another opt-out project.
|
||||
|
||||
Container and packaging stages may preprovision an immutable installed tree and configure with `VCPKG_MANIFEST_INSTALL=OFF`. In that explicit mode the module preserves the caller's `VCPKG_INSTALLED_DIR`, does not assign shared transient roots, and marks the shared pool inactive. Switching an existing managed configure tree to or from this mode still requires `--fresh`. Do not use this exception for an installation that vcpkg will mutate.
|
||||
|
||||
Windows Ninja presets that select `cl.exe` require a Visual Studio developer environment. `VsDevCmd.bat` may replace an existing `VCPKG_ROOT` with the vcpkg bundled by Visual Studio, so initialize the developer environment first and then select the project-managed `VCPKG_ROOT` before running the helper, configure, or build in that same environment. A different vcpkg installation is a different dependency contract and may intentionally select a different pool or trigger the safe local fallback. On other hosts, set both `CC` and `CXX`, or both CMake compiler variables, when the first configure cannot identify them safely.
|
||||
|
||||
Disable the shared installed tree for an isolated configure with:
|
||||
|
||||
```text
|
||||
-DCANARY_USE_SHARED_VCPKG_INSTALLED=OFF
|
||||
```
|
||||
|
||||
Switching an existing build tree between opt-in and opt-out changes dependency paths and therefore requires:
|
||||
|
||||
```text
|
||||
cmake --fresh --preset <configure-preset> -DCANARY_USE_SHARED_VCPKG_INSTALLED=OFF
|
||||
```
|
||||
|
||||
Use separate configure presets and binary directories if opt-in and opt-out builds must exist simultaneously.
|
||||
|
||||
## Visual Studio Solution builds
|
||||
|
||||
Repositories that include `SharedVcpkgCache.targets` in their maintained Solution directory use the same dependency resolver for CMake and MSBuild. Normal setup generates an ignored, machine-local `.canary-shared-cache/SharedVcpkgCache.props` beside the selected project. The bridge discovers the maintained `vcproj`, `vc18`, or `vc17` project and all configurations for the requested platform. Regenerate it directly when only the Solution contract changed:
|
||||
|
||||
```powershell
|
||||
pwsh -File tools/configure_shared_solution_cache.ps1
|
||||
```
|
||||
|
||||
Projects whose Solution uses configuration names other than the conventional
|
||||
`Debug` and `Release` can generate all contracts explicitly, for example:
|
||||
|
||||
```powershell
|
||||
pwsh -File tools/configure_shared_solution_cache.ps1 -Configurations Debug,OpenGL,DirectX
|
||||
```
|
||||
|
||||
Configuration and platform names may contain spaces, such as `Release Static` or `Any CPU`. The helper rejects XML, path, and MSBuild metacharacters instead of embedding untrusted values in the generated condition.
|
||||
|
||||
The setup and audit helper discovers the maintained x64 project in the common
|
||||
`vcproj`, `vc18`, or `vc17` layout and derives its configuration names from the
|
||||
project file. This keeps repositories with a CMake entry point and a native
|
||||
Solution under the same dependency contract without sharing their object,
|
||||
PCH, PDB, generated-source, or output directories.
|
||||
|
||||
Reload the Visual Studio project after the file changes. The generated file supplies each supported configuration with its validated `VcpkgInstalledDir`, fingerprint-specific `buildtrees` and `packages` roots, cleanup options, selected vcpkg checkout, and pinned Visual Studio instance. The tracked target re-evaluates the complete contract immediately before `VcpkgInstallManifestDependencies` inside the active developer environment; stale generated values stop the build and request regeneration instead of mutating the wrong pool.
|
||||
|
||||
The bridge uses two hashes:
|
||||
|
||||
- the **dependency fingerprint** is neutral between CMake and MSBuild and owns the expanded installed and transient roots;
|
||||
- the **consumer fingerprint** binds that dependency contract to the invoking build system, generator or configuration, and its build-system tool.
|
||||
|
||||
Consequently, a Solution Release configuration and a CMake Release preset share one expanded tree only when their target and host triplets, features, registries, overlays, linkage, compiler, toolset, SDK, vcpkg revision, and dependency tools all match. Debug or any other configuration with a different contract receives another dependency fingerprint automatically. Command-line MSBuild overrides for the manifest root, triplets, link configuration, toolset, SDK, or install options are compared with the generated contract and fail closed when incompatible. Never copy a fingerprint from another configuration or edit the generated `.props`.
|
||||
|
||||
When no generated `.props` exists, the Solution uses `vcpkg_installed`, `.vcpkg-buildtrees/<configuration>`, and `.vcpkg-packages/<configuration>` below its own project directory. This is the safe fallback when the global cache is not configured. Solution objects, PCH/PDB files, generated protocol sources, intermediate directories, and executables always remain local, even when dependencies converge with CMake.
|
||||
|
||||
Audit only the Solution bridge without writing pools or generated files:
|
||||
|
||||
```powershell
|
||||
pwsh -File tools/configure_shared_solution_cache.ps1 -AuditOnly
|
||||
```
|
||||
|
||||
Use `-WhatIf` to preview the contracts. The repository-wide `configure_shared_build_cache.ps1 -AuditOnly` also scans and re-evaluates generated Solution contracts across every registered worktree. The Solution inherits the global vcpkg downloads and binary cache. It does not automatically route compiler invocations through sccache; adding such a launcher is a separate concern, and MSVC PCH compilations remain ineligible.
|
||||
|
||||
## Sharing across baselines and forks
|
||||
|
||||
The repository name, branch, and absolute checkout path are not fingerprint inputs. Independent forks therefore converge when their declared and effective dependency contracts are identical.
|
||||
|
||||
A common `builtin-baseline` improves the chance of reuse but is not sufficient. Sharing an installed tree also requires identical manifests, enabled features, registry configuration and content, ordered overlays, target and host triplets, linkage, vcpkg options, compiler/toolset identity, dependency-tool identity, and vcpkg revision.
|
||||
|
||||
Repositories in one maintained fork family must inherit their vcpkg baseline, default registry baseline, version metadata, and shared custom-port payloads from that family's open upstream. A fork may add a dependency required by its own code, but it must resolve common dependencies through the same catalog instead of selecting an independent version. Scheduled update automation must synchronize from the open upstream rather than advancing each fork independently.
|
||||
|
||||
An unrelated project family or a temporarily incompatible migration may still use a different catalog. The fingerprint isolates that contract while downloads and ABI-compatible binary packages remain global. Treat such a split as an explicit compatibility boundary, not as a disk-saving shortcut, and document why the canonical catalog cannot yet be used.
|
||||
|
||||
One fixed global vcpkg tool checkout may serve several manifest baselines when that is the repository's supported workflow. If projects require different vcpkg tool revisions, activate an immutable tool root per revision or per shell. Never let concurrent projects switch one shared mutable vcpkg checkout between revisions. The selected executable, toolchain, and Git revision participate in the fingerprint.
|
||||
|
||||
vcpkg does not provide a supported content-addressed or hardlinked representation for files expanded into different installed trees. The safe native limit is one expanded tree per exact contract; do not hardlink or junction two distinct fingerprints.
|
||||
|
||||
### Canonical dependency contracts between forks
|
||||
|
||||
The fingerprint deliberately does not guess that two different vcpkg declarations are semantically equivalent. For example, a byte-identical custom port delivered as an overlay and as a filesystem registry still produces different fingerprints. Those mechanisms have different precedence, version selection, and metadata rules, so automatically treating them as interchangeable could mix incompatible installations.
|
||||
|
||||
When several maintained forks are intended to use the same dependency contract, select one canonical representation and port that representation atomically. A versioned filesystem registry is usually preferable for a maintained custom port because it records both the port payload and its version metadata. Equality requires more than copying the port directory:
|
||||
|
||||
- keep `vcpkg.json`, the separate or embedded vcpkg configuration, registry metadata, triplets, features, and install options aligned;
|
||||
- include the filesystem registry's `versions/baseline.json` and per-port version database, not only `ports/<port>`;
|
||||
- keep the same normalized `cmake/SharedBuildCache.cmake` implementation and schema;
|
||||
- use the same vcpkg tool revision and compiler contract for configurations that are expected to converge;
|
||||
- when automation updates a baseline that is declared in both the manifest and `default-registry`, update both declarations in one change.
|
||||
|
||||
Before canonicalizing two forks, compare the dependency inputs and prove that the selected features, linkage, target and host triplets, and custom port contents are compatible. Align common dependency versions to the open upstream catalog. Preserve only genuinely additive dependencies and build-contract differences; they receive a separate fingerprint while still sharing downloads, sccache storage, and ABI-compatible binary packages.
|
||||
|
||||
After adopting the canonical representation, run the setup helper from the newly participating repository, configure its existing preset with `--fresh`, regenerate any Solution `.props`, and compare the full dependency fingerprints. Matching fingerprints are the result of matching contracts; never override or manually rename a fingerprint to force convergence. If the fingerprints differ, inspect their metadata and preserve the separate pools until the remaining input difference is understood.
|
||||
|
||||
Another build system must keep its expanded installed tree local until it consumes this same neutral dependency contract, validates its own consumer fingerprint, and supplies equivalent locking and transient-root options. It may still use the global downloads and vcpkg binary cache.
|
||||
|
||||
## Fingerprint contract
|
||||
|
||||
The dependency fingerprint contains inputs that can change the manifest installation or package ABI:
|
||||
|
||||
- the normalized implementation hash and schema of `cmake/SharedBuildCache.cmake`;
|
||||
- the complete `vcpkg.json`, including either supported embedded configuration spelling, and optional separate `vcpkg-configuration.json`;
|
||||
- contents of filesystem registries declared by the configuration;
|
||||
- ordered contents of overlay port and overlay triplet directories declared by variables or configuration;
|
||||
- target and host triplet names and selected triplet files;
|
||||
- manifest features, feature flags, linkage settings, build type, and install options;
|
||||
- chainloaded toolchain contents;
|
||||
- host identity and the CMake executable/version used as a dependency tool;
|
||||
- C and C++ compiler executable hashes;
|
||||
- on Windows, the pinned vcpkg Visual Studio instance, `vcvarsall.bat`, and selectable MSVC compiler tool binaries;
|
||||
- selected Visual Studio toolset, Windows SDK, and host/target architecture environment;
|
||||
- vcpkg executable, toolchain, repository revision, and relevant dirty state.
|
||||
|
||||
The consumer fingerprint includes the dependency fingerprint and then adds either the CMake generator and CMake consumer identity, or the MSBuild executable, build configuration, link configuration, platform, toolset, and SDK. Consumer-specific values do not create duplicate installed trees when the dependency contract is identical, but they are validated to prevent a stale CMake cache or generated `.props` from silently changing build systems.
|
||||
|
||||
The module disables sharing when any required identity or the local-filesystem guarantee is ambiguous. Absolute worktree paths do not participate. Content paths inside manifests and configurations still participate through the files themselves, while referenced local trees are hashed using relative file names and contents.
|
||||
|
||||
The module's normalized SHA-256 is part of schema `v3`. Copies in different forks must therefore be byte-equivalent after newline normalization to converge. A divergent implementation selects another fingerprint even if a maintainer forgets to bump the schema.
|
||||
|
||||
An existing configured preset never changes fingerprint or falls back in place. Cached package variables could retain paths into the old pool, so the module stops before `project()` and requests `cmake --fresh --preset <configure-preset>`.
|
||||
|
||||
Fingerprint input files and trees are CMake configure dependencies. Adding, removing, or changing a manifest, registry, overlay, triplet, compiler, or toolchain input requests regeneration.
|
||||
|
||||
The full dependency SHA-256 and non-local metadata are written below `<cache-root>/metadata/v3`. Directory names use the first 24 hexadecimal characters to limit Windows path length; the metadata lock verifies the full hash before a shortened directory is accepted.
|
||||
|
||||
## Concurrency
|
||||
|
||||
Consumers of one fingerprint request one package set and installed-root lock. Different fingerprints receive independent installed, `buildtrees`, and `packages` roots. Projects that opt out receive build-local roots.
|
||||
|
||||
Do not manually modify a fingerprint directory. Do not prune caches while CMake, vcpkg, Ninja, a compiler, or a linker is using any registered build family.
|
||||
|
||||
## Migrating existing build trees
|
||||
|
||||
Reconfigure an existing preset with `--fresh`; do not create an ad-hoc build directory:
|
||||
|
||||
```text
|
||||
cmake --fresh --preset <configure-preset>
|
||||
```
|
||||
|
||||
Verify its `CMakeCache.txt`:
|
||||
|
||||
```text
|
||||
CANARY_SHARED_VCPKG_ACTIVE:INTERNAL=true
|
||||
CANARY_VCPKG_DEPENDENCY_FINGERPRINT:INTERNAL=<full-dependency-fingerprint>
|
||||
CANARY_VCPKG_CONSUMER_FINGERPRINT:INTERNAL=<full-consumer-fingerprint>
|
||||
VCPKG_INSTALLED_DIR:PATH=<cache-root>/vcpkg-installed/v3/<dependency-fingerprint>
|
||||
```
|
||||
|
||||
Also confirm that `CMakeCache.txt` and the generated native build files contain neither a legacy local installed path nor another global fingerprint. Inspect `build.ninja` for a Ninja preset; inspect the generated `.sln` and `.vcxproj` files for a Visual Studio preset. Complete a build against the refreshed preset before deleting the old local tree, then build again after deletion. The final invocation must not recreate the local installation.
|
||||
|
||||
For a Solution migration, generate the `.props`, reload the project, build every migrated configuration successfully, and confirm a no-op rebuild. Only then remove that worktree's exact legacy `vcpkg_installed` directory and repeat the build. If multiple configurations used the same local installed directory, all of them must be migrated and validated before deletion.
|
||||
|
||||
## Cleanup and recovery
|
||||
|
||||
Before pruning a fingerprint:
|
||||
|
||||
1. Confirm no configure or build process is active.
|
||||
2. Run the audit from any registered repository.
|
||||
3. Inspect every reported `CMakeCache.txt` and generator-specific build file: `build.ninja` for Ninja, or the generated `.sln` and `.vcxproj` files for Visual Studio. Inspect every generated Solution cache contract as well.
|
||||
4. Preserve every installed root referenced by any registered CMake or MSBuild consumer.
|
||||
5. Remove only an unreferenced fingerprint and its matching transient and metadata entries.
|
||||
|
||||
An audit that reports an unregistered, unavailable, partially enumerated, or malformed repository/configure tree, a non-local/reparse root, or a missing/mismatched full-hash identity is incomplete and exits with failure. Do not prune any global fingerprint until every registered family is available and the audit succeeds.
|
||||
|
||||
Schema migrations intentionally create a new pool. Keep the previous schema until every registered configured build has migrated, built successfully, and stopped referencing it.
|
||||
|
||||
If one fingerprint becomes corrupt, stop all its consumers, remove only that exact directory, and reconfigure one existing preset. vcpkg recreates it from the binary cache. Do not delete downloads or the global binary cache during normal recovery.
|
||||
|
||||
## CI and production boundaries
|
||||
|
||||
The feature is opt-in through `CANARY_SHARED_CACHE_ROOT`. CI and fresh clones retain build-local manifest installations unless their environment explicitly enables the pool. Cache setup must not change deployment directories, runtime data, production services, or release publication behavior.
|
||||
|
||||
## Regression checklist
|
||||
|
||||
Before changing build or dependency configuration, verify:
|
||||
|
||||
- `build/<preset>` remains local to each worktree;
|
||||
- Solution intermediate/output directories, PCH/PDB files, and generated files remain local;
|
||||
- all vcpkg settings are finalized before `project()`;
|
||||
- new manifest, registry, overlay, triplet, compiler, and toolchain inputs participate in the fingerprint;
|
||||
- independent forks use the same module implementation before sharing a fingerprint;
|
||||
- opt-out and fallback transients remain build-local;
|
||||
- no machine-local path appears in committed presets or documentation;
|
||||
- shared mutable state remains on a local filesystem outside every checkout;
|
||||
- the repository registry and cleanup audit cover every consumer before data is removed.
|
||||
1476
tools/configure_shared_build_cache.ps1
Normal file
1476
tools/configure_shared_build_cache.ps1
Normal file
File diff suppressed because it is too large
Load diff
724
tools/configure_shared_solution_cache.ps1
Normal file
724
tools/configure_shared_solution_cache.ps1
Normal file
|
|
@ -0,0 +1,724 @@
|
|||
#Requires -Version 7.2
|
||||
|
||||
[CmdletBinding(SupportsShouldProcess = $true)]
|
||||
param(
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string] $Configuration = "All",
|
||||
[string[]] $Configurations = @(),
|
||||
[string] $Platform = "x64",
|
||||
[string] $ProjectFile,
|
||||
[string] $OutputProps,
|
||||
[string] $CacheRoot,
|
||||
[string] $VcpkgRoot,
|
||||
[string] $VisualStudioPath,
|
||||
[string] $CMakePath,
|
||||
[string] $MSBuildPath,
|
||||
[string] $FingerprintInputDirectory,
|
||||
[switch] $ValidateOnly,
|
||||
[switch] $AuditOnly,
|
||||
[string] $ExpectedDependencyFingerprint,
|
||||
[string] $ExpectedConsumerFingerprint,
|
||||
[string] $ExpectedInstalledRoot
|
||||
)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Get-FullPath {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string] $Path,
|
||||
[string] $BasePath = (Get-Location).Path
|
||||
)
|
||||
|
||||
$fullPath = if ([IO.Path]::IsPathRooted($Path)) {
|
||||
[IO.Path]::GetFullPath($Path)
|
||||
} else {
|
||||
[IO.Path]::GetFullPath((Join-Path $BasePath $Path))
|
||||
}
|
||||
$pathRoot = [IO.Path]::GetPathRoot($fullPath)
|
||||
if ($fullPath -eq $pathRoot) {
|
||||
return $fullPath
|
||||
}
|
||||
|
||||
return $fullPath.TrimEnd(
|
||||
[IO.Path]::DirectorySeparatorChar,
|
||||
[IO.Path]::AltDirectorySeparatorChar
|
||||
)
|
||||
}
|
||||
|
||||
function Get-EnvironmentValue {
|
||||
param([Parameter(Mandatory = $true)][string] $Name)
|
||||
|
||||
foreach ($scope in @("Process", "User", "Machine")) {
|
||||
$value = [Environment]::GetEnvironmentVariable($Name, $scope)
|
||||
if (-not [string]::IsNullOrWhiteSpace($value)) {
|
||||
return $value
|
||||
}
|
||||
}
|
||||
|
||||
return $null
|
||||
}
|
||||
|
||||
function Assert-LocalFixedVolume {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string] $Path,
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string] $Description
|
||||
)
|
||||
|
||||
$fullPath = Get-FullPath -Path $Path
|
||||
$existingPath = $fullPath
|
||||
while (-not (Test-Path -LiteralPath $existingPath)) {
|
||||
$parentPath = Split-Path -Parent $existingPath
|
||||
if ([string]::IsNullOrWhiteSpace($parentPath) -or $parentPath -eq $existingPath) {
|
||||
throw "$Description has no verifiable existing filesystem ancestor: $fullPath"
|
||||
}
|
||||
$existingPath = $parentPath
|
||||
}
|
||||
while (-not [string]::IsNullOrWhiteSpace($existingPath)) {
|
||||
$existingItem = Get-Item -LiteralPath $existingPath -Force
|
||||
if ($existingItem.Attributes -band [IO.FileAttributes]::ReparsePoint) {
|
||||
throw "$Description traverses a reparse point and cannot prove local filesystem semantics: $existingPath"
|
||||
}
|
||||
$parentPath = Split-Path -Parent $existingPath
|
||||
if ([string]::IsNullOrWhiteSpace($parentPath) -or $parentPath -eq $existingPath) {
|
||||
break
|
||||
}
|
||||
$existingPath = $parentPath
|
||||
}
|
||||
|
||||
$pathRoot = [IO.Path]::GetPathRoot($fullPath)
|
||||
if ([string]::IsNullOrWhiteSpace($pathRoot)) {
|
||||
throw "$Description does not resolve to a filesystem volume: $fullPath"
|
||||
}
|
||||
$drive = [IO.DriveInfo]::new($pathRoot)
|
||||
if (-not $drive.IsReady -or $drive.DriveType -ne [IO.DriveType]::Fixed) {
|
||||
throw "$Description must use a ready local fixed volume: $fullPath"
|
||||
}
|
||||
}
|
||||
|
||||
function Resolve-Executable {
|
||||
param(
|
||||
[string] $Candidate,
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string] $Name
|
||||
)
|
||||
|
||||
if (-not [string]::IsNullOrWhiteSpace($Candidate)) {
|
||||
$candidatePath = Get-FullPath -Path $Candidate
|
||||
if (Test-Path -LiteralPath $candidatePath -PathType Leaf) {
|
||||
return $candidatePath
|
||||
}
|
||||
throw "$Name was not found: $candidatePath"
|
||||
}
|
||||
|
||||
$command = Get-Command $Name -ErrorAction SilentlyContinue | Select-Object -First 1
|
||||
if ($null -ne $command) {
|
||||
return Get-FullPath -Path $command.Source
|
||||
}
|
||||
|
||||
return $null
|
||||
}
|
||||
|
||||
function Assert-MSBuildPropertyQuerySupport {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string] $Executable
|
||||
)
|
||||
|
||||
$versionOutput = @(& $Executable -nologo -version 2>&1)
|
||||
$msbuildExitCode = $LASTEXITCODE
|
||||
if ($msbuildExitCode -ne 0) {
|
||||
throw "MSBuild version detection failed for $Executable with exit code $msbuildExitCode."
|
||||
}
|
||||
|
||||
$versionMatch = [regex]::Match(
|
||||
($versionOutput -join [Environment]::NewLine),
|
||||
'(?m)^\s*(\d+\.\d+(?:\.\d+){0,2})\s*$'
|
||||
)
|
||||
if (-not $versionMatch.Success) {
|
||||
throw "MSBuild did not report a recognizable version: $Executable"
|
||||
}
|
||||
|
||||
$msbuildVersion = [version] $versionMatch.Groups[1].Value
|
||||
if ($msbuildVersion -lt [version] "17.8") {
|
||||
throw "MSBuild 17.8 or newer is required for evaluated property queries. Found $msbuildVersion at $Executable."
|
||||
}
|
||||
}
|
||||
|
||||
function Assert-SafeMSBuildDimension {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string] $Value,
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string] $Description
|
||||
)
|
||||
|
||||
if (
|
||||
[string]::IsNullOrWhiteSpace($Value) -or
|
||||
$Value.Length -gt 128 -or
|
||||
$Value -notmatch '^[A-Za-z0-9_. -]+$'
|
||||
) {
|
||||
throw "Unsupported $Description name: $Value"
|
||||
}
|
||||
}
|
||||
|
||||
function Import-VisualStudioEnvironment {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string] $Root,
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string] $PreservedVcpkgRoot
|
||||
)
|
||||
|
||||
$developerCommand = Join-Path $Root "Common7\Tools\VsDevCmd.bat"
|
||||
if (-not (Test-Path -LiteralPath $developerCommand -PathType Leaf)) {
|
||||
throw "Visual Studio developer environment was not found: $developerCommand"
|
||||
}
|
||||
|
||||
$environmentLines = & cmd.exe /d /s /c "`"$developerCommand`" -no_logo -arch=x64 -host_arch=x64 && set"
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Visual Studio developer environment initialization failed with exit code $LASTEXITCODE."
|
||||
}
|
||||
|
||||
foreach ($line in $environmentLines) {
|
||||
$separator = $line.IndexOf("=")
|
||||
if ($separator -le 0) {
|
||||
continue
|
||||
}
|
||||
[Environment]::SetEnvironmentVariable(
|
||||
$line.Substring(0, $separator),
|
||||
$line.Substring($separator + 1),
|
||||
"Process"
|
||||
)
|
||||
}
|
||||
|
||||
# VsDevCmd may select the Visual Studio bundled vcpkg. The repository contract
|
||||
# owns the active vcpkg root, so restore it after importing compiler variables.
|
||||
[Environment]::SetEnvironmentVariable("VCPKG_ROOT", $PreservedVcpkgRoot, "Process")
|
||||
}
|
||||
|
||||
function Get-MSBuildProperties {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string] $Executable,
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string] $Project,
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string] $BuildConfiguration,
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string] $BuildPlatform
|
||||
)
|
||||
|
||||
$propertyNames = @(
|
||||
"VcpkgRoot",
|
||||
"VcpkgManifestRoot",
|
||||
"VcpkgTriplet",
|
||||
"VcpkgHostTriplet",
|
||||
"VcpkgConfiguration",
|
||||
"VcpkgEnableManifest",
|
||||
"PlatformToolset",
|
||||
"WindowsTargetPlatformVersion",
|
||||
"CanaryVcpkgBuildType",
|
||||
"CanaryVcpkgFeatureFlags",
|
||||
"CanaryVcpkgManifestFeatures",
|
||||
"CanaryVcpkgManifestNoDefaultFeatures",
|
||||
"CanaryVcpkgOverlayPorts",
|
||||
"CanaryVcpkgOverlayTriplets",
|
||||
"CanaryVcpkgInstallOptions"
|
||||
) -join ","
|
||||
|
||||
$arguments = @(
|
||||
$Project,
|
||||
"-nologo",
|
||||
"-nodeReuse:false",
|
||||
"-p:Configuration=$BuildConfiguration",
|
||||
"-p:Platform=$BuildPlatform",
|
||||
"-p:CanarySharedVcpkgDisable=true",
|
||||
"-getProperty:$propertyNames"
|
||||
)
|
||||
$output = & $Executable @arguments 2>&1
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "MSBuild property evaluation failed for $BuildConfiguration|$BuildPlatform.`n$($output -join [Environment]::NewLine)"
|
||||
}
|
||||
|
||||
$json = $output -join [Environment]::NewLine
|
||||
$jsonStart = $json.IndexOf("{")
|
||||
if ($jsonStart -lt 0) {
|
||||
throw "MSBuild did not return its evaluated properties as JSON."
|
||||
}
|
||||
|
||||
return ($json.Substring($jsonStart) | ConvertFrom-Json).Properties
|
||||
}
|
||||
|
||||
function Convert-ContractResult {
|
||||
param([Parameter(Mandatory = $true)][string] $Path)
|
||||
|
||||
$result = [ordered]@{}
|
||||
foreach ($line in Get-Content -LiteralPath $Path) {
|
||||
$separator = $line.IndexOf("=")
|
||||
if ($separator -le 0) {
|
||||
continue
|
||||
}
|
||||
$result[$line.Substring(0, $separator)] = $line.Substring($separator + 1)
|
||||
}
|
||||
|
||||
foreach ($requiredName in @(
|
||||
"active",
|
||||
"schema",
|
||||
"implementation-sha256",
|
||||
"dependency-fingerprint",
|
||||
"consumer-fingerprint",
|
||||
"installed-root",
|
||||
"buildtrees-root",
|
||||
"packages-root",
|
||||
"target-triplet",
|
||||
"host-triplet"
|
||||
)) {
|
||||
if (-not $result.Contains($requiredName) -or [string]::IsNullOrWhiteSpace($result[$requiredName])) {
|
||||
throw "The shared-cache resolver omitted '$requiredName'."
|
||||
}
|
||||
}
|
||||
|
||||
return $result
|
||||
}
|
||||
|
||||
function ConvertTo-MSBuildOptionString {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[Collections.IDictionary] $Contract,
|
||||
[Parameter(Mandatory = $true)]
|
||||
[pscustomobject] $Properties
|
||||
)
|
||||
|
||||
$options = [Collections.Generic.List[string]]::new()
|
||||
if (-not [string]::IsNullOrWhiteSpace($Properties.CanaryVcpkgFeatureFlags)) {
|
||||
$featureFlags = $Properties.CanaryVcpkgFeatureFlags.Replace(";", ",")
|
||||
$options.Add("--feature-flags=$featureFlags")
|
||||
}
|
||||
foreach ($feature in @($Properties.CanaryVcpkgManifestFeatures -split ";" | Where-Object { $_ })) {
|
||||
$options.Add("--x-feature=$feature")
|
||||
}
|
||||
if ($Properties.CanaryVcpkgManifestNoDefaultFeatures -match "^(1|ON|TRUE|YES)$") {
|
||||
$options.Add("--x-no-default-features")
|
||||
}
|
||||
foreach ($overlayPort in @($Properties.CanaryVcpkgOverlayPorts -split ";" | Where-Object { $_ })) {
|
||||
$options.Add("`"--overlay-ports=$overlayPort`"")
|
||||
}
|
||||
foreach ($overlayTriplet in @($Properties.CanaryVcpkgOverlayTriplets -split ";" | Where-Object { $_ })) {
|
||||
$options.Add("`"--overlay-triplets=$overlayTriplet`"")
|
||||
}
|
||||
foreach ($installOption in @($Properties.CanaryVcpkgInstallOptions -split ";" | Where-Object { $_ })) {
|
||||
$options.Add($installOption)
|
||||
}
|
||||
$options.Add("`"--x-buildtrees-root=$($Contract['buildtrees-root'])`"")
|
||||
$options.Add("`"--x-packages-root=$($Contract['packages-root'])`"")
|
||||
|
||||
return $options -join " "
|
||||
}
|
||||
|
||||
function Invoke-ContractResolver {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string] $BuildConfiguration,
|
||||
[Parameter(Mandatory = $true)]
|
||||
[pscustomobject] $Properties,
|
||||
[Parameter(Mandatory = $true)]
|
||||
[bool] $Prepare
|
||||
)
|
||||
|
||||
if ($Properties.VcpkgEnableManifest -notmatch "^(1|ON|TRUE|YES)$") {
|
||||
throw "The Solution configuration $BuildConfiguration|$Platform does not enable vcpkg manifest mode."
|
||||
}
|
||||
foreach ($requiredProperty in @("VcpkgTriplet", "VcpkgHostTriplet", "PlatformToolset")) {
|
||||
if ([string]::IsNullOrWhiteSpace($Properties.$requiredProperty)) {
|
||||
throw "The Solution configuration $BuildConfiguration|$Platform does not define $requiredProperty."
|
||||
}
|
||||
}
|
||||
|
||||
$manifestRoot = Get-FullPath -Path $Properties.VcpkgManifestRoot -BasePath $repositoryRoot
|
||||
if ($manifestRoot -ne $repositoryRoot) {
|
||||
throw "The evaluated vcpkg manifest root does not match this repository: $manifestRoot"
|
||||
}
|
||||
|
||||
$resultPath = Join-Path ([IO.Path]::GetTempPath()) ("canary-shared-contract-{0}.txt" -f [guid]::NewGuid())
|
||||
$fingerprintInputPath = $null
|
||||
try {
|
||||
$resolverArguments = [Collections.Generic.List[string]]::new()
|
||||
if ($Prepare) {
|
||||
$resolverArguments.Add("-DCANARY_SHARED_CACHE_PREPARE_ONLY=ON")
|
||||
} else {
|
||||
$resolverArguments.Add("-DCANARY_SHARED_CACHE_READ_ONLY=ON")
|
||||
}
|
||||
foreach ($argument in @(
|
||||
"-DCANARY_SHARED_CACHE_RESULT_FILE=$resultPath",
|
||||
"-DCANARY_SHARED_CACHE_CONSUMER=msbuild",
|
||||
"-DCANARY_SHARED_CACHE_CONSUMER_TOOL=$resolvedMSBuildPath",
|
||||
"-DCANARY_SHARED_CACHE_CONSUMER_CONFIGURATION=$BuildConfiguration",
|
||||
"-DCANARY_SHARED_CACHE_CONSUMER_PLATFORM=$Platform",
|
||||
"-DCANARY_SHARED_CACHE_CONSUMER_LINK_CONFIGURATION=$($Properties.VcpkgConfiguration)",
|
||||
"-DCANARY_SHARED_CACHE_CONSUMER_TOOLSET=$($Properties.PlatformToolset)",
|
||||
"-DCANARY_SHARED_CACHE_CONSUMER_SDK=$($Properties.WindowsTargetPlatformVersion)",
|
||||
"-DCMAKE_TOOLCHAIN_FILE=$resolvedVcpkgRoot/scripts/buildsystems/vcpkg.cmake",
|
||||
"-DCMAKE_C_COMPILER=$compilerPath",
|
||||
"-DCMAKE_CXX_COMPILER=$compilerPath",
|
||||
"-DVCPKG_MANIFEST_DIR=$manifestRoot",
|
||||
"-DVCPKG_TARGET_TRIPLET=$($Properties.VcpkgTriplet)",
|
||||
"-DVCPKG_HOST_TRIPLET=$($Properties.VcpkgHostTriplet)",
|
||||
"-DVCPKG_PLATFORM_TOOLSET=$($Properties.PlatformToolset)",
|
||||
"-DVCPKG_FEATURE_FLAGS=$($Properties.CanaryVcpkgFeatureFlags)",
|
||||
"-DVCPKG_MANIFEST_FEATURES=$($Properties.CanaryVcpkgManifestFeatures)",
|
||||
"-DVCPKG_OVERLAY_PORTS=$($Properties.CanaryVcpkgOverlayPorts)",
|
||||
"-DVCPKG_OVERLAY_TRIPLETS=$($Properties.CanaryVcpkgOverlayTriplets)",
|
||||
"-DVCPKG_INSTALL_OPTIONS=$($Properties.CanaryVcpkgInstallOptions)"
|
||||
)) {
|
||||
$resolverArguments.Add($argument)
|
||||
}
|
||||
if (-not [string]::IsNullOrWhiteSpace($FingerprintInputDirectory)) {
|
||||
$resolvedFingerprintInputDirectory = Get-FullPath -Path $FingerprintInputDirectory -BasePath $repositoryRoot
|
||||
[IO.Directory]::CreateDirectory($resolvedFingerprintInputDirectory) | Out-Null
|
||||
$fingerprintInputPath = Join-Path $resolvedFingerprintInputDirectory ("{0}-{1}.txt" -f $BuildConfiguration.ToLowerInvariant(), $Platform.ToLowerInvariant())
|
||||
$resolverArguments.Add("-DCANARY_SHARED_CACHE_FINGERPRINT_INPUT_FILE=$fingerprintInputPath")
|
||||
}
|
||||
if (-not [string]::IsNullOrWhiteSpace($Properties.CanaryVcpkgBuildType)) {
|
||||
$resolverArguments.Add("-DVCPKG_BUILD_TYPE=$($Properties.CanaryVcpkgBuildType)")
|
||||
}
|
||||
if (-not [string]::IsNullOrWhiteSpace($Properties.CanaryVcpkgManifestNoDefaultFeatures)) {
|
||||
$resolverArguments.Add("-DVCPKG_MANIFEST_NO_DEFAULT_FEATURES=$($Properties.CanaryVcpkgManifestNoDefaultFeatures)")
|
||||
}
|
||||
$resolverArguments.Add("-P")
|
||||
$resolverArguments.Add($resolverModule)
|
||||
|
||||
Push-Location $repositoryRoot
|
||||
try {
|
||||
$resolverOutput = & $resolvedCMakePath @resolverArguments 2>&1
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Shared-cache contract resolution failed for $BuildConfiguration|$Platform.`n$($resolverOutput -join [Environment]::NewLine)"
|
||||
}
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
if (-not (Test-Path -LiteralPath $resultPath -PathType Leaf)) {
|
||||
throw "The shared-cache resolver did not produce a result for $BuildConfiguration|$Platform.`n$($resolverOutput -join [Environment]::NewLine)"
|
||||
}
|
||||
return Convert-ContractResult -Path $resultPath
|
||||
} finally {
|
||||
if ([IO.File]::Exists($resultPath)) {
|
||||
[IO.File]::Delete($resultPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$repositoryRoot = Get-FullPath -Path (Join-Path $PSScriptRoot "..")
|
||||
$resolverModule = Join-Path $repositoryRoot "cmake\SharedBuildCache.cmake"
|
||||
if (-not (Test-Path -LiteralPath $resolverModule -PathType Leaf)) {
|
||||
throw "Shared-cache resolver was not found: $resolverModule"
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($ProjectFile)) {
|
||||
foreach ($relativeProjectPath in @(
|
||||
"vcproj\canary.vcxproj",
|
||||
"vc18\otclient.vcxproj",
|
||||
"vc17\otclient.vcxproj"
|
||||
)) {
|
||||
$projectCandidate = Join-Path $repositoryRoot $relativeProjectPath
|
||||
if (Test-Path -LiteralPath $projectCandidate -PathType Leaf) {
|
||||
$ProjectFile = $projectCandidate
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($ProjectFile)) {
|
||||
throw "No maintained Visual Studio project was found. Pass -ProjectFile explicitly."
|
||||
}
|
||||
$ProjectFile = Get-FullPath -Path $ProjectFile -BasePath $repositoryRoot
|
||||
if (-not (Test-Path -LiteralPath $ProjectFile -PathType Leaf)) {
|
||||
throw "Visual Studio project was not found: $ProjectFile"
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($OutputProps)) {
|
||||
$OutputProps = Join-Path (Split-Path -Parent $ProjectFile) ".canary-shared-cache\SharedVcpkgCache.props"
|
||||
}
|
||||
$OutputProps = Get-FullPath -Path $OutputProps -BasePath $repositoryRoot
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($CacheRoot)) {
|
||||
$CacheRoot = Get-EnvironmentValue -Name "CANARY_SHARED_CACHE_ROOT"
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($CacheRoot)) {
|
||||
throw "CANARY_SHARED_CACHE_ROOT is not configured. Run tools/configure_shared_build_cache.ps1 first."
|
||||
}
|
||||
$CacheRoot = Get-FullPath -Path $CacheRoot
|
||||
Assert-LocalFixedVolume -Path $CacheRoot -Description "The shared cache"
|
||||
[Environment]::SetEnvironmentVariable("CANARY_SHARED_CACHE_ROOT", $CacheRoot, "Process")
|
||||
[Environment]::SetEnvironmentVariable("CANARY_SHARED_CACHE_LOCAL_FILESYSTEM_VERIFIED", "ON", "Process")
|
||||
[Environment]::SetEnvironmentVariable("CANARY_SHARED_CACHE_VERIFIED_ROOT", $CacheRoot, "Process")
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($VcpkgRoot)) {
|
||||
$VcpkgRoot = Get-EnvironmentValue -Name "VCPKG_ROOT"
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($VcpkgRoot)) {
|
||||
throw "VCPKG_ROOT is not configured."
|
||||
}
|
||||
$resolvedVcpkgRoot = Get-FullPath -Path $VcpkgRoot
|
||||
if (-not (Test-Path -LiteralPath (Join-Path $resolvedVcpkgRoot "vcpkg.exe") -PathType Leaf)) {
|
||||
throw "The active vcpkg executable was not found below: $resolvedVcpkgRoot"
|
||||
}
|
||||
[Environment]::SetEnvironmentVariable("VCPKG_ROOT", $resolvedVcpkgRoot, "Process")
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($VisualStudioPath)) {
|
||||
$VisualStudioPath = Get-EnvironmentValue -Name "CANARY_VCPKG_VISUAL_STUDIO_PATH"
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($VisualStudioPath)) {
|
||||
throw "CANARY_VCPKG_VISUAL_STUDIO_PATH is not configured. Run tools/configure_shared_build_cache.ps1 first."
|
||||
}
|
||||
$VisualStudioPath = Get-FullPath -Path $VisualStudioPath
|
||||
[Environment]::SetEnvironmentVariable("CANARY_VCPKG_VISUAL_STUDIO_PATH", $VisualStudioPath, "Process")
|
||||
Import-VisualStudioEnvironment -Root $VisualStudioPath -PreservedVcpkgRoot $resolvedVcpkgRoot
|
||||
|
||||
$resolvedCMakePath = Resolve-Executable -Candidate $CMakePath -Name "cmake.exe"
|
||||
if ([string]::IsNullOrWhiteSpace($resolvedCMakePath)) {
|
||||
$bundledCMake = Join-Path $VisualStudioPath "Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe"
|
||||
if (Test-Path -LiteralPath $bundledCMake -PathType Leaf) {
|
||||
$resolvedCMakePath = Get-FullPath -Path $bundledCMake
|
||||
}
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($resolvedCMakePath)) {
|
||||
throw "cmake.exe was not found on PATH or in the selected Visual Studio installation. Pass -CMakePath explicitly."
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($MSBuildPath)) {
|
||||
$MSBuildPath = Get-EnvironmentValue -Name "CANARY_SOLUTION_MSBUILD_PATH"
|
||||
}
|
||||
$resolvedMSBuildPath = Resolve-Executable -Candidate $MSBuildPath -Name "MSBuild.exe"
|
||||
if ([string]::IsNullOrWhiteSpace($resolvedMSBuildPath)) {
|
||||
$bundledMSBuild = Join-Path $VisualStudioPath "MSBuild\Current\Bin\amd64\MSBuild.exe"
|
||||
if (Test-Path -LiteralPath $bundledMSBuild -PathType Leaf) {
|
||||
$resolvedMSBuildPath = Get-FullPath -Path $bundledMSBuild
|
||||
}
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($resolvedMSBuildPath)) {
|
||||
throw "MSBuild.exe was not found on PATH or in the selected Visual Studio installation. Pass -MSBuildPath explicitly."
|
||||
}
|
||||
Assert-MSBuildPropertyQuerySupport -Executable $resolvedMSBuildPath
|
||||
$compilerCommand = Get-Command cl.exe -ErrorAction SilentlyContinue | Select-Object -First 1
|
||||
if ($null -eq $compilerCommand) {
|
||||
throw "cl.exe was not found after initializing the selected Visual Studio developer environment."
|
||||
}
|
||||
$compilerPath = $compilerCommand.Source
|
||||
|
||||
$Platform = ([string] $Platform).Trim()
|
||||
Assert-SafeMSBuildDimension -Value $Platform -Description "Solution platform"
|
||||
|
||||
[string[]] $configurations = if ($Configurations.Count -gt 0) {
|
||||
@($Configurations)
|
||||
} elseif ($Configuration -eq "All") {
|
||||
try {
|
||||
[xml] $projectConfigurationDocument = Get-Content -LiteralPath $ProjectFile -Raw
|
||||
} catch {
|
||||
throw "The Visual Studio project is malformed and its configurations cannot be discovered: $ProjectFile. $($_.Exception.Message)"
|
||||
}
|
||||
@(
|
||||
$projectConfigurationDocument.SelectNodes("//*[local-name()='ProjectConfiguration']") |
|
||||
ForEach-Object { [string] $_.Include } |
|
||||
Where-Object { $_.EndsWith("|$Platform", [StringComparison]::OrdinalIgnoreCase) } |
|
||||
ForEach-Object { ($_ -split '\|', 2)[0] } |
|
||||
Select-Object -Unique
|
||||
)
|
||||
} else {
|
||||
@($Configuration)
|
||||
}
|
||||
$configurations = @(
|
||||
$configurations |
|
||||
ForEach-Object { $_ -split '[,;]' } |
|
||||
ForEach-Object { $_.Trim() } |
|
||||
Where-Object { -not [string]::IsNullOrWhiteSpace($_) } |
|
||||
Select-Object -Unique
|
||||
)
|
||||
if ($configurations.Count -eq 0) {
|
||||
throw "The Visual Studio project declares no configurations for platform $Platform."
|
||||
}
|
||||
foreach ($configurationName in $configurations) {
|
||||
Assert-SafeMSBuildDimension -Value $configurationName -Description "Solution configuration"
|
||||
}
|
||||
|
||||
if ($AuditOnly) {
|
||||
if (-not (Test-Path -LiteralPath $OutputProps -PathType Leaf)) {
|
||||
Write-Output "Solution cache fallback is local; no generated shared-cache props exist."
|
||||
return
|
||||
}
|
||||
try {
|
||||
[xml] $existingProps = Get-Content -LiteralPath $OutputProps -Raw
|
||||
} catch {
|
||||
throw "Generated Solution cache props are malformed: $OutputProps. Regenerate the file and reload the project. $($_.Exception.Message)"
|
||||
}
|
||||
$activePropertyGroups = @(
|
||||
$existingProps.SelectNodes("/*[local-name()='Project']/*[local-name()='PropertyGroup']") |
|
||||
Where-Object { $_.CanarySharedVcpkgActive -eq "true" }
|
||||
)
|
||||
foreach ($expectedConfiguration in $configurations) {
|
||||
$matchingGroups = @(
|
||||
$activePropertyGroups |
|
||||
Where-Object { $_.CanarySharedVcpkgConfiguration -eq $expectedConfiguration }
|
||||
)
|
||||
if ($matchingGroups.Count -ne 1) {
|
||||
throw "Generated Solution cache props must contain exactly one current contract for $expectedConfiguration|$Platform. Regenerate the file and reload the project."
|
||||
}
|
||||
}
|
||||
foreach ($propertyGroup in $activePropertyGroups) {
|
||||
if ($propertyGroup.CanarySharedVcpkgActive -ne "true") {
|
||||
continue
|
||||
}
|
||||
$configurationName = [string] $propertyGroup.CanarySharedVcpkgConfiguration
|
||||
$properties = Get-MSBuildProperties -Executable $resolvedMSBuildPath -Project $ProjectFile -BuildConfiguration $configurationName -BuildPlatform $Platform
|
||||
$contract = Invoke-ContractResolver -BuildConfiguration $configurationName -Properties $properties -Prepare $false
|
||||
if (
|
||||
$contract["dependency-fingerprint"] -ne [string] $propertyGroup.CanarySharedVcpkgDependencyFingerprint -or
|
||||
$contract["consumer-fingerprint"] -ne [string] $propertyGroup.CanarySharedVcpkgConsumerFingerprint -or
|
||||
(Get-FullPath -Path $contract["installed-root"]) -ne (Get-FullPath -Path ([string] $propertyGroup.VcpkgInstalledDir))
|
||||
) {
|
||||
throw "Generated Solution cache props are stale for $configurationName|$Platform. Run this script without -AuditOnly and reload the project."
|
||||
}
|
||||
}
|
||||
Write-Output "Solution cache audit complete: all generated contracts are current."
|
||||
return
|
||||
}
|
||||
|
||||
if ($ValidateOnly) {
|
||||
foreach ($requiredExpected in @(
|
||||
@{ Name = "ExpectedDependencyFingerprint"; Value = $ExpectedDependencyFingerprint },
|
||||
@{ Name = "ExpectedConsumerFingerprint"; Value = $ExpectedConsumerFingerprint },
|
||||
@{ Name = "ExpectedInstalledRoot"; Value = $ExpectedInstalledRoot }
|
||||
)) {
|
||||
if ([string]::IsNullOrWhiteSpace($requiredExpected.Value)) {
|
||||
throw "$($requiredExpected.Name) is required with -ValidateOnly."
|
||||
}
|
||||
}
|
||||
if (@($configurations).Count -ne 1) {
|
||||
throw "-ValidateOnly requires one concrete Configuration."
|
||||
}
|
||||
$properties = Get-MSBuildProperties -Executable $resolvedMSBuildPath -Project $ProjectFile -BuildConfiguration $configurations[0] -BuildPlatform $Platform
|
||||
$contract = Invoke-ContractResolver -BuildConfiguration $configurations[0] -Properties $properties -Prepare $true
|
||||
$actualValues = [ordered]@{
|
||||
ManifestRoot = [Environment]::GetEnvironmentVariable("CANARY_SHARED_VCPKG_ACTUAL_MANIFEST_ROOT", "Process")
|
||||
TargetTriplet = [Environment]::GetEnvironmentVariable("CANARY_SHARED_VCPKG_ACTUAL_TARGET_TRIPLET", "Process")
|
||||
HostTriplet = [Environment]::GetEnvironmentVariable("CANARY_SHARED_VCPKG_ACTUAL_HOST_TRIPLET", "Process")
|
||||
Configuration = [Environment]::GetEnvironmentVariable("CANARY_SHARED_VCPKG_ACTUAL_CONFIGURATION", "Process")
|
||||
Toolset = [Environment]::GetEnvironmentVariable("CANARY_SHARED_VCPKG_ACTUAL_TOOLSET", "Process")
|
||||
SDK = [Environment]::GetEnvironmentVariable("CANARY_SHARED_VCPKG_ACTUAL_SDK", "Process")
|
||||
InstallOptions = [Environment]::GetEnvironmentVariable("CANARY_SHARED_VCPKG_ACTUAL_INSTALL_OPTIONS", "Process")
|
||||
}
|
||||
foreach ($actualValue in $actualValues.GetEnumerator()) {
|
||||
if ([string]::IsNullOrWhiteSpace($actualValue.Value)) {
|
||||
throw "The evaluated MSBuild value '$($actualValue.Key)' was not supplied to the canonical validator."
|
||||
}
|
||||
}
|
||||
if ((Get-FullPath -Path $actualValues.ManifestRoot) -ne (Get-FullPath -Path $properties.VcpkgManifestRoot -BasePath $repositoryRoot)) {
|
||||
throw "The evaluated vcpkg manifest root differs from the canonical Solution contract."
|
||||
}
|
||||
$canonicalValues = [ordered]@{
|
||||
TargetTriplet = [string] $contract["target-triplet"]
|
||||
HostTriplet = [string] $contract["host-triplet"]
|
||||
Configuration = [string] $properties.VcpkgConfiguration
|
||||
Toolset = [string] $properties.PlatformToolset
|
||||
SDK = [string] $properties.WindowsTargetPlatformVersion
|
||||
InstallOptions = ConvertTo-MSBuildOptionString -Contract $contract -Properties $properties
|
||||
}
|
||||
foreach ($canonicalValue in $canonicalValues.GetEnumerator()) {
|
||||
if ([string] $actualValues[$canonicalValue.Key] -cne [string] $canonicalValue.Value) {
|
||||
throw "The evaluated MSBuild value '$($canonicalValue.Key)' differs from the canonical Solution contract."
|
||||
}
|
||||
}
|
||||
if ($contract["dependency-fingerprint"] -ne $ExpectedDependencyFingerprint) {
|
||||
throw "The Solution dependency fingerprint changed. Regenerate SharedVcpkgCache.props and reload the project."
|
||||
}
|
||||
if ($contract["consumer-fingerprint"] -ne $ExpectedConsumerFingerprint) {
|
||||
throw "The Solution consumer fingerprint changed. Regenerate SharedVcpkgCache.props and reload the project."
|
||||
}
|
||||
if ((Get-FullPath -Path $contract["installed-root"]) -ne (Get-FullPath -Path $ExpectedInstalledRoot)) {
|
||||
throw "The Solution installed root does not match its validated fingerprint."
|
||||
}
|
||||
Write-Output "Validated shared Solution dependency contract $($contract['dependency-fingerprint'])."
|
||||
return
|
||||
}
|
||||
|
||||
$resolvedContracts = [Collections.Generic.List[object]]::new()
|
||||
foreach ($buildConfiguration in $configurations) {
|
||||
$properties = Get-MSBuildProperties -Executable $resolvedMSBuildPath -Project $ProjectFile -BuildConfiguration $buildConfiguration -BuildPlatform $Platform
|
||||
$contract = Invoke-ContractResolver -BuildConfiguration $buildConfiguration -Properties $properties -Prepare (-not $WhatIfPreference)
|
||||
$resolvedContracts.Add([pscustomobject]@{
|
||||
Configuration = $buildConfiguration
|
||||
Properties = $properties
|
||||
Contract = $contract
|
||||
Options = ConvertTo-MSBuildOptionString -Contract $contract -Properties $properties
|
||||
})
|
||||
}
|
||||
|
||||
$propertyGroups = foreach ($entry in $resolvedContracts) {
|
||||
$condition = "'`$(Configuration)|`$(Platform)' == '$($entry.Configuration)|$Platform'"
|
||||
$escapedCondition = [Security.SecurityElement]::Escape($condition)
|
||||
$values = [ordered]@{
|
||||
CanarySharedVcpkgActive = "true"
|
||||
CanarySharedCacheRoot = $CacheRoot
|
||||
CanarySharedVcpkgSchema = $entry.Contract["schema"]
|
||||
CanarySharedVcpkgConfiguration = $entry.Configuration
|
||||
CanarySharedVcpkgDependencyFingerprint = $entry.Contract["dependency-fingerprint"]
|
||||
CanarySharedVcpkgConsumerFingerprint = $entry.Contract["consumer-fingerprint"]
|
||||
CanarySharedVcpkgExpectedManifestRoot = $repositoryRoot
|
||||
CanarySharedVcpkgExpectedTargetTriplet = $entry.Contract["target-triplet"]
|
||||
CanarySharedVcpkgExpectedHostTriplet = $entry.Contract["host-triplet"]
|
||||
CanarySharedVcpkgExpectedConfiguration = $entry.Properties.VcpkgConfiguration
|
||||
CanarySharedVcpkgExpectedToolset = $entry.Properties.PlatformToolset
|
||||
CanarySharedVcpkgExpectedSDK = $entry.Properties.WindowsTargetPlatformVersion
|
||||
CanarySharedVcpkgExpectedInstallOptions = $entry.Options
|
||||
CanarySharedVcpkgBuildtreesRoot = $entry.Contract["buildtrees-root"]
|
||||
CanarySharedVcpkgPackagesRoot = $entry.Contract["packages-root"]
|
||||
CanaryVcpkgVisualStudioPath = $VisualStudioPath
|
||||
CanaryVcpkgDependencyCMakeDirectory = [IO.Path]::GetDirectoryName($resolvedCMakePath)
|
||||
VcpkgRoot = $resolvedVcpkgRoot
|
||||
VcpkgInstalledDir = $entry.Contract["installed-root"]
|
||||
VcpkgAdditionalInstallOptions = $entry.Options
|
||||
}
|
||||
$lines = foreach ($value in $values.GetEnumerator()) {
|
||||
$escapedValue = [Security.SecurityElement]::Escape([string] $value.Value)
|
||||
" <$($value.Key)>$escapedValue</$($value.Key)>"
|
||||
}
|
||||
" <PropertyGroup Label=`"CanarySharedVcpkgCache`" Condition=`"$escapedCondition`">`n$($lines -join "`n")`n </PropertyGroup>"
|
||||
}
|
||||
$propsContent = @"
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generated by tools/configure_shared_solution_cache.ps1. Do not edit. -->
|
||||
<Project>
|
||||
$($propertyGroups -join "`n")
|
||||
</Project>
|
||||
"@
|
||||
|
||||
if ($PSCmdlet.ShouldProcess($OutputProps, "write generated shared Solution cache props")) {
|
||||
$propsDirectory = Split-Path -Parent $OutputProps
|
||||
[void] (New-Item -ItemType Directory -Path $propsDirectory -Force)
|
||||
$temporaryProps = Join-Path $propsDirectory ("SharedVcpkgCache.{0}.tmp" -f [guid]::NewGuid())
|
||||
try {
|
||||
[IO.File]::WriteAllText($temporaryProps, $propsContent, [Text.UTF8Encoding]::new($false))
|
||||
[IO.File]::Move($temporaryProps, $OutputProps, $true)
|
||||
} finally {
|
||||
if ([IO.File]::Exists($temporaryProps)) {
|
||||
[IO.File]::Delete($temporaryProps)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$resolvedContracts | ForEach-Object {
|
||||
[pscustomobject]@{
|
||||
Configuration = "$($_.Configuration)|$Platform"
|
||||
Dependency = $_.Contract["dependency-fingerprint"]
|
||||
Consumer = $_.Contract["consumer-fingerprint"]
|
||||
Installed = $_.Contract["installed-root"]
|
||||
}
|
||||
} | Format-Table -AutoSize -Wrap | Out-String | Write-Output
|
||||
|
||||
if ($WhatIfPreference) {
|
||||
Write-Output "Preview only: no pool directories or generated props were changed."
|
||||
} else {
|
||||
Write-Output "Shared Solution cache props generated. Reload the Visual Studio project before building."
|
||||
}
|
||||
77
vc18/SharedVcpkgCache.targets
Normal file
77
vc18/SharedVcpkgCache.targets
Normal 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->'"--overlay-ports=%(Identity)"', ' ')</_CanaryVcpkgOverlayPortOptions>
|
||||
<_CanaryVcpkgOverlayTripletOptions>@(_CanaryVcpkgOverlayTriplet->'"--overlay-triplets=%(Identity)"', ' ')</_CanaryVcpkgOverlayTripletOptions>
|
||||
<_CanaryVcpkgInstallOptions>@(_CanaryVcpkgInstallOption, ' ')</_CanaryVcpkgInstallOptions>
|
||||
<VcpkgAdditionalInstallOptions>$(_CanaryVcpkgFeatureFlagOptions) $(_CanaryVcpkgManifestFeatureOptions) $(_CanaryVcpkgNoDefaultFeatureOptions) $(_CanaryVcpkgOverlayPortOptions) $(_CanaryVcpkgOverlayTripletOptions) $(_CanaryVcpkgInstallOptions) "--x-buildtrees-root=$(MSBuildProjectDirectory)\.vcpkg-buildtrees\$(Configuration)-$(Platform)" "--x-packages-root=$(MSBuildProjectDirectory)\.vcpkg-packages\$(Configuration)-$(Platform)"</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)"
|
||||
Prefix="true" />
|
||||
</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 "$(VcpkgManifestRoot)\tools\configure_shared_solution_cache.ps1" -ValidateOnly -Configuration "$(Configuration)" -Platform "$(Platform)" -ProjectFile "$(MSBuildProjectFullPath)" -CacheRoot "$(CanarySharedCacheRoot)" -VcpkgRoot "$(VcpkgRoot)" -VisualStudioPath "$(CanaryVcpkgVisualStudioPath)" -CMakePath "$(CanaryVcpkgDependencyCMakeDirectory)\cmake.exe" -MSBuildPath "$(MSBuildToolsPath)\MSBuild.exe" -ExpectedDependencyFingerprint "$(CanarySharedVcpkgDependencyFingerprint)" -ExpectedConsumerFingerprint "$(CanarySharedVcpkgConsumerFingerprint)" -ExpectedInstalledRoot "$(VcpkgInstalledDir)"" />
|
||||
</Target>
|
||||
</Project>
|
||||
|
|
@ -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" />
|
||||
|
|
@ -156,7 +162,10 @@
|
|||
<PropertyGroup Label="Vcpkg">
|
||||
<VcpkgEnableManifest>true</VcpkgEnableManifest>
|
||||
<VcpkgAutoLink>true</VcpkgAutoLink>
|
||||
<VcpkgAdditionalInstallOptions>--overlay-triplets="$(MSBuildProjectDirectory)\..\cmake\triplets" --binarysource=clear --binarysource=files,$(VcpkgRoot)\binary-cache,readwrite</VcpkgAdditionalInstallOptions>
|
||||
<CanaryVcpkgFeatureFlags>versions</CanaryVcpkgFeatureFlags>
|
||||
<CanaryVcpkgBuildType>release</CanaryVcpkgBuildType>
|
||||
<CanaryVcpkgOverlayTriplets>$(MSBuildProjectDirectory)\..\cmake\triplets</CanaryVcpkgOverlayTriplets>
|
||||
<CanaryVcpkgInstallOptions>--clean-packages-after-build;--clean-buildtrees-after-build</CanaryVcpkgInstallOptions>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<VcpkgHostTriplet>x64-windows</VcpkgHostTriplet>
|
||||
|
|
@ -168,6 +177,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>
|
||||
|
|
@ -749,32 +760,29 @@
|
|||
<Target Name="DisplayRunProtoCompileValue" BeforeTargets="ProtoCompile">
|
||||
<Message Text="RunProtoCompile value: $(RunProtoCompile)" Importance="high" />
|
||||
</Target>
|
||||
<PropertyGroup Condition="'$(RunProtoCompile)'=='true'">
|
||||
<ProtocPath>$(VcpkgInstalledDir)\$(VcpkgTriplet)\tools\protobuf\protoc.exe</ProtocPath>
|
||||
<ProtoPath>$(SourcePath)protobuf</ProtoPath>
|
||||
<PropertyGroup>
|
||||
<ProtocPath>$(VcpkgInstalledDir)\$(VcpkgHostTriplet)\tools\protobuf\protoc.exe</ProtocPath>
|
||||
<ProtoPath>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\..\src\protobuf'))</ProtoPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(RunProtoCompile)'=='false'">
|
||||
<ProtocPath>$(VcpkgInstalledDir)\$(VcpkgTriplet)\tools\protobuf\protoc.exe</ProtocPath>
|
||||
<ProtoPath>$(SourcePath)protobuf</ProtoPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ItemGroup Condition="'$(RunProtoCompile)'=='true'">
|
||||
<ProtoFiles Include="$(ProtoPath)\*.proto" />
|
||||
<ClCompile Include="@(ProtoFiles->'generated\%(Filename).pb.cc')">
|
||||
<IncludeInUnityFile>false</IncludeInUnityFile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClInclude Include="@(ProtoFiles->'generated\%(Filename).pb.h')" />
|
||||
</ItemGroup>
|
||||
<Target Name="ProtoCompile" BeforeTargets="PrepareForBuild" DependsOnTargets="VcpkgInstallManifestDependencies" Condition="'$(RunProtoCompile)'=='true'">
|
||||
<Exec Command=""$(ProtocPath)" --proto_path="$(ProtoPath)" --cpp_out="generated" "%(ProtoFiles.Identity)"" />
|
||||
<ItemGroup>
|
||||
<ClCompile Include="generated\%(ProtoFiles.Filename).pb.cc">
|
||||
<IncludeInUnityFile>false</IncludeInUnityFile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClInclude Include="generated\%(ProtoFiles.Filename).pb.h">
|
||||
<IncludeInUnityFile>false</IncludeInUnityFile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<Target Name="ProtoCompile"
|
||||
BeforeTargets="PrepareForBuild"
|
||||
DependsOnTargets="VcpkgInstallManifestDependencies"
|
||||
Condition="'$(RunProtoCompile)'=='true'"
|
||||
Inputs="@(ProtoFiles);$(ProtocPath)"
|
||||
Outputs="@(ProtoFiles->'$(MSBuildProjectDirectory)\generated\%(Filename).pb.cc');@(ProtoFiles->'$(MSBuildProjectDirectory)\generated\%(Filename).pb.h')">
|
||||
<Exec Command=""$(ProtocPath)" --proto_path="$(ProtoPath)" --cpp_out="generated" @(ProtoFiles->'"%(FullPath)"', ' ')" />
|
||||
</Target>
|
||||
<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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue