-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
393 lines (347 loc) · 15.4 KB
/
Copy pathmanylinux.yml
File metadata and controls
393 lines (347 loc) · 15.4 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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
name: manylinux
on:
pull_request:
types: [synchronize, opened]
push:
branches:
- main
env:
DEBIAN_FRONTEND: noninteractive
OPENCV_VERSION: 5.0.0
jobs:
# ---------------------------------------------------------------------------
# Build full libOpenCvSharpExtern.so inside manylinux_2_28.
# Static deps (FFmpeg via build_static_deps.sh cached in /opt/ffmpeg;
# image libs + Tesseract + Leptonica via vcpkg cached in vcpkg_installed/)
# The resulting .so depends only on glibc / libstdc++ system libraries.
# ---------------------------------------------------------------------------
build_full:
name: Linux (x64, full)
runs-on: ubuntu-24.04
container:
image: quay.io/pypa/manylinux_2_28_x86_64
options: --user root
steps:
- uses: actions/checkout@v7
with:
submodules: true
# -- System tools --------------------------------------------------------
- name: Install system tools
run: |
dnf install -y \
git \
zip \
unzip \
nasm \
yasm \
pkg-config \
ninja-build \
kernel-headers \
perl-IPC-Cmd \
perl-Time-Piece \
gtk3-devel
# -- vcpkg (image libs + Tesseract + Leptonica) --------------------------
- name: Bootstrap vcpkg
run: |
git clone --filter=blob:none https://github.com/microsoft/vcpkg.git /opt/vcpkg
/opt/vcpkg/bootstrap-vcpkg.sh -disableMetrics
- name: Restore vcpkg package cache
id: vcpkg-cache
uses: actions/cache/restore@v5
with:
path: ${{ github.workspace }}/vcpkg_installed
key: vcpkg-x64-linux-static-${{ hashFiles('vcpkg.json') }}-${{ hashFiles('cmake/triplets/x64-linux-static.cmake') }}
- name: Install packages via vcpkg
if: steps.vcpkg-cache.outputs.cache-hit != 'true'
run: |
/opt/vcpkg/vcpkg install \
--triplet x64-linux-static \
--overlay-triplets=${GITHUB_WORKSPACE}/cmake/triplets
- name: Save vcpkg package cache
if: steps.vcpkg-cache.outputs.cache-hit != 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/cache/save@v5
with:
path: ${{ github.workspace }}/vcpkg_installed
key: vcpkg-x64-linux-static-${{ hashFiles('vcpkg.json') }}-${{ hashFiles('cmake/triplets/x64-linux-static.cmake') }}
# -- FFmpeg cache --------------------------------------------------------
- name: Restore FFmpeg cache
id: ffmpeg-cache
uses: actions/cache/restore@v5
with:
path: /opt/ffmpeg
key: manylinux2_28-ffmpeg-${{ hashFiles('docker/manylinux/build_static_deps.sh') }}
- name: Build FFmpeg
if: steps.ffmpeg-cache.outputs.cache-hit != 'true'
run: bash docker/manylinux/build_static_deps.sh
- name: Save FFmpeg cache
if: steps.ffmpeg-cache.outputs.cache-hit != 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/cache/save@v5
with:
path: /opt/ffmpeg
key: manylinux2_28-ffmpeg-${{ hashFiles('docker/manylinux/build_static_deps.sh') }}
# -- OpenCV cache --------------------------------------------------------
- name: Restore OpenCV cache (full)
id: opencv-cache
uses: actions/cache/restore@v5
with:
path: ${{ github.workspace }}/opencv_artifacts
key: opencv-${{ env.OPENCV_VERSION }}-manylinux2_28-full-${{ hashFiles('vcpkg.json', 'cmake/opencv_build_options.cmake', 'docker/manylinux/build_static_deps.sh') }}
- name: Configure OpenCV (full)
if: steps.opencv-cache.outputs.cache-hit != 'true'
run: |
cmake \
-G Ninja \
-C cmake/opencv_build_options.cmake \
-S opencv \
-B opencv/build \
-D OPENCV_EXTRA_MODULES_PATH=${GITHUB_WORKSPACE}/opencv_contrib/modules \
-D CMAKE_INSTALL_PREFIX=${GITHUB_WORKSPACE}/opencv_artifacts \
-D CMAKE_TOOLCHAIN_FILE=/opt/vcpkg/scripts/buildsystems/vcpkg.cmake \
-D VCPKG_TARGET_TRIPLET=x64-linux-static \
-D VCPKG_INSTALLED_DIR=${GITHUB_WORKSPACE}/vcpkg_installed \
-D CMAKE_PREFIX_PATH=/opt/ffmpeg \
-D BUILD_JPEG=OFF \
-D BUILD_PNG=OFF \
-D BUILD_TIFF=OFF \
-D BUILD_WEBP=OFF \
-D BUILD_ZLIB=ON \
-D WITH_TBB=OFF \
-D WITH_OPENEXR=OFF \
-D WITH_JASPER=OFF \
-D WITH_OPENGL=OFF \
-D WITH_VA=OFF \
-D WITH_VA_INTEL=OFF \
2>&1 | tee /tmp/opencv-configure-full.log
- name: Verify OpenCV cmake features (full)
if: steps.opencv-cache.outputs.cache-hit != 'true'
run: |
log=/tmp/opencv-configure-full.log
fail=0
for feature in Tesseract FFMPEG JPEG PNG TIFF WEBP; do
val=$(grep -E "^--\s+${feature}:\s+" "$log" | tail -1 | sed -E "s/^.*${feature}:[[:space:]]+//")
if [[ -n "$val" ]] && [[ "$val" != NO* ]]; then
echo "OK: $feature = $val"
else
echo "MISSING or DISABLED: $feature"
grep -iE "${feature}" "$log" | tail -3 || true
fail=1
fi
done
[ "$fail" -eq 0 ]
- name: Build OpenCV (full)
if: steps.opencv-cache.outputs.cache-hit != 'true'
run: |
cmake --build opencv/build -j 3
cmake --install opencv/build
echo "=== opencv_artifacts layout ==="
find ${GITHUB_WORKSPACE}/opencv_artifacts -name 'OpenCVConfig.cmake' -o -name '*.pc' | head -20
du -sh ${GITHUB_WORKSPACE}/opencv_artifacts/*/
- name: Validate OpenCV install (full)
if: steps.opencv-cache.outputs.cache-hit != 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
config=$(find ${GITHUB_WORKSPACE}/opencv_artifacts -name 'OpenCVConfig.cmake' | head -1)
if [ -z "$config" ]; then
echo "ERROR: OpenCVConfig.cmake not found under opencv_artifacts - install is incomplete."
exit 1
fi
echo "Found: $config"
shell: bash
- name: Save OpenCV cache (full)
if: steps.opencv-cache.outputs.cache-hit != 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/cache/save@v5
with:
path: ${{ github.workspace }}/opencv_artifacts
key: opencv-${{ env.OPENCV_VERSION }}-manylinux2_28-full-${{ hashFiles('vcpkg.json', 'cmake/opencv_build_options.cmake', 'docker/manylinux/build_static_deps.sh') }}
# -- OpenCvSharpExtern ---------------------------------------------------
- name: Build OpenCvSharpExtern (full)
run: |
cmake \
-G Ninja \
-S src \
-B src/build \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_TOOLCHAIN_FILE=/opt/vcpkg/scripts/buildsystems/vcpkg.cmake \
-D VCPKG_TARGET_TRIPLET=x64-linux-static \
-D VCPKG_INSTALLED_DIR=${GITHUB_WORKSPACE}/vcpkg_installed \
-D OpenCV_DIR=${GITHUB_WORKSPACE}/opencv_artifacts/lib64/cmake/opencv4 \
-D CMAKE_PREFIX_PATH="${GITHUB_WORKSPACE}/opencv_artifacts;/opt/ffmpeg;${GITHUB_WORKSPACE}/vcpkg_installed/x64-linux-static" \
-D ZLIB_LIBRARY="${GITHUB_WORKSPACE}/vcpkg_installed/x64-linux-static/lib/libz.a" \
-D ZLIB_INCLUDE_DIR="${GITHUB_WORKSPACE}/vcpkg_installed/x64-linux-static/include" \
-D CMAKE_SHARED_LINKER_FLAGS="-L${GITHUB_WORKSPACE}/vcpkg_installed/x64-linux-static/lib"
cmake --build src/build -j
cp src/build/OpenCvSharpExtern/libOpenCvSharpExtern.so ${GITHUB_WORKSPACE}/libOpenCvSharpExtern.so
- uses: actions/upload-artifact@v7
with:
name: libOpenCvSharpExtern-full
path: libOpenCvSharpExtern.so
# ---------------------------------------------------------------------------
# Build slim libOpenCvSharpExtern.so inside manylinux_2_28.
# No external deps needed: OpenCV bundled 3rdparty provides static .a for
# jpeg/png/tiff/webp/zlib internally.
# ---------------------------------------------------------------------------
build_slim:
name: Linux (x64, slim)
runs-on: ubuntu-24.04
container:
image: quay.io/pypa/manylinux_2_28_x86_64
options: --user root
steps:
- uses: actions/checkout@v7
with:
submodules: true
# -- System tools --------------------------------------------------------
- name: Install system tools
run: dnf install -y ninja-build
- name: Restore OpenCV cache (slim)
id: opencv-cache
uses: actions/cache/restore@v5
with:
path: ${{ github.workspace }}/opencv_artifacts_slim
key: opencv-${{ env.OPENCV_VERSION }}-manylinux2_28-slim-${{ hashFiles('cmake/opencv_build_options_slim.cmake') }}
- name: Configure OpenCV (slim)
if: steps.opencv-cache.outputs.cache-hit != 'true'
run: |
cmake \
-G Ninja \
-C cmake/opencv_build_options_slim.cmake \
-S opencv \
-B opencv/build \
-D OPENCV_EXTRA_MODULES_PATH=${GITHUB_WORKSPACE}/opencv_contrib/modules \
-D CMAKE_INSTALL_PREFIX=${GITHUB_WORKSPACE}/opencv_artifacts_slim \
-D WITH_TBB=OFF \
-D BUILD_ZLIB=ON
- name: Build OpenCV (slim)
if: steps.opencv-cache.outputs.cache-hit != 'true'
run: |
cmake --build opencv/build -j 3
cmake --install opencv/build
echo "=== opencv_artifacts_slim layout ==="
find ${GITHUB_WORKSPACE}/opencv_artifacts_slim -name 'OpenCVConfig.cmake' -o -name '*.pc' | head -20
du -sh ${GITHUB_WORKSPACE}/opencv_artifacts_slim/*/
- name: Save OpenCV cache (slim)
if: steps.opencv-cache.outputs.cache-hit != 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
config=$(find ${GITHUB_WORKSPACE}/opencv_artifacts_slim -name 'OpenCVConfig.cmake' | head -1)
if [ -z "$config" ]; then
echo "ERROR: OpenCVConfig.cmake not found under opencv_artifacts_slim - install is incomplete."
exit 1
fi
echo "Found: $config"
shell: bash
- name: Save OpenCV cache (slim) - upload
if: steps.opencv-cache.outputs.cache-hit != 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/cache/save@v5
with:
path: ${{ github.workspace }}/opencv_artifacts_slim
key: opencv-${{ env.OPENCV_VERSION }}-manylinux2_28-slim-${{ hashFiles('cmake/opencv_build_options_slim.cmake') }}
- name: Build OpenCvSharpExtern (slim)
run: |
cmake \
-G Ninja \
-S src \
-B src/build-slim \
-D CMAKE_BUILD_TYPE=Release \
-D OpenCV_DIR=${GITHUB_WORKSPACE}/opencv_artifacts_slim/lib64/cmake/opencv5 \
-D CMAKE_PREFIX_PATH=${GITHUB_WORKSPACE}/opencv_artifacts_slim \
-D NO_CONTRIB=ON \
-D NO_VIDEOIO=ON \
-D NO_HIGHGUI=ON \
-D NO_DNN=ON \
-D NO_STITCHING=ON
cmake --build src/build-slim -j
cp src/build-slim/OpenCvSharpExtern/libOpenCvSharpExtern.so ${GITHUB_WORKSPACE}/libOpenCvSharpExtern-slim.so
- uses: actions/upload-artifact@v7
with:
name: libOpenCvSharpExtern-slim
path: libOpenCvSharpExtern-slim.so
# ---------------------------------------------------------------------------
# Integration test: run the manylinux-built .so on bare Ubuntu 24.04 (no container).
# This validates that a glibc 2.28-built binary works on a newer distro.
# ---------------------------------------------------------------------------
test:
name: Linux (test)
needs: [build_full, build_slim]
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v7
with:
submodules: false
- name: Download full artifact
uses: actions/download-artifact@v8
with:
name: libOpenCvSharpExtern-full
path: nuget/
- name: Download slim artifact
uses: actions/download-artifact@v8
with:
name: libOpenCvSharpExtern-slim
path: nuget-slim/
- name: Install .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'
- name: Test (full)
run: |
cd ${GITHUB_WORKSPACE}/test/OpenCvSharp.Tests
dotnet build -c Release -f net10.0
cp ${GITHUB_WORKSPACE}/nuget/libOpenCvSharpExtern.so bin/Release/net10.0/
cp ${GITHUB_WORKSPACE}/nuget/libOpenCvSharpExtern.so ./
sudo cp ${GITHUB_WORKSPACE}/nuget/libOpenCvSharpExtern.so /usr/lib/
LD_LIBRARY_PATH=. dotnet test OpenCvSharp.Tests.csproj -c Release -f net10.0 --runtime linux-x64 \
--logger "trx;LogFileName=test-results.trx" < /dev/null
- name: Smoke test (slim)
run: |
cd ${GITHUB_WORKSPACE}/nuget-slim/
mv libOpenCvSharpExtern-slim.so libOpenCvSharpExtern.so
echo -ne "#include <stdio.h>\nint core_Mat_sizeof(); int main(){ int i = core_Mat_sizeof(); printf(\"sizeof(Mat) = %d\", i); return 0; }" > test.c
gcc -I./ -L./ test.c -o test -lOpenCvSharpExtern
LD_LIBRARY_PATH=. ./test
- uses: actions/upload-artifact@v7
with:
name: test-results-manylinux
path: test/OpenCvSharp.Tests/bin/Release/net10.0/test-results.trx
# ---------------------------------------------------------------------------
# Create NuGet packages from the manylinux-built binaries.
# Only runs on push to main.
# ---------------------------------------------------------------------------
nuget:
name: Linux (nuget)
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v7
- name: Download full artifact
uses: actions/download-artifact@v8
with:
name: libOpenCvSharpExtern-full
path: /tmp/so-full/
- name: Download slim artifact
uses: actions/download-artifact@v8
with:
name: libOpenCvSharpExtern-slim
path: /tmp/so-slim/
- name: Install .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'
- name: Create NuGet packages
env:
BETA: "-beta"
run: |
yyyymmdd=$(date '+%Y%m%d')
version="${OPENCV_VERSION}.${yyyymmdd}${BETA}"
echo "Package version: $version"
# Full package
cp /tmp/so-full/libOpenCvSharpExtern.so nuget/libOpenCvSharpExtern.so
dotnet pack nuget/OpenCvSharp5.official.runtime.linux-x64.csproj \
-o ${GITHUB_WORKSPACE}/artifacts -p:Version=$version
# Slim package (overwrite .so in nuget/ with slim binary)
cp /tmp/so-slim/libOpenCvSharpExtern-slim.so nuget/libOpenCvSharpExtern.so
dotnet pack nuget/OpenCvSharp5.official.runtime.linux-x64.slim.csproj \
-o ${GITHUB_WORKSPACE}/artifacts -p:Version=$version
ls ${GITHUB_WORKSPACE}/artifacts
- uses: actions/upload-artifact@v7
with:
name: nuget-packages-manylinux
path: artifacts