-
Notifications
You must be signed in to change notification settings - Fork 0
241 lines (209 loc) · 7.89 KB
/
Copy pathbuild_binary.yml
File metadata and controls
241 lines (209 loc) · 7.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
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: ['*']
pull_request:
branches: ['*']
jobs:
generate-metadata:
name: 'Generate FFI metadata (x86_64-windows-msvc)'
runs-on: windows-2025
env:
ASTREIN_VERSION: '3.0.0'
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: 'Setup ASTrein'
id: astrein
uses: Katze719/setup-astrein@v1
with:
version: ${{ env.ASTREIN_VERSION }}
- 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=${{ steps.astrein.outputs.path }}" `
"-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: 'Verify FFI metadata'
shell: pwsh
run: |
$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 3) {
throw "Unexpected FFI metadata schema version: $($metadata.schemaVersion)"
}
$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/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
outputs:
package_version: ${{ steps.version.outputs.PACKAGE_VERSION }}
is_valid_package_version: ${{ steps.check-tag.outputs.IS_VALID_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: |
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