Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
# Pin clang-format so CI matches local: build.ps1 prefers a PATH
# clang-format at this version, otherwise an unpinned VS-bundled one drifts
# between machines. Keep this version in sync with $PINNED_CLANG_FORMAT in build.ps1.
- name: Install pinned clang-format
shell: pwsh
run: pip install "clang-format==20.1.8"
- name: clang-format check
shell: pwsh
run: .\build.ps1 check-format
Expand Down
30 changes: 26 additions & 4 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,28 @@ function Get-LlvmTool {
return Resolve-FirstPath $candidates ([System.IO.Path]::GetFileNameWithoutExtension($Exe))
}

# clang-format is version-pinned so CI and local agree. An unpinned, VS-bundled
# clang-format drifts between machines (it infers East vs West pointer alignment
# differently by version, among other things), which makes `check-format` pass
# locally yet fail in CI. CI installs this exact version with
# `pip install clang-format==<ver>` (see .github/workflows/ci.yml); locally we
# prefer a matching clang-format on PATH and fall back to the VS-bundled tool.
$PINNED_CLANG_FORMAT = '20.1.8'

function Get-ClangFormat {
# Pick the first clang-format on PATH that reports the pinned version (CI
# installs it via pip). Scan ALL PATH matches, not just the first, so a
# different-version or non-clang-format `clang-format` ahead on PATH (e.g. a
# Chromium depot_tools wrapper) can't shadow the pinned one. Probe quietly and
# fall back to the VS-bundled tool for local dev.
foreach ($cmd in @(Get-Command clang-format -All -ErrorAction SilentlyContinue)) {
$verLine = ''
try { $verLine = (& $cmd.Source --version 2>$null | Out-String) } catch {}
if ($verLine -match [regex]::Escape($PINNED_CLANG_FORMAT)) { return $cmd.Source }
}
return Get-LlvmTool 'clang-format.exe'
}

# --- Resolve MSBuild ---
$msbuildCandidates = @()
if ($vsInstall) {
Expand All @@ -107,9 +129,9 @@ function Get-SourceFiles {

switch ($mode) {
'format' {
$clangFormat = Get-LlvmTool 'clang-format.exe'
$clangFormat = Get-ClangFormat
if (-not $clangFormat) {
Write-Host 'clang-format not found. Install LLVM tools via Visual Studio or put clang-format.exe on PATH.' -ForegroundColor Red
Write-Host "clang-format not found. Install it with 'pip install clang-format==$PINNED_CLANG_FORMAT' or via Visual Studio LLVM tools." -ForegroundColor Red
exit 1
}
Write-Host 'Formatting source files...'
Expand All @@ -118,9 +140,9 @@ switch ($mode) {
exit 0
}
'check-format' {
$clangFormat = Get-LlvmTool 'clang-format.exe'
$clangFormat = Get-ClangFormat
if (-not $clangFormat) {
Write-Host 'clang-format not found. Install LLVM tools via Visual Studio or put clang-format.exe on PATH.' -ForegroundColor Red
Write-Host "clang-format not found. Install it with 'pip install clang-format==$PINNED_CLANG_FORMAT' or via Visual Studio LLVM tools." -ForegroundColor Red
exit 1
}
Write-Host 'Checking format...'
Expand Down
2 changes: 1 addition & 1 deletion src/framework/components/config/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
// un-parameterized IDE builds. d2bsng versions start at 2.x so scripts can tell
// it apart from legacy d2bs, which topped out at 1.6.x.
#ifndef D2BS_VERSION
#define D2BS_VERSION "2.0.0-dev"
#define D2BS_VERSION "2.0.0-dev"
#endif
Loading