Skip to content

Commit 963fce7

Browse files
committed
save
1 parent 8837fe8 commit 963fce7

File tree

3 files changed

+67
-136
lines changed

3 files changed

+67
-136
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# .github/workflows/build-windows.yml
2+
name: Windows Build
3+
4+
on: [push, pull_request]
5+
6+
jobs:
7+
build:
8+
runs-on: windows-2022
9+
steps:
10+
- uses: actions/checkout@v4
11+
12+
- name: Setup vcpkg
13+
run: |
14+
git clone https://github.com/microsoft/vcpkg.git C:\vcpkg
15+
C:\vcpkg\bootstrap-vcpkg.bat -disableMetrics
16+
17+
- name: Configure CMake
18+
run: cmake --preset msvc_debug
19+
env:
20+
VCPKG_ROOT: C:\vcpkg
21+
22+
- name: Build
23+
run: cmake --build --preset msvc_debug
24+
25+
- name: Test
26+
run: ctest --preset msvc_debug

docker/windows/Dockerfile

Lines changed: 41 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -3,163 +3,68 @@
33
# [run] docker run -it --rm bitbishop-windows
44
# NOTE: Before trying to build this dockerfile, ensure docker engine runs in windows container mode
55

6-
FROM mcr.microsoft.com/windows/servercore:ltsc2022
7-
8-
# Configure PowerShell as the default shell with strict error handling
9-
# - PowerShell is more powerful than cmd for scripting and package management
10-
# - $ErrorActionPreference = 'Stop' ensures the build fails on any error (critical for CI/CD)
11-
# - $ProgressPreference = 'SilentlyContinue' suppresses progress bars that can clutter build logs
12-
SHELL ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
13-
14-
# Install Chocolatey package manager
15-
# - Chocolatey is the standard package manager for Windows, similar to apt/yum on Linux
16-
# - Set-ExecutionPolicy Bypass allows script execution for this process only (security)
17-
# - SecurityProtocol 3072 = TLS 1.2, required for secure HTTPS downloads
18-
# - iex (Invoke-Expression) downloads and executes the Chocolatey install script
19-
RUN Set-ExecutionPolicy Bypass -Scope Process -Force; \
20-
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; \
21-
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
22-
23-
# Install core build dependencies via Chocolatey
24-
# - git: version control, required to clone vcpkg and project repositories
25-
# - cmake: cross-platform build system generator, industry standard for C++ projects
26-
# - ninja: fast build system, alternative to MSBuild, preferred for faster compilation
27-
# - zip: archive utility, often needed for packaging and handling compressed files
28-
# - llvm: compiler infrastructure including clang, useful for cross-platform builds
29-
# - -y: automatic yes to prompts (non-interactive installation for Docker builds)
30-
# NOTE: Installing each tool separately ensures proper PATH registration
31-
RUN choco install -y git
6+
# Use the official GitHub Actions Windows runner image
7+
# This image already has most development tools pre-installed:
8+
# - Chocolatey
9+
# - Git
10+
# - Visual Studio Build Tools
11+
# - Windows SDK
12+
# - PowerShell
13+
# - And many more tools commonly used in CI/CD
14+
FROM ghcr.io/actions/actions-runner:windows-2025
15+
16+
# Switch to PowerShell with strict error handling
17+
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
18+
19+
# Install additional tools not included in the base image
20+
# CMake, Ninja, and LLVM are needed for your C++ builds
3221
RUN choco install -y cmake --installargs 'ADD_CMAKE_TO_PATH=System'
3322
RUN choco install -y ninja
34-
RUN choco install -y zip
3523
RUN choco install -y llvm
3624

37-
# Update PATH environment variable to make installed tools accessible
38-
# CRITICAL: Must use [Environment]::SetEnvironmentVariable to persist changes to the system
39-
# This ensures PATH modifications survive container restarts and are available at runtime
40-
# - Machine scope: system-wide PATH that persists across sessions
41-
RUN [Environment]::SetEnvironmentVariable('PATH', \
42-
\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0;\" + \
43-
\"C:\\Program Files\\Git\\cmd;\" + \
44-
\"C:\\Program Files\\CMake\\bin;\" + \
45-
\"C:\\ProgramData\\chocolatey\\bin;\" + \
46-
\"C:\\Tools\\ninja;\" + \
47-
\"C:\\Program Files\\LLVM\\bin;\" + \
48-
$env:PATH, \
49-
[EnvironmentVariableTarget]::Machine)
50-
51-
# Refresh the current session's PATH to include newly installed tools
52-
# This is necessary for subsequent RUN commands in the Dockerfile
53-
RUN refreshenv; \
54-
$env:PATH = [System.Environment]::GetEnvironmentVariable('PATH','Machine')
25+
# Refresh environment to ensure newly installed tools are in PATH
26+
RUN refreshenv
5527

56-
# Install Visual Studio Build Tools 2022
57-
# This provides the MSVC compiler toolchain required for building native Windows C++ applications
58-
# - Invoke-WebRequest: downloads the VS Build Tools installer
59-
# - Start-Process with -Wait: ensures installation completes before proceeding
60-
# - --quiet --wait --norestart --nocache: silent, synchronous install without restart or cache
61-
#
62-
# Component selection rationale:
63-
# - Microsoft.VisualStudio.Workload.VCTools:
64-
# Core C++ build tools workload (compilers, libraries, build tools)
65-
# - Microsoft.VisualStudio.Component.Windows11SDK.22000:
66-
# Windows 11 SDK (22000 = version 10.0.22000.0), provides Windows API headers and libraries
67-
# Note: Compatible with Windows 10 projects as well, backward compatible
68-
# - Microsoft.VisualStudio.Component.VC.Tools.x86.x64:
69-
# MSVC v143 compiler toolset for x86 and x64 (both 32-bit and 64-bit compilation)
70-
# - --includeRecommended:
71-
# Adds recommended components for selected workloads (debuggers, profilers, etc.)
72-
#
73-
# Remove installer after completion to reduce image size
74-
RUN Invoke-WebRequest -Uri https://aka.ms/vs/17/release/vs_BuildTools.exe -OutFile vs_buildtools.exe; \
75-
Start-Process -FilePath .\vs_buildtools.exe -ArgumentList '--quiet', '--wait', '--norestart', '--nocache', \
76-
'--add', 'Microsoft.VisualStudio.Workload.VCTools', \
77-
'--add', 'Microsoft.VisualStudio.Component.Windows11SDK.22000', \
78-
'--add', 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64', \
79-
'--includeRecommended' \
80-
-NoNewWindow -Wait; \
81-
Remove-Item vs_buildtools.exe -Force
82-
83-
# Clone the vcpkg C++ package manager
84-
# - vcpkg is Microsoft's cross-platform C++ package manager
85-
# - Cloning from GitHub ensures we get the latest version with all port definitions
86-
# - C:\vcpkg: standard installation location, commonly used in documentation
28+
# Clone and bootstrap vcpkg
29+
# vcpkg is Microsoft's C++ package manager
8730
RUN git clone https://github.com/microsoft/vcpkg.git C:\vcpkg
8831

89-
# Bootstrap vcpkg - this step requires special shell handling
90-
# WHY SHELL SWITCH IS NECESSARY:
91-
# - bootstrap-vcpkg.bat is a Windows batch script that internally calls powershell.exe
92-
# - When executed from PowerShell context, it cannot find powershell.exe in its environment
93-
# - cmd.exe provides the native environment where batch scripts expect to run
94-
# - The batch script will successfully locate and execute powershell.exe from PATH
95-
#
96-
# - /S /C: cmd switches for silent execution and command execution
97-
# - -disableMetrics: opts out of vcpkg telemetry collection
32+
# Bootstrap vcpkg using cmd shell (required for batch script)
9833
SHELL ["cmd", "/S", "/C"]
9934
RUN C:\vcpkg\bootstrap-vcpkg.bat -disableMetrics
10035

101-
# Switch back to PowerShell for remaining operations
102-
# PowerShell is preferred for its superior scripting capabilities and error handling
103-
SHELL ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
36+
# Switch back to PowerShell
37+
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
10438

10539
# Configure vcpkg environment variables
106-
# - VCPKG_ROOT: tells tools where vcpkg is installed (standard vcpkg convention)
107-
# - VCPKG_FEATURE_FLAGS: enables advanced vcpkg features
108-
# * manifest: enables vcpkg.json manifest mode for declarative dependency management
109-
# * binarycaching: enables binary package caching to speed up builds
110-
# - VCPKG_BINARY_SOURCES: configures where binary cache is stored
111-
# * clear: clears any inherited cache configuration
112-
# * files: uses local filesystem cache (C:\vcpkg\binarycache)
113-
# NOTE: x-gha backend has been removed, using local file cache instead
11440
ENV VCPKG_ROOT="C:\\vcpkg"
11541
ENV VCPKG_FEATURE_FLAGS="manifest,binarycaching"
11642
ENV VCPKG_BINARY_SOURCES="clear;files,C:\\vcpkg\\binarycache,readwrite"
11743

11844
# Create binary cache directory
11945
RUN New-Item -ItemType Directory -Path C:\vcpkg\binarycache -Force
12046

121-
# Final PATH configuration with all build tools
122-
# Add VS Build Tools and vcpkg to the system PATH
123-
# This ensures all tools are available when the container starts
124-
# CRITICAL: Include MSVC compiler binaries for ninja/cmake to find cl.exe
125-
RUN $vsPath = (Get-ChildItem 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC' | Select-Object -Last 1).FullName; \
126-
[Environment]::SetEnvironmentVariable('PATH', \
127-
\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools;\" + \
128-
\"$vsPath\\bin\\Hostx64\\x64;\" + \
129-
\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\IDE\\CommonExtensions\\Microsoft\\CMake\\Ninja;\" + \
130-
\"C:\\vcpkg;\" + \
131-
[System.Environment]::GetEnvironmentVariable('PATH','Machine'), \
132-
[EnvironmentVariableTarget]::Machine)
133-
134-
# Set up MSVC environment variables required for compilation
135-
# These environment variables are normally set by vcvarsall.bat or VsDevCmd.bat
136-
# Setting them explicitly ensures cmake/ninja can find and use the MSVC toolchain
137-
RUN $vsPath = (Get-ChildItem 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC' | Select-Object -Last 1).FullName; \
138-
$sdkPath = 'C:\Program Files (x86)\Windows Kits\10'; \
139-
$sdkVersion = (Get-ChildItem \"$sdkPath\Include\" | Select-Object -Last 1).Name; \
140-
[Environment]::SetEnvironmentVariable('INCLUDE', \
141-
\"$vsPath\\include;\" + \
142-
\"$sdkPath\\Include\\$sdkVersion\\ucrt;\" + \
143-
\"$sdkPath\\Include\\$sdkVersion\\um;\" + \
144-
\"$sdkPath\\Include\\$sdkVersion\\shared\", \
145-
[EnvironmentVariableTarget]::Machine); \
146-
[Environment]::SetEnvironmentVariable('LIB', \
147-
\"$vsPath\\lib\\x64;\" + \
148-
\"$sdkPath\\Lib\\$sdkVersion\\ucrt\\x64;\" + \
149-
\"$sdkPath\\Lib\\$sdkVersion\\um\\x64\", \
150-
[EnvironmentVariableTarget]::Machine); \
151-
[Environment]::SetEnvironmentVariable('LIBPATH', \
152-
\"$vsPath\\lib\\x64;\" + \
153-
\"$sdkPath\\UnionMetadata\\$sdkVersion;\" + \
154-
\"$sdkPath\\References\\$sdkVersion\", \
47+
# Create custom vcpkg triplet that uses MSBuild instead of Ninja
48+
# This avoids rc.exe access violations in Windows Server Core containers
49+
RUN New-Item -ItemType Directory -Path C:\vcpkg\triplets\community -Force
50+
RUN $content = @(); \
51+
$content += 'set(VCPKG_TARGET_ARCHITECTURE x64)'; \
52+
$content += 'set(VCPKG_CRT_LINKAGE dynamic)'; \
53+
$content += 'set(VCPKG_LIBRARY_LINKAGE dynamic)'; \
54+
$content += 'set(VCPKG_CMAKE_GENERATOR \"Visual Studio 17 2022\")'; \
55+
$content += 'set(VCPKG_PLATFORM_TOOLSET v143)'; \
56+
$content | Out-File -FilePath C:\vcpkg\triplets\community\x64-windows-msbuild.cmake -Encoding ASCII
57+
58+
# Set the custom triplet as default
59+
ENV VCPKG_DEFAULT_TRIPLET="x64-windows-msbuild"
60+
61+
# Add vcpkg to PATH
62+
RUN [Environment]::SetEnvironmentVariable('PATH', \
63+
'C:\vcpkg;' + [System.Environment]::GetEnvironmentVariable('PATH','Machine'), \
15564
[EnvironmentVariableTarget]::Machine)
15665

157-
# Set working directory for when container starts
158-
# C:\workspace is a conventional location for build operations
66+
# Set working directory
15967
WORKDIR C:\\workspace
16068

161-
COPY . .
162-
163-
# Default command when container starts
164-
# PowerShell provides better interactive experience and scripting capabilities than cmd
69+
# Default command
16570
CMD ["powershell.exe"]

0 commit comments

Comments
 (0)