-
Notifications
You must be signed in to change notification settings - Fork 0
309 lines (264 loc) · 9.34 KB
/
Copy pathbuild_binary.yml
File metadata and controls
309 lines (264 loc) · 9.34 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
name: 'Build Binary'
description: |
This workflow builds the binary files for Linux. The build binaries are stored as artifact
and may be reused by other workflows.
on:
push:
branches: ['main']
tags: ['*']
pull_request:
branches: ['*']
jobs:
setup-matrix:
name: 'Setup matrix'
runs-on: ubuntu-24.04
steps:
- id: setup-matrix
uses: loat-dev/generate-matrix@v1.0.0
with:
matrix: |
include:
- runner: ubuntu-24.04
target: x86_64-linux-gnu
arch: x86_64
image: quay.io/pypa/manylinux_2_28_x86_64@sha256:4dc41da7df20400310c80d162a2fe2d2c2f3d9734d8dec20f6b9843711618deb
- runner: ubuntu-24.04-arm
target: aarch64-linux-gnu
arch: aarch64
image: quay.io/pypa/manylinux_2_28_aarch64@sha256:29a6ceb78de5b00494e6e7456a72782a4cb54238de102e7491d15fe47789b4d1
outputs:
matrix: ${{ steps.setup-matrix.outputs.matrix }}
generate-target-metadata:
name: 'Generate target metadata (${{ matrix.target }})'
needs: ['setup-matrix']
runs-on: ${{ matrix.runner }}
env:
ASTREIN_VERSION: '3.0.0'
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }}
steps:
- name: 'Checkout repository'
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: 'Install native compiler'
run: |
sudo apt-get update
sudo apt-get install -y \
gcc-14 \
g++-14
- name: 'Setup ASTrein'
id: astrein
uses: Katze719/setup-astrein@v1
with:
version: ${{ env.ASTREIN_VERSION }}
- name: 'Setup CMake'
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: '3.31.x'
- name: 'Configure native metadata context'
run: |
cmake -S . \
-B "build/ffi/${{ matrix.arch }}" \
-G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=gcc-14 \
-DCMAKE_CXX_COMPILER=g++-14 \
-DCPP_BINDINGS_LINUX_ENABLE_FFI_JSON_EXPORT=ON \
-DCPP_BINDINGS_LINUX_ASTREIN_EXECUTABLE="${{ steps.astrein.outputs.path }}" \
-DCPP_BINDINGS_LINUX_FFI_JSON_OUTPUT="${GITHUB_WORKSPACE}/dist/ffi/${{ matrix.arch }}.ffi.json"
- name: 'Generate metadata'
run: |
cmake --build "build/ffi/${{ matrix.arch }}" \
--target cpp_bindings_linux_ffi_json
- name: 'Upload target-specific FFI metadata'
uses: actions/upload-artifact@v7
with:
if-no-files-found: error
name: cpp-bindings-linux-ffi-${{ matrix.target }}
path: dist/ffi/${{ matrix.arch }}.ffi.json
generate-metadata:
name: 'Generate metadata'
needs: ['generate-target-metadata']
runs-on: ubuntu-24.04
steps:
- name: 'Checkout repository'
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: 'Setup CMake'
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: '3.31.x'
- name: 'Install package-context compiler'
run: |
sudo apt-get update
sudo apt-get install -y \
gcc-14 \
g++-14
- name: 'Configure package context'
run: |
cmake -S . \
-B build/package \
-G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=gcc-14 \
-DCMAKE_CXX_COMPILER=g++-14
- name: 'Set package version'
id: version
run: |
. build/package/env.sh
echo "PACKAGE_VERSION=${PACKAGE_VERSION}" >> "${GITHUB_OUTPUT}"
- name: 'Check package version'
id: check-tag
env:
PACKAGE_VERSION: ${{ steps.version.outputs.PACKAGE_VERSION }}
run: |
if [[ "${PACKAGE_VERSION}" =~ ^(0|[1-9][[:digit:]]*)\.(0|[1-9][[:digit:]]*)\.(0|[1-9][[:digit:]]*)(-(alpha|rc|beta|experimental)\.[1-9][[:digit:]]*)?$ ]]; then
echo "Version \"${PACKAGE_VERSION}\" is a valid package version."
echo "IS_VALID_PACKAGE_VERSION=true" >> "${GITHUB_OUTPUT}"
else
echo "Version \"${PACKAGE_VERSION}\" is not a valid package version."
echo "IS_VALID_PACKAGE_VERSION=false" >> "${GITHUB_OUTPUT}"
fi
- name: 'Download target-specific FFI metadata'
uses: actions/download-artifact@v8
with:
pattern: cpp-bindings-linux-ffi-*
path: dist/ffi
merge-multiple: true
- name: 'Upload combined FFI metadata'
uses: actions/upload-artifact@v7
with:
if-no-files-found: error
name: cpp-bindings-linux-ffi
path: dist/ffi/*.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 binary (${{ matrix.target }})'
needs: ['setup-matrix']
runs-on: ${{ matrix.runner }}
container:
image: ${{ matrix.image }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }}
steps:
- name: 'Checkout repository'
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: 'Enable Git metadata in the build container'
run: |
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
git rev-parse --verify HEAD
- name: 'Configure portable release'
run: |
cmake -S . \
-B build \
-G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=gcc \
-DCMAKE_CXX_COMPILER=g++ \
-DCPP_BINDINGS_LINUX_PORTABLE_CPU_BASELINE=ON \
-DCPP_BINDINGS_LINUX_STATIC_CXX_RUNTIME=ON
- name: 'Build and test'
run: |
cmake --build build \
--target cpp_bindings_linux cpp_bindings_linux_tests \
--parallel 4
ctest --test-dir build \
--output-on-failure \
--output-junit test-report.xml
- name: 'Stage and verify binary'
run: |
mkdir -p "dist/${{ matrix.target }}"
cp -L build/libcpp_bindings_linux.so \
"dist/${{ matrix.target }}/libcpp_bindings_linux.so"
./scripts/verify_release_binary.sh \
"dist/${{ matrix.target }}/libcpp_bindings_linux.so" \
"${{ matrix.target }}"
- name: 'Upload test report'
if: always()
uses: actions/upload-artifact@v7
with:
if-no-files-found: warn
name: test-report-${{ matrix.target }}
path: build/test-report.xml
- name: 'Upload binary'
uses: actions/upload-artifact@v7
with:
if-no-files-found: error
name: libcpp_bindings_linux-${{ matrix.target }}
path: dist/${{ matrix.target }}/libcpp_bindings_linux.so
test-unit-cpp:
name: 'Run: Test Unit C++'
needs: ['build-binary']
uses: './.github/workflows/test_unit_cpp.yml'
permissions:
contents: read
checks: write
with:
artifact-name: libcpp_bindings_linux-x86_64-linux-gnu
create-release:
name: 'Create GitHub release'
needs:
- setup-matrix
- generate-metadata
- build-binary
- test-unit-cpp
if: github.ref_type == 'tag' && needs.generate-metadata.outputs.is_valid_package_version == 'true'
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
- name: 'Download binaries'
uses: actions/download-artifact@v8
with:
pattern: libcpp_bindings_linux-*
path: release/binaries
- name: 'Download FFI metadata'
uses: actions/download-artifact@v8
with:
name: cpp-bindings-linux-ffi
path: release/ffi
- name: 'Name release assets'
env:
MATRIX_JSON: ${{ needs.setup-matrix.outputs.matrix }}
run: |
mkdir -p release/assets
echo "${MATRIX_JSON}" | jq -c '.include[]' | while read -r entry; do
target=$(jq -r '.target' <<< "${entry}")
arch=$(jq -r '.arch' <<< "${entry}")
cp "release/binaries/libcpp_bindings_linux-${target}/libcpp_bindings_linux.so" \
"release/assets/libcpp_bindings_linux-${target}.so"
cp "release/ffi/${arch}.ffi.json" \
"release/assets/cpp_bindings_linux-${target}.ffi.json"
done
- 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/assets/*
publish-jsr:
name: 'Run: Publish JSR'
needs:
- 'setup-matrix'
- 'generate-metadata'
- 'build-binary'
- 'test-unit-cpp'
uses: './.github/workflows/publish_jsr.yml'
permissions:
contents: read
id-token: write
with:
publish: ${{ needs.generate-metadata.outputs.is_valid_package_version == 'true' }}
version: ${{ needs.generate-metadata.outputs.package_version }}
matrix: ${{ needs.setup-matrix.outputs.matrix }}
artifact-name-prefix: libcpp_bindings_linux
ffi-artifact-name: cpp-bindings-linux-ffi