Skip to content

Commit 86a20bc

Browse files
committed
try build opencvsharp4
1 parent 9eb2a80 commit 86a20bc

File tree

1 file changed

+109
-22
lines changed

1 file changed

+109
-22
lines changed

.github/workflows/opencvsharp.yml

Lines changed: 109 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ jobs:
3434
- { os: osx, arch: x64, runs-on: macos-13 }
3535
- { os: osx, arch: arm64, runs-on: macos-14 }
3636
- { os: osx.15, arch: arm64, runs-on: macos-15 }
37+
- { os: centos.7, arch: x64, runs-on: ubuntu-22.04, image: oraclelinux:7 }
38+
- { os: centos.7, arch: arm64, runs-on: ubuntu-22.04-arm, image: oraclelinux:7 }
39+
- { os: rhel.8, arch: x64, runs-on: ubuntu-22.04, image: oraclelinux:8 }
40+
- { os: rhel.8, arch: arm64, runs-on: ubuntu-22.04-arm, image: oraclelinux:8 }
41+
- { os: rhel.9, arch: x64, runs-on: ubuntu-22.04, image: oraclelinux:9 }
42+
- { os: rhel.9, arch: arm64, runs-on: ubuntu-22.04-arm, image: oraclelinux:9 }
43+
- { os: android, arch: arm64, runs-on: ubuntu-22.04 }
44+
- { os: android, arch: x64, runs-on: ubuntu-22.04 }
3745

3846
steps:
3947
- name: Checkout
@@ -66,51 +74,130 @@ jobs:
6674
cd opencvsharp
6775
git apply --ignore-whitespace ../eng/opencvsharp.patch
6876
69-
- name: Configure OpenCvSharp
77+
- name: Pull Docker Image
78+
if: matrix.image != ''
7079
run: |
71-
cd opencvsharp && mkdir build && cd build
80+
docker pull ${{ matrix.image }}
7281
73-
if [[ "${{ matrix.os }}" =~ ^win ]]; then
74-
OpenCV_DIR="${{ github.workspace }}/opencv/${{ matrix.arch }}/vc17/staticlib"
75-
else
76-
OpenCV_DIR="${{ github.workspace }}/opencv/lib/cmake/opencv4"
82+
- name: Start Docker Container
83+
if: matrix.image != ''
84+
run: |
85+
docker run -d --name builder -v "$PWD":${{ github.workspace }} -w ${{ github.workspace }} ${{ matrix.image }} tail -f /dev/null
86+
87+
- name: Initialize Docker Container
88+
if: matrix.image != ''
89+
run: |
90+
if [[ "${{ matrix.os }}" == "centos.7" ]]; then
91+
script=$(
92+
cat <<'EOS'
93+
set -eux
94+
yum install -y oracle-epel-release-el7
95+
yum-config-manager --enable ol7_developer_epel
96+
EOS
97+
)
98+
elif [[ "${{ matrix.os }}" == "rhel.8" ]]; then
99+
script=$(
100+
cat <<'EOS'
101+
set -eux
102+
dnf config-manager --set-enabled ol8_codeready_builder
103+
EOS
104+
)
105+
elif [[ "${{ matrix.os }}" == "rhel.9" ]]; then
106+
script=$(
107+
cat <<'EOS'
108+
set -eux
109+
dnf config-manager --set-enabled ol9_codeready_builder
110+
EOS
111+
)
77112
fi
113+
echo "Executing script in Docker container: $script"
114+
docker exec builder bash -c "$script"
78115
79-
EXTRA_FLAGS=""
80-
if [[ "${{ matrix.os }}" == "win" && "${{ matrix.arch }}" == "x86" ]]; then
81-
EXTRA_FLAGS+=" -A Win32"
116+
- name: Install Dependencies in Docker Container
117+
if: matrix.image != ''
118+
run: |
119+
if [[ "${{ matrix.os }}" == "centos.7" || "${{ matrix.os }}" =~ "rhel." ]]; then
120+
script=$(
121+
cat <<'EOS'
122+
set -eux
123+
yum install -y gcc cmake3 gcc-c++ make nasm
124+
EOS
125+
)
82126
fi
127+
echo "Executing script in Docker container: $script"
128+
docker exec builder bash -c "$script"
83129
84-
cmake \
85-
-D CMAKE_INSTALL_PREFIX="${{ github.workspace }}/opencvsharp/build" \
86-
-D OpenCV_DIR="$OpenCV_DIR" \
87-
$EXTRA_FLAGS \
88-
../src
130+
- name: Configure OpenCvSharp
131+
run: |
132+
script=$(
133+
cat <<'EOS'
134+
set -eux
135+
if [[ "${{ matrix.os }}" =~ ^win ]]; then
136+
OpenCV_DIR="${{ github.workspace }}/opencv/${{ matrix.arch }}/vc17/staticlib"
137+
else
138+
OpenCV_DIR="${{ github.workspace }}/opencv/lib/cmake/opencv4"
139+
fi
140+
141+
EXTRA_FLAGS=""
142+
if [[ "${{ matrix.os }}" == "win" && "${{ matrix.arch }}" == "x86" ]]; then
143+
EXTRA_FLAGS+=" -A Win32"
144+
fi
145+
146+
cd opencvsharp && mkdir build && cd build
147+
cmake \
148+
-D CMAKE_INSTALL_PREFIX="${{ github.workspace }}/opencvsharp/build" \
149+
-D OpenCV_DIR="$OpenCV_DIR" \
150+
$EXTRA_FLAGS \
151+
../src
152+
EOS
153+
)
154+
155+
if [[ "${{ matrix.image }}" == "" ]]; then
156+
bash -c "$script"
157+
else
158+
docker exec builder bash -c "$script"
159+
fi
89160
90161
- name: Build OpenCvSharp
91162
run: |
92-
cd opencvsharp/build
93-
94-
if [[ "${{ matrix.os }}" =~ ^win ]]; then
95-
cmake --build . --parallel --config Release
163+
script=$(
164+
cat <<'EOS'
165+
set -eux
166+
cd opencvsharp/build
167+
if [[ "${{ matrix.os }}" =~ ^win ]]; then
168+
cmake --build . --parallel --config Release
169+
else
170+
make -j$(nproc)
171+
fi
172+
EOS
173+
)
174+
175+
if [[ "${{ matrix.image }}" == "" ]]; then
176+
bash -c "$script"
96177
else
97-
make -j$(nproc)
178+
docker exec builder bash -c "$script"
98179
fi
99180
100181
- name: Strip OpenCvSharpExtern
101182
run: |
102183
cd opencvsharp/build
184+
BIN="OpenCvSharpExtern/libOpenCvSharpExtern.so"
103185
104186
if [[ "${{ matrix.os }}" =~ ^win ]]; then
105187
BIN="OpenCvSharpExtern/Release/OpenCvSharpExtern.dll"
106188
llvm-objcopy --strip-all "$BIN"
107-
108189
elif [[ "${{ matrix.os }}" =~ ^osx ]]; then
109190
BIN="OpenCvSharpExtern/libOpenCvSharpExtern.dylib"
110191
strip -x "$BIN"
111-
192+
elif [[ "${{ matrix.os }}" == "android" ]]; then
193+
if [[ "${{ matrix.arch }}" == "arm64" ]]; then
194+
aarch64-linux-android-strip --strip-unneeded "$BIN"
195+
elif [[ "${{ matrix.arch }}" == "x64" ]]; then
196+
x86_64-linux-android-strip --strip-unneeded "$BIN"
197+
else
198+
echo "Unsupported Android architecture: ${{ matrix.arch }}"
199+
fi
112200
else # Linux
113-
BIN="OpenCvSharpExtern/libOpenCvSharpExtern.so"
114201
strip --strip-unneeded "$BIN"
115202
fi
116203

0 commit comments

Comments
 (0)