Skip to content

Bring Windows bindings to Linux feature parity #59

Bring Windows bindings to Linux feature parity

Bring Windows bindings to Linux feature parity #59

Workflow file for this run

name: 'Build Binary'
on:
push:
branches: ['main']
tags: ['*']
pull_request:
branches: ['*']
jobs:
generate-metadata:
name: 'Generate FFI metadata (x86_64-windows-msvc)'
runs-on: windows-2025
env:
ASTREIN_VERSION: '1.2.0'
ASTREIN_SHA256: 'd8a4984dca05175a6523530bef5756ef9bf87d0e4e6d58981bee3b9980544149'
outputs:
package_version: ${{ steps.version.outputs.PACKAGE_VERSION }}
is_valid_package_version: ${{ steps.check-tag.outputs.IS_VALID_PACKAGE_VERSION }}
steps:
- name: 'Checkout repository'
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 'Setup CMake'
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: '4.3.x'
- name: 'Install LLVM 22.1.8'
uses: KyleMayes/install-llvm-action@v2
with:
version: '22.1.8'
arch: x64
directory: ${{ runner.temp }}/llvm
force-url: 'https://github.com/llvm/llvm-project/releases/download/llvmorg-22.1.8/LLVM-22.1.8-win64.exe'
- name: 'Download ASTrein'
shell: pwsh
run: |
$archive = Join-Path $env:RUNNER_TEMP 'astrein-windows-x86_64.zip'
$destination = Join-Path $env:RUNNER_TEMP 'astrein-package'
Invoke-WebRequest `
-Uri "https://github.com/Katze719/ASTrein/releases/download/v$env:ASTREIN_VERSION/astrein-windows-x86_64.zip" `
-OutFile $archive
$actualHash = (Get-FileHash -Algorithm SHA256 $archive).Hash.ToLowerInvariant()
if ($actualHash -ne $env:ASTREIN_SHA256) {
throw "ASTrein checksum mismatch: expected $env:ASTREIN_SHA256, got $actualHash"
}
Expand-Archive -Path $archive -DestinationPath $destination
$astrein = Join-Path $destination 'astrein/bin/astrein.exe'
& $astrein --version
"ASTREIN_EXECUTABLE=$astrein" >> $env:GITHUB_ENV
- name: 'Configure metadata context'
shell: pwsh
run: |
cmake -S . -B build/ffi -G Ninja `
-DCMAKE_BUILD_TYPE=Release `
-DCMAKE_C_COMPILER=clang-cl `
-DCMAKE_CXX_COMPILER=clang-cl `
-DCPP_BINDINGS_WINDOWS_ENABLE_FFI_JSON_EXPORT=ON `
"-DCPP_BINDINGS_WINDOWS_ASTREIN_EXECUTABLE=$env:ASTREIN_EXECUTABLE" `
"-DCPP_BINDINGS_WINDOWS_FFI_JSON_OUTPUT=$env:GITHUB_WORKSPACE/dist/ffi/x86_64.ffi.json"
- name: 'Generate metadata'
run: |
cmake --build build/ffi --target cpp_bindings_windows_ffi_json
- name: 'Set package version'
id: version
shell: pwsh
run: |
$content = Get-Content -Raw build/ffi/env.bat
$match = [regex]::Match($content, 'PACKAGE_VERSION=(.+)')
$version = if ($match.Success) { $match.Groups[1].Value.Trim() } else { '0.0.0' }
"PACKAGE_VERSION=$version" >> $env:GITHUB_OUTPUT
- name: 'Check package version'
id: check-tag
shell: pwsh
env:
PACKAGE_VERSION: ${{ steps.version.outputs.PACKAGE_VERSION }}
run: |
if ($env:PACKAGE_VERSION -match '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(alpha|rc|beta|experimental)\.[1-9]\d*)?$') {
"IS_VALID_PACKAGE_VERSION=true" >> $env:GITHUB_OUTPUT
} else {
"IS_VALID_PACKAGE_VERSION=false" >> $env:GITHUB_OUTPUT
}
- name: 'Upload FFI metadata'
uses: actions/upload-artifact@v4
with:
if-no-files-found: error
name: cpp-bindings-windows-ffi
path: dist/ffi/x86_64.ffi.json
build-binary:
name: 'Build x86_64-windows-msvc'
runs-on: windows-2025
steps:
- name: 'Checkout repository'
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 'Setup CMake'
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: '4.3.x'
- name: 'Install LLVM 22.1.8'
uses: KyleMayes/install-llvm-action@v2
with:
version: '22.1.8'
arch: x64
directory: ${{ runner.temp }}/llvm
force-url: 'https://github.com/llvm/llvm-project/releases/download/llvmorg-22.1.8/LLVM-22.1.8-win64.exe'
- name: 'Configure release'
run: |
cmake --preset windows-clang-release `
-DCPP_BINDINGS_WINDOWS_STATIC_MSVC_RUNTIME=ON
- name: 'Build and test'
run: |
cmake --build --preset windows-clang-release `
--target cpp_bindings_windows cpp_bindings_windows_tests `
--parallel 4
ctest --test-dir build `
--output-on-failure `
--output-junit test-report.xml
- name: 'Stage and verify binary'
shell: pwsh
run: |
$dll = Get-ChildItem -Recurse -Path build -Filter cpp_bindings_windows.dll -File |
Select-Object -First 1
if (-not $dll) {
throw 'cpp_bindings_windows.dll not found under build/'
}
New-Item -ItemType Directory -Force -Path dist/x86_64-windows-msvc | Out-Null
Copy-Item -Force $dll.FullName dist/x86_64-windows-msvc/cpp_bindings_windows.dll
./scripts/verify_release_binary.ps1 `
dist/x86_64-windows-msvc/cpp_bindings_windows.dll `
x86_64-windows-msvc
- name: 'Upload test report'
if: always()
uses: actions/upload-artifact@v4
with:
if-no-files-found: warn
name: test-report-x86_64-windows-msvc
path: build/test-report.xml
- name: 'Upload binary'
uses: actions/upload-artifact@v4
with:
if-no-files-found: error
name: cpp-bindings-windows-x86_64-windows-msvc
path: dist/x86_64-windows-msvc/cpp_bindings_windows.dll
test-unit-cpp:
name: 'Run: Test Unit C++'
needs: ['build-binary']
uses: './.github/workflows/test_unit_cpp.yml'
with:
artifact-name: cpp-bindings-windows-x86_64-windows-msvc
permissions:
contents: read
checks: write
create-release:
name: 'Create GitHub release'
needs: ['generate-metadata', 'build-binary', 'test-unit-cpp']
if: github.ref_type == 'tag' && needs.generate-metadata.outputs.is_valid_package_version == 'true'
runs-on: windows-2025
permissions:
contents: write
steps:
- name: 'Download binary'
uses: actions/download-artifact@v4
with:
name: cpp-bindings-windows-x86_64-windows-msvc
path: release/binary
- name: 'Download FFI metadata'
uses: actions/download-artifact@v4
with:
name: cpp-bindings-windows-ffi
path: release/ffi
- name: 'Name release assets'
shell: pwsh
run: |
Move-Item release/binary/cpp_bindings_windows.dll `
release/cpp_bindings_windows-x86_64-windows-msvc.dll
Move-Item release/ffi/x86_64.ffi.json `
release/cpp_bindings_windows-x86_64-windows-msvc.ffi.json
- name: 'Create GitHub release'
uses: softprops/action-gh-release@v2
with:
name: 'v${{ needs.generate-metadata.outputs.package_version }}'
tag_name: ${{ github.ref_name }}
generate_release_notes: true
files: |
release/cpp_bindings_windows-x86_64-windows-msvc.dll
release/cpp_bindings_windows-x86_64-windows-msvc.ffi.json
publish-jsr:
name: 'Run: Publish JSR'
needs: ['generate-metadata', 'build-binary', 'test-unit-cpp']
uses: './.github/workflows/publish_jsr.yml'
with:
publish: ${{ needs.generate-metadata.outputs.is_valid_package_version == 'true' }}
version: ${{ needs.generate-metadata.outputs.package_version }}
artifact-name: cpp-bindings-windows-x86_64-windows-msvc
ffi-artifact-name: cpp-bindings-windows-ffi
permissions:
contents: read
id-token: write