Use git submodules for OpenCV, vcpkg for Tesseract, and cmake initial cache files for build flags #89
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Ubuntu Slim | |
| on: | |
| pull_request: | |
| types: [synchronize, opened] | |
| push: | |
| branches: | |
| - main | |
| env: | |
| DEBIAN_FRONTEND: noninteractive | |
| OPENCV_VERSION: 4.13.0 | |
| jobs: | |
| build_test: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - ubuntu: "22.04" | |
| - ubuntu: "24.04" | |
| runs-on: ubuntu-${{ matrix.ubuntu }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| submodules: true | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update -y | |
| sudo apt-get install -y --no-install-recommends \ | |
| apt-transport-https \ | |
| software-properties-common \ | |
| ca-certificates \ | |
| g++ \ | |
| make \ | |
| cmake \ | |
| libtbb-dev \ | |
| libatlas-base-dev \ | |
| libjpeg-dev \ | |
| libpng-dev \ | |
| libtiff-dev \ | |
| libopenjp2-7-dev \ | |
| zlib1g-dev | |
| - name: Restore OpenCV cache (slim) | |
| id: opencv-cache | |
| uses: actions/cache/restore@v5 | |
| with: | |
| path: | | |
| ${{ github.workspace }}/opencv_artifacts_slim/include | |
| ${{ github.workspace }}/opencv_artifacts_slim/lib | |
| key: opencv-${{ env.OPENCV_VERSION }}-ubuntu-${{ matrix.ubuntu }}-slim | |
| - name: Build OpenCV (slim) | |
| if: steps.opencv-cache.outputs.cache-hit != 'true' | |
| run: | | |
| # Keep a practical subset (e.g., features2d/objdetect) while avoiding heavy runtime deps | |
| # from UI/video stacks and contrib modules. | |
| cmake \ | |
| -C cmake/opencv_build_options_slim.cmake \ | |
| -S opencv \ | |
| -B opencv/build \ | |
| -D CMAKE_INSTALL_PREFIX=${GITHUB_WORKSPACE}/opencv_artifacts_slim | |
| cmake --build opencv/build -j 3 | |
| cmake --install opencv/build | |
| - name: Validate OpenCV protobuf export (slim) | |
| run: | | |
| set -euo pipefail | |
| modules_dir="${GITHUB_WORKSPACE}/opencv_artifacts_slim/lib/cmake/opencv4" | |
| modules_file="${modules_dir}/OpenCVModules.cmake" | |
| release_file="${modules_dir}/OpenCVModules-release.cmake" | |
| if [ -f "${modules_file}" ]; then | |
| echo "Checking OpenCV module exports for protobuf reference" | |
| grep -n "liblibprotobuf.a\|libprotobuf.a" "${modules_file}" || true | |
| fi | |
| if [ -f "${release_file}" ]; then | |
| grep -n "liblibprotobuf.a\|libprotobuf.a" "${release_file}" || true | |
| fi | |
| bad_ref=0 | |
| if [ -f "${modules_file}" ] && grep -q "liblibprotobuf.a" "${modules_file}"; then | |
| bad_ref=1 | |
| fi | |
| if [ -f "${release_file}" ] && grep -q "liblibprotobuf.a" "${release_file}"; then | |
| bad_ref=1 | |
| fi | |
| if [ "${bad_ref}" -eq 1 ]; then | |
| echo "Found bad liblibprotobuf.a reference, applying compatibility rewrite" | |
| [ -f "${modules_file}" ] && sed -i 's/liblibprotobuf.a/libprotobuf.a/g' "${modules_file}" | |
| [ -f "${release_file}" ] && sed -i 's/liblibprotobuf.a/libprotobuf.a/g' "${release_file}" | |
| fi | |
| if [ -f "${modules_file}" ]; then | |
| grep -n "liblibprotobuf.a" "${modules_file}" && exit 1 || true | |
| fi | |
| if [ -f "${release_file}" ]; then | |
| grep -n "liblibprotobuf.a" "${release_file}" && exit 1 || true | |
| fi | |
| - name: Save OpenCV cache (slim) | |
| 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/include | |
| ${{ github.workspace }}/opencv_artifacts_slim/lib | |
| key: opencv-${{ env.OPENCV_VERSION }}-ubuntu-${{ matrix.ubuntu }}-slim | |
| - name: Build OpenCvSharpExtern (slim) | |
| run: | | |
| # Match OpenCV subset above: keep common CV modules, disable wrappers for disabled modules. | |
| cmake \ | |
| -S src \ | |
| -B src/build-slim \ | |
| -D CMAKE_BUILD_TYPE=Release \ | |
| -D CMAKE_PREFIX_PATH=${GITHUB_WORKSPACE}/opencv_artifacts_slim \ | |
| -D NO_CONTRIB=ON \ | |
| -D NO_STITCHING=ON \ | |
| -D NO_VIDEO=ON \ | |
| -D NO_VIDEOIO=ON \ | |
| -D NO_HIGHGUI=ON \ | |
| -D NO_DNN=ON \ | |
| -D NO_ML=ON \ | |
| -D NO_BARCODE=ON | |
| cmake --build src/build-slim -j | |
| cp src/build-slim/OpenCvSharpExtern/libOpenCvSharpExtern.so ${GITHUB_WORKSPACE}/nuget/ | |
| - name: Check OpenCvSharpExtern dependencies (slim) | |
| run: | | |
| cd ${GITHUB_WORKSPACE}/nuget/ | |
| ldd -r libOpenCvSharpExtern.so | |
| ! ldd libOpenCvSharpExtern.so | grep -q "not found" | |
| - name: Smoke test OpenCvSharpExtern (slim) | |
| run: | | |
| cd ${GITHUB_WORKSPACE}/nuget/ | |
| echo -ne "#include <stdio.h> \n int 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 | |
| - name: Install .NET | |
| uses: actions/setup-dotnet@v5 | |
| with: | |
| dotnet-version: '8.0.x' | |
| - name: Create NuGet package (slim) | |
| env: | |
| BETA: "-beta" | |
| run: | | |
| yyyymmdd=`date '+%Y%m%d'` | |
| version="${OPENCV_VERSION}.${yyyymmdd}${BETA}" | |
| echo "Package version: $version" | |
| cd ${GITHUB_WORKSPACE} | |
| package_project="OpenCvSharp4.official.runtime.ubuntu.${{ matrix.ubuntu }}-x64.slim.csproj" | |
| dotnet pack "nuget/${package_project}" -o ${GITHUB_WORKSPACE}/artifacts -p:Version=$version | |
| - name: Create linux-x64 NuGet package (slim) | |
| if: matrix.ubuntu == '22.04' | |
| env: | |
| BETA: "-beta" | |
| run: | | |
| yyyymmdd=`date '+%Y%m%d'` | |
| version="${OPENCV_VERSION}.${yyyymmdd}${BETA}" | |
| echo "Package version: $version" | |
| cd ${GITHUB_WORKSPACE} | |
| dotnet pack "nuget/OpenCvSharp4.official.runtime.linux-x64.slim.csproj" -o ${GITHUB_WORKSPACE}/artifacts -p:Version=$version | |
| - uses: actions/upload-artifact@v6 | |
| with: | |
| name: artifacts_ubuntu_slim_${{ matrix.ubuntu }} | |
| path: artifacts |