Skip to content
Open
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
254 changes: 194 additions & 60 deletions .github/workflows/build_binary.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
name: 'Build Binary'
description: |
This workflow builds the binary files for Windows. The build binaries are stored as artifact
and may be reused by other workflows.

on:
push:
branches: [ 'main' ]
tags: [ '*' ]

branches: ['main']
tags: ['*']
pull_request:
branches: [ '*' ]
branches: ['*']

jobs:
build-binary:
name: 'Build binary'
runs-on: windows-latest
permissions:
contents: write
generate-metadata:
name: 'Generate FFI metadata (x86_64-windows-msvc)'
runs-on: windows-2025
env:
ASTREIN_VERSION: '1.2.1'
ASTREIN_SHA256: 'c90eb0e3a24dbdd8775289b30e60d0ee2dfa1c0395c8687aa9a2fabeada2d2df'
outputs:
package_version: ${{ steps.version.outputs.PACKAGE_VERSION }}
is_valid_package_version: ${{ steps.check-tag.outputs.IS_VALID_PACKAGE_VERSION }}

steps:
- name: 'Checkout repository'
Expand All @@ -27,89 +27,223 @@ jobs:
- name: 'Setup CMake'
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: '3.31.x'
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"
}

- name: 'Configure CMake'
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 --preset windows-vs-release
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: 'Build'
id: build
- name: 'Verify FFI metadata'
shell: pwsh
run: |
cmake --build --preset windows-vs-release --config Release --target cpp_bindings_windows
$metadataPath = 'dist/ffi/x86_64.ffi.json'
$metadata = Get-Content -Raw $metadataPath |
ConvertFrom-Json -ErrorAction Stop

if ($metadata.schema -ne 'astrein_ffi_api') {
throw "Unexpected FFI metadata schema: $($metadata.schema)"
}
if ($metadata.schemaVersion -ne 1) {
throw "Unexpected FFI metadata schema version: $($metadata.schemaVersion)"
}

- name: 'Set PACKAGE_VERSION from env.bat'
$functionCount = @($metadata.functions).Count
if ($functionCount -eq 0) {
throw 'FFI metadata contains no functions'
}
Write-Host "Verified FFI metadata with $functionCount functions"

- name: 'Set package version'
id: version
shell: pwsh
run: |
$content = Get-Content -Raw build/env.bat
echo "$content"
$m = [regex]::Match($content, 'PACKAGE_VERSION=(.+)')
$v = if ($m.Success) { $m.Groups[1].Value.Trim() } else { '0.0.0' }
echo "PACKAGE_VERSION=$v" >> $env:GITHUB_OUTPUT
$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: 'Copy DLL to stable path and upload artifact'
- name: 'Check package version'
id: check-tag
shell: pwsh
env:
PACKAGE_VERSION: ${{ steps.version.outputs.PACKAGE_VERSION }}
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 build/out | Out-Null
Copy-Item -Force $dll.FullName -Destination build/out/cpp_bindings_windows.dll
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 artifacts'
- name: 'Upload FFI metadata'
uses: actions/upload-artifact@v4
with:
if-no-files-found: error
name: cpp_bindings_windows
path: build/out/cpp_bindings_windows.dll
name: cpp-bindings-windows-ffi
path: dist/ffi/x86_64.ffi.json

- name: 'Check tag'
id: check-tag
shell: pwsh
env:
PACKAGE_VERSION: ${{ steps.version.outputs.PACKAGE_VERSION }}
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: |
$v = $env:PACKAGE_VERSION
if ($v -match '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(alpha|rc|beta|experimental)\.[1-9]\d*)?$') {
echo "IS_VALID_PACKAGE_VERSION=true" >> $env:GITHUB_OUTPUT
} else {
echo "IS_VALID_PACKAGE_VERSION=false" >> $env:GITHUB_OUTPUT
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/'
}

- name: 'Create GitHub Release'
if: github.ref_type == 'tag' && steps.check-tag.outputs.IS_VALID_PACKAGE_VERSION == 'true'
uses: softprops/action-gh-release@v2
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:
name: 'v${{ steps.version.outputs.PACKAGE_VERSION }}'
tag_name: ${{ github.ref_name }}
generate_release_notes: true
files: build/out/cpp_bindings_windows.dll
if-no-files-found: warn
name: test-report-x86_64-windows-msvc
path: build/test-report.xml

outputs:
package_version: ${{ steps.version.outputs.PACKAGE_VERSION }}
is_valid_package_version: ${{ steps.check-tag.outputs.IS_VALID_PACKAGE_VERSION }}
- 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' ]
needs: ['build-binary']
uses: './.github/workflows/test_unit_cpp.yml'
with:
artifact-name: cpp_bindings_windows

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: [ 'build-binary', 'test-unit-cpp' ]
needs: ['generate-metadata', 'build-binary', 'test-unit-cpp']
uses: './.github/workflows/publish_jsr.yml'
with:
publish: ${{ needs.build-binary.outputs.is_valid_package_version == 'true' }}
version: ${{ needs.build-binary.outputs.package_version }}
artifact-name: cpp_bindings_windows

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
14 changes: 11 additions & 3 deletions .github/workflows/deno_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ jobs:
- name: Setup CMake >= 3.30
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: "3.31.x"
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: Setup Deno
uses: denoland/setup-deno@v2
Expand All @@ -30,11 +38,11 @@ jobs:

- name: Configure CMake
run: |
cmake --preset windows-vs-release
cmake --preset windows-clang-release

- name: Build
run: |
cmake --build --preset windows-vs-release --config Release
cmake --build --preset windows-clang-release --target cpp_bindings_windows

- name: Run Deno integration tests
working-directory: integration_tests
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/publish_jsr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ on:
required: true
type: string

ffi-artifact-name:
description: 'Name of the FFI metadata artifact'
required: true
type: string

permissions:
contents: read
id-token: write
Expand All @@ -46,15 +51,23 @@ jobs:
name: ${{ inputs.artifact-name }}
path: artifacts

- name: 'Download FFI metadata'
uses: actions/download-artifact@v4
with:
name: ${{ inputs.ffi-artifact-name }}
path: artifacts/ffi

- name: 'Prepare files for JSR'
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path ./jsr/bin | Out-Null
Copy-Item -Force ./artifacts/cpp_bindings_windows.dll ./jsr/bin/x86_64.dll
Copy-Item -Force ./artifacts/ffi/x86_64.ffi.json ./jsr/bin/x86_64.ffi.json
Copy-Item -Force ./LICENSE ./jsr/LICENSE

./jsr/scripts/binary_to_json.ps1 `
artifacts/cpp_bindings_windows.dll `
jsr/bin/x86_64.json windows-x86_64
jsr/bin/x86_64.json x86_64-windows-msvc

./jsr/scripts/set_version.ps1 `
jsr/jsr.json `
Expand Down
Loading
Loading