Commit graph

2 commits

Author SHA1 Message Date
Eduardo Dantas
4a2de8de5f
fix(cache): canonicalize manifest line endings (#1802)
fix(cache): canonicalize vcpkg manifest line endings

Normalize manifest line endings when generating shared build-cache fingerprints so equivalent vcpkg configurations use the same dependency pool regardless of Git checkout settings.

Root cause:
- Equivalent Git content can be checked out using CRLF or LF depending on core.autocrlf and local Git configuration.
- The previous shared-cache resolver hashed raw manifest bytes.
- Two otherwise equivalent worktrees could therefore resolve to different dependency fingerprints and separate vcpkg pools.

Main changes:
- Normalize CRLF and LF when fingerprinting vcpkg.json.
- Normalize CRLF and LF when fingerprinting vcpkg-configuration.json.
- Keep registry, overlay, port, patch, and arbitrary payload trees byte-signatured because their contents may be line-ending-sensitive.
- Advance the shared-cache contract from schema v3 to schema v4.
- Retain recognition of schemas v1 through v3 for auditing and transient cleanup.
- Require an exact full-fingerprint metadata match before cleaning fingerprint-specific transient data.
- Keep shortened cache directory names backed by full SHA-256 identity metadata.
- Update shared-cache setup and cleanup tooling for the v4 layout.
- Update documentation with v4 fingerprinting behavior, migration rules, cleanup procedures, and cache paths.

Windows build updates:
- Move Windows CI to the Visual Studio 2026 hosted runner.
- Verify that Visual Studio 2026 provides the native C++ v145 toolset.
- Configure MSBuild discovery specifically for the Visual Studio 18.x prerelease range.
- Remove the previous Chocolatey-based Visual Studio toolset installation path.

Validation:
- Reproduced the Release x64 dependency contract in two worktrees with different manifest line endings.
- Verified both worktrees now resolve to the same schema v4 dependency fingerprint.
- Ran SharedBuildCache.cmake in CMake script mode.
- Verified the windows-release preset listing.
- Ran PowerShell parser checks.
- Ran JSON parsing checks.
- Ran documentation portability checks.
- Ran git diff --check.

This keeps shared vcpkg cache identity stable across CRLF and LF checkouts while preserving byte-sensitive hashing for dependency content where physical file representation can affect behavior.
2026-08-14 17:56:59 -03:00
Eduardo Dantas
44a980b07e
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.
2026-08-13 18:47:47 -03:00