-
Notifications
You must be signed in to change notification settings - Fork 18
261 lines (228 loc) · 8.77 KB
/
Copy pathopencvsharp.yml
File metadata and controls
261 lines (228 loc) · 8.77 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
name: Build-OpenCvSharp
on:
workflow_dispatch:
env:
OPENCVSHARP_VERSION: 4.13.0.20260602
jobs:
build:
name: Build
runs-on: ${{ matrix.runs-on }}
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
include:
- { os: win, arch: x64, runs-on: windows-2022 }
- { os: win, arch: x86, runs-on: windows-2022 }
- { os: win, arch: arm64, runs-on: windows-11-arm }
- { os: osx, arch: x64, runs-on: macos-15-intel }
- { os: osx, arch: arm64, runs-on: macos-15 }
- { os: rhel.8, arch: x64, runs-on: ubuntu-22.04, image: oraclelinux:8 }
- { os: rhel.8, arch: arm64, runs-on: ubuntu-22.04-arm, image: oraclelinux:8 }
- { os: alpine.3.22, arch: x64, runs-on: ubuntu-22.04, image: alpine:3.22 }
- { os: alpine.3.22, arch: arm64, runs-on: ubuntu-22.04-arm, image: alpine:3.22 }
- { os: android, arch: arm64, runs-on: ubuntu-22.04 }
- { os: android, arch: x64, runs-on: ubuntu-22.04 }
# Uncomment the following lines to enable additional platforms:
# - { os: ubuntu.24.04, arch: x64, runs-on: ubuntu-24.04 }
# - { os: ubuntu.24.04, arch: arm64, runs-on: ubuntu-24.04-arm }
# - { os: win11, arch: x64, runs-on: windows-2025 }
# - { os: osx.15, arch: arm64, runs-on: macos-15 }
# - { os: rhel.9, arch: x64, runs-on: ubuntu-22.04, image: oraclelinux:9 }
# - { os: rhel.9, arch: arm64, runs-on: ubuntu-22.04-arm, image: oraclelinux:9 }
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Download OpenCV Artifacts
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "Fetching latest run of opencv.yml on branch ${{ github.ref_name }}"
RUN_ID=$(gh run list -R ${{ github.repository }} --workflow=opencv.yml --branch=${{ github.ref_name }} --status=success --limit=1 --json databaseId | jq -r '.[0].databaseId')
echo "Latest opencv run ID: $RUN_ID"
echo "Downloading artifact 'opencv' from run ${RUN_ID}"
gh run download -R ${{ github.repository }} $RUN_ID --name opencv-${{ matrix.os }}-${{ matrix.arch }} --dir opencv
echo "::group::OpenCV Artifacts"
ls -lR opencv
echo "::endgroup::"
- name: Checkout OpenCvSharp
uses: actions/checkout@v6
with:
repository: shimat/opencvsharp
ref: ${{ env.OPENCVSHARP_VERSION }}
path: opencvsharp
- name: Apply Patches
run: |
cd opencvsharp
git apply --ignore-whitespace ../eng/opencvsharp.patch
- name: Pull Docker Image
if: matrix.image != ''
run: |
docker pull ${{ matrix.image }}
- name: Start Docker Container
if: matrix.image != ''
run: |
docker run -d --name builder -v "$PWD":${{ github.workspace }} -w ${{ github.workspace }} ${{ matrix.image }} tail -f /dev/null
- name: Initialize Docker Container
if: matrix.image != ''
run: |
if [[ "${{ matrix.os }}" == "rhel.8" ]]; then
script=$(
cat <<'EOS'
set -eux
dnf config-manager --set-enabled ol8_codeready_builder
EOS
)
elif [[ "${{ matrix.os }}" == "rhel.9" ]]; then
script=$(
cat <<'EOS'
set -eux
dnf config-manager --set-enabled ol9_codeready_builder
EOS
)
fi
echo "Executing script in Docker container: $script"
docker exec builder /bin/sh -c "$script"
- name: Install Dependencies in Docker Container
if: matrix.image != ''
run: |
if [[ "${{ matrix.os }}" =~ "rhel." ]]; then
script=$(
cat <<'EOS'
set -eux
yum install -y gcc cmake3 gcc-c++ make
EOS
)
elif [[ "${{ matrix.os }}" =~ ^alpine ]]; then
script=$(
cat <<'EOS'
set -eux
apk add --no-cache build-base cmake
EOS
)
fi
echo "Executing script in Docker container: $script"
docker exec builder /bin/sh -c "$script"
- name: Configure OpenCvSharp
run: |
script=$(
cat <<'EOS'
set -eux
set --
OpenCV_DIR="${{ github.workspace }}/opencv/lib/cmake/opencv4"
if [[ "${{ matrix.os }}" =~ ^win ]]; then
OpenCV_DIR="${{ github.workspace }}/opencv/${{ matrix.arch }}/vc17/staticlib"
if [[ "${{ matrix.arch }}" == "x86" ]]; then
set -- "$@" -A Win32
fi
elif [[ "${{ matrix.image }}" =~ ^oraclelinux ]]; then
OpenCV_DIR="${{ github.workspace }}/opencv/lib64/cmake/opencv4"
elif [[ "${{ matrix.os }}" =~ ^alpine ]]; then
set -- "$@" "-DCMAKE_SHARED_LINKER_FLAGS=-static-libstdc++ -static-libgcc"
elif [[ ${{ matrix.os }} == "android" ]]; then
OpenCV_DIR="${{ github.workspace }}/opencv/sdk/native/jni"
set -- "$@" \
"-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake" \
"-DANDROID_PLATFORM=android-24" \
"-DANDROID_STL=c++_static"
if [[ "${{ matrix.arch }}" == "arm64" ]]; then
set -- "$@" "-DANDROID_ABI=arm64-v8a"
elif [[ "${{ matrix.arch }}" == "x64" ]]; then
set -- "$@" "-DANDROID_ABI=x86_64"
fi
fi
cd opencvsharp && mkdir build && cd build
cmake \
-D CMAKE_INSTALL_PREFIX="${{ github.workspace }}/opencvsharp/build" \
-D CMAKE_POLICY_VERSION_MINIMUM=3.5 \
-D OpenCV_DIR="$OpenCV_DIR" \
"$@" \
../src
EOS
)
if [[ "${{ matrix.image }}" == "" ]]; then
bash -c "$script"
else
docker exec builder /bin/sh -c "$script"
fi
- name: Build OpenCvSharp
run: |
script=$(
cat <<'EOS'
set -eux
cd opencvsharp/build
if [[ "${{ matrix.os }}" =~ ^win ]]; then
cmake --build . --parallel --config Release
else
make -j$(nproc)
fi
EOS
)
if [[ "${{ matrix.image }}" == "" ]]; then
bash -c "$script"
else
docker exec builder /bin/sh -c "$script"
fi
- name: Strip OpenCvSharpExtern
run: |
script=$(
cat <<'EOS'
set -eux
cd opencvsharp/build
BIN="OpenCvSharpExtern/libOpenCvSharpExtern.so"
if [[ "${{ matrix.os }}" =~ ^win ]]; then
BIN="OpenCvSharpExtern/Release/OpenCvSharpExtern.dll"
llvm-objcopy --strip-all "$BIN"
elif [[ "${{ matrix.os }}" =~ ^osx ]]; then
BIN="OpenCvSharpExtern/libOpenCvSharpExtern.dylib"
strip -x "$BIN"
elif [[ "${{ matrix.os }}" == "android" ]]; then
$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip --strip-unneeded "$BIN"
else # Linux
strip --strip-unneeded "$BIN"
fi
echo "Size after strip:"
du -h "$BIN"
EOS
)
if [[ "${{ matrix.image }}" == "" ]]; then
bash -c "$script"
else
docker exec builder /bin/sh -c "$script"
fi
- name: Show OpenCvSharp Artifacts
run: |
cd opencvsharp/build
echo "::group::OpenCvSharp Artifacts"
ls -lR
echo "::endgroup::"
case "${{ matrix.os }}" in
android)
$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-readelf -d OpenCvSharpExtern/libOpenCvSharpExtern.so | grep NEEDED
;;
win)
echo "Can't show dependencies for Windows DLLs"
;;
osx*)
otool -L OpenCvSharpExtern/libOpenCvSharpExtern.dylib
;;
*) # Linux
ldd OpenCvSharpExtern/libOpenCvSharpExtern.so
;;
esac
- name: Make artifacts
run: |
mkdir artifacts && cd artifacts && mkdir lib test
if [[ "${{ matrix.os }}" =~ ^win ]]; then
cp -r ../opencvsharp/build/OpenCvSharpExtern/Release/OpenCvSharpExtern.* ./lib
else
cp -r ../opencvsharp/build/OpenCvSharpExtern/libOpenCvSharpExtern.* ./lib
fi
ls -lR
- name: Upload Artifacts
uses: actions/upload-artifact@v7
with:
name: opencvsharp-${{ matrix.os }}-${{ matrix.arch }}
path: artifacts