Skip to content

Commit e410ac9

Browse files
committed
CI: Windows MSVC/clang-cl Test using Visual Studio 2022.
This commit introduces Continuous Integration for Windows with MSVC/clang-cl shipped in Visual Studio 2022. vcpkg is used to automatically build all dependencies from source, with the advantage of full automation, latest upstream version, perfect binary compatibility, and customizable build flags. However, the full source build takes a long time (like using Gentoo Portage or MacPorts), in this case, 2 hours. A vcpkg binary cache is used to speedup iterative development. GitHub Actions cache is immutable, we can't modify existing cache, so we use a last-recently logic: Before each run, the last-written cache with a given prefix is restored. After each run, a new cache with the same prefix and a different suffix is submitted to GitHub. It's GitHub's responsibility to delete old cache if 7 days have passed or after the total size exceeds 10 GiB. Signed-off-by: Yifeng Li <tomli@tomli.me>
1 parent 580b11b commit e410ac9

1 file changed

Lines changed: 127 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,3 +712,130 @@ jobs:
712712
echo "Unittest CSXCAD Python module execution in venv..."
713713
cd $GITHUB_WORKSPACE/CSXCAD/python/tests
714714
python3 -m unittest
715+
716+
Windows:
717+
runs-on: windows-latest
718+
needs: Dependencies
719+
720+
strategy:
721+
# Use "false" means a single failed build won't terminate other combinations
722+
# in the matrix. This wastes CPU time, but is an important debugging tool to
723+
# prevent a single broken platform from stopping the whole matrix.
724+
fail-fast: false
725+
726+
matrix:
727+
toolchain:
728+
# name: toonchain name (only a name for humans to read).
729+
# CC, CXX: C/C++ compiler, environment variables
730+
- name: "MSVC"
731+
CC: "cl"
732+
CXX: "cl"
733+
734+
- name: "clang-cl"
735+
CC: "clang-cl"
736+
CXX: "clang-cl"
737+
738+
env:
739+
VS_ROOT_DIR: "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/"
740+
CC: "${{ matrix.toolchain.CC }}"
741+
CXX: "${{ matrix.toolchain.CXX }}"
742+
CFLAGS: "/D_WIN32_WINNT=0x0601"
743+
CXXFLAGS: "/D_WIN32_WINNT=0x0601"
744+
745+
VCPKG_CACHE_PATH: "${{ github.workspace }}/vcpkg-cache/"
746+
VCPKG_BINARY_CACHE_PATH: "${{ github.workspace }}/vcpkg-cache/binary"
747+
VCPKG_BINARY_SOURCES: "clear;files,${{ github.workspace }}/vcpkg-cache/binary,readwrite"
748+
VCPKG_ASSET_CACHE_PATH: "${{ github.workspace }}/vcpkg-cache/asset"
749+
X_VCPKG_ASSET_SOURCES: "x-azurl,file://${{ github.workspace }}/vcpkg-cache/asset,readwrite"
750+
751+
# allow this job to create and modify vcpkg packages for binary cache
752+
permissions:
753+
packages: write
754+
755+
name: "Windows (${{ matrix.toolchain.name }}, latest)"
756+
757+
steps:
758+
# When checking out repos, I recommend running actions/checkout
759+
# as soon as possible before anything else, and in the reverse
760+
# order, from the project repo to its dependencies. This reduces
761+
# race conditions due to force pushes (they are harmless but
762+
# annoying).
763+
- name: Checkout CSXCAD.git
764+
uses: actions/checkout@v4
765+
with:
766+
path: CSXCAD
767+
# checkout must be deep, not shallow.
768+
# We need tags for "git describe", otherwise build fails.
769+
fetch-depth: 0
770+
771+
- name: ${{ needs.Dependencies.outputs.fparser_checkout_title }}
772+
uses: actions/checkout@v4
773+
with:
774+
repository: "${{ needs.Dependencies.outputs.fparser_repo }}"
775+
ref: "${{ needs.Dependencies.outputs.fparser_branch }}"
776+
path: fparser
777+
# checkout must be deep, not shallow.
778+
# We need tags for "git describe", otherwise build fails.
779+
fetch-depth: 0
780+
781+
# It doesn't really work, because MSVC itself doesn't support long path.
782+
# But for future-proofing (it does work for clang).
783+
- name: Enable long paths
784+
run: |
785+
New-ItemProperty -Path "HKLM:/SYSTEM/CurrentControlSet/Control/FileSystem" `
786+
-Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
787+
788+
- name: Create vcpkg cache directories
789+
run: |
790+
mkdir -p "$env:VCPKG_CACHE_PATH"
791+
mkdir -p "$env:VCPKG_BINARY_CACHE_PATH"
792+
mkdir -p "$env:VCPKG_ASSET_CACHE_PATH"
793+
794+
- name: Restore vcpkg cache
795+
uses: actions/cache/restore@v5
796+
with:
797+
path: ${{ env.VCPKG_CACHE_PATH }}
798+
# almost always nonexistent
799+
key: "Windows - ${{ matrix.toolchain.name }} - ${{ github.sha }}"
800+
# use GitHub's fallback feature to pick the latest cache with this prefix
801+
restore-keys: |
802+
Windows - ${{ matrix.toolchain.name }}
803+
804+
- name: Build and install fparser
805+
run: |
806+
& "$env:VS_ROOT_DIR/Common7/Tools/Launch-VsDevShell.ps1" -Arch amd64 -HostArch amd64
807+
808+
cd "$env:GITHUB_WORKSPACE/fparser"
809+
mkdir build && cd build
810+
cmake ../ -GNinja -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON `
811+
-DCMAKE_BUILD_TYPE=Release `
812+
-DCMAKE_INSTALL_PREFIX="$HOME/opt"
813+
814+
cmake --build ./ --parallel
815+
cmake --install ./ --parallel 8
816+
817+
- name: Build and install CSXCAD
818+
run: |
819+
& "$env:VS_ROOT_DIR/Common7/Tools/Launch-VsDevShell.ps1" -Arch amd64 -HostArch amd64
820+
821+
cd "$env:GITHUB_WORKSPACE/CSXCAD"
822+
mkdir build && cd build
823+
cmake ../ -GNinja `
824+
-DCMAKE_BUILD_TYPE=Release `
825+
-DCMAKE_INSTALL_PREFIX="$HOME/opt" `
826+
-DFPARSER_ROOT_DIR="$HOME/opt" `
827+
-DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" `
828+
-DVCPKG_HOST_TRIPLET="x64-windows-release" `
829+
-DVCPKG_TARGET_TRIPLET="x64-windows-release"
830+
831+
cmake --build ./ --parallel
832+
cmake --install ./ --parallel 8
833+
834+
- name: Save vcpkg cache
835+
if: always() # save even after a build failure.
836+
uses: actions/cache/save@v5
837+
with:
838+
path: ${{ env.VCPKG_CACHE_PATH }}
839+
# GitHub cache is immutable and can't be overwritten
840+
# save a new cache key every time
841+
key: Windows - ${{ matrix.toolchain.name }} - ${{ github.sha }}

0 commit comments

Comments
 (0)