diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml new file mode 100644 index 000000000..a67f8d6ae --- /dev/null +++ b/.github/workflows/macos.yml @@ -0,0 +1,193 @@ +name: macOS + +on: + pull_request: + types: [synchronize, opened] + push: + branches: + - main + +env: + DEBIAN_FRONTEND: noninteractive + OPENCV_VERSION: 4.13.0 + OPENCV_CACHE_VERSION: 4 + +jobs: + build: + strategy: + matrix: + include: + - runner: macos-14 + arch: arm64 + runtime_id: osx-arm64 + csproj: OpenCvSharp4.runtime.osx-arm64.csproj + artifact_name: artifacts_macos_arm64 + brew_prefix: /opt/homebrew + - runner: macos-15-intel + arch: x64 + runtime_id: osx-x64 + csproj: OpenCvSharp4.runtime.osx-x64.csproj + artifact_name: artifacts_macos_x64 + brew_prefix: /usr/local + + runs-on: ${{ matrix.runner }} + + steps: + - uses: actions/checkout@v6 + with: + path: opencvsharp + fetch-depth: 1 + + - name: Install build dependencies + run: | + brew install wget pkg-config mono-libgdiplus gtk+ ffmpeg@4 glog yasm harfbuzz jpeg libpng libtiff openjpeg metis openblas opencore-amr protobuf tbb webp # openexr + + - name: Cache OpenCV + id: opencv-cache + uses: actions/cache@v5 + with: + path: ${{ github.workspace }}/opencv_macos/ + key: opencv-${{ env.OPENCV_VERSION }}-macos-${{ matrix.arch }}-rev${{ env.OPENCV_CACHE_VERSION }} + + - name: Checkout OpenCV + if: steps.opencv-cache.outputs.cache-hit != 'true' + uses: actions/checkout@v6 + with: + repository: opencv/opencv + path: opencv + ref: ${{ env.OPENCV_VERSION }} + + - name: Checkout OpenCV Contrib + if: steps.opencv-cache.outputs.cache-hit != 'true' + uses: actions/checkout@v6 + with: + repository: opencv/opencv_contrib + path: opencv_contrib + ref: ${{ env.OPENCV_VERSION }} + + - name: Build OpenCV + if: steps.opencv-cache.outputs.cache-hit != 'true' + run: | + pwd + cmake \ + -S opencv \ + -B opencv/build \ + -D CMAKE_BUILD_TYPE=Release \ + -D CMAKE_PREFIX_PATH=${{ matrix.brew_prefix }} \ + -D OPENCV_EXTRA_MODULES_PATH=${GITHUB_WORKSPACE}/opencv_contrib/modules \ + -D BUILD_SHARED_LIBS=OFF \ + -D ENABLE_CXX11=ON \ + -D BUILD_TESTS=OFF \ + -D BUILD_PERF_TESTS=OFF \ + -D BUILD_DOCS=OFF \ + -D BUILD_EXAMPLES=OFF \ + -D BUILD_JAVA=OFF \ + -D BUILD_opencv_java_bindings_generator=OFF \ + -D BUILD_opencv_python_bindings_generator=OFF \ + -D BUILD_opencv_python_tests=OFF \ + -D BUILD_opencv_ts=OFF \ + -D BUILD_opencv_js=OFF \ + -D BUILD_opencv_js_bindings_generator=OFF \ + -D BUILD_opencv_apps=OFF \ + -D BUILD_opencv_barcode=OFF \ + -D BUILD_opencv_bioinspired=OFF \ + -D BUILD_opencv_ccalib=OFF \ + -D BUILD_opencv_datasets=OFF \ + -D BUILD_opencv_dnn_objdetect=OFF \ + -D BUILD_opencv_dpm=OFF \ + -D BUILD_opencv_fuzzy=OFF \ + -D BUILD_opencv_gapi=OFF \ + -D BUILD_opencv_intensity_transform=OFF \ + -D BUILD_opencv_mcc=OFF \ + -D BUILD_opencv_objc_bindings_generator=OFF \ + -D BUILD_opencv_rapid=OFF \ + -D BUILD_opencv_reg=OFF \ + -D BUILD_opencv_stereo=OFF \ + -D BUILD_opencv_structured_light=OFF \ + -D BUILD_opencv_surface_matching=OFF \ + -D BUILD_opencv_wechat_qrcode=ON \ + -D BUILD_opencv_videostab=OFF \ + -D Protobuf_ROOT=${{ matrix.brew_prefix }} \ + -D Protobuf_DIR=${{ matrix.brew_prefix }}/lib/cmake/protobuf \ + -D PROTOBUF_UPDATE_FILES=ON \ + -D WITH_VULKAN=OFF \ + -D WITH_OPENCL=OFF \ + -D WITH_GSTREAMER=OFF \ + -D WITH_EIGEN=OFF \ + -D WITH_ADE=OFF \ + -D WITH_OPENEXR=OFF \ + -D OPENCV_ENABLE_NONFREE=ON \ + -D CMAKE_INSTALL_PREFIX=${GITHUB_WORKSPACE}/opencv_macos + cmake --build opencv/build -j + cmake --install opencv/build + ls + + - name: Build OpenCvSharpExtern + run: | + export Protobuf_ROOT=${{ matrix.brew_prefix }} + export Protobuf_DIR=${{ matrix.brew_prefix }}/lib/cmake/protobuf + cmake \ + -S opencvsharp/src \ + -B opencvsharp/src/build \ + -D CMAKE_BUILD_TYPE=Release \ + -D CMAKE_PREFIX_PATH="${GITHUB_WORKSPACE}/opencv_macos;${{ matrix.brew_prefix }}" \ + -D Protobuf_ROOT=${{ matrix.brew_prefix }} \ + -D Protobuf_DIR=${{ matrix.brew_prefix }}/lib/cmake/protobuf + cmake --build opencvsharp/src/build -j + ls opencvsharp/src/build + ls opencvsharp/src/build/OpenCvSharpExtern + cp opencvsharp/src/build/OpenCvSharpExtern/libOpenCvSharpExtern.dylib ${GITHUB_WORKSPACE}/opencvsharp/nuget/ + + - name: Check OpenCvSharpExtern + run: | + cd ${GITHUB_WORKSPACE}/opencvsharp/nuget/ + otool -L libOpenCvSharpExtern.dylib + nm libOpenCvSharpExtern.dylib + echo -ne "#include \n int core_Mat_sizeof(); int main(){ int i = core_Mat_sizeof(); printf(\"sizeof(Mat) = %d\", i); return 0; }" > test.c + gcc -I./ -L./ -Wl,-rpath,. test.c -o test -lOpenCvSharpExtern + ./test + + - name: Install .NET + uses: actions/setup-dotnet@v5 + with: + dotnet-version: '8.0.x' + + - name: Create NuGet package + env: + BETA: "" + run: | + yyyymmdd=`date '+%Y%m%d'` + echo $yyyymmdd + version="${OPENCV_VERSION}.${yyyymmdd}${BETA}" + echo "Package version: $version" + dotnet pack ${GITHUB_WORKSPACE}/opencvsharp/nuget/${{ matrix.csproj }} -o ${GITHUB_WORKSPACE}/${{ matrix.artifact_name }} -p:Version=$version + ls ${GITHUB_WORKSPACE}/${{ matrix.artifact_name }} + + - uses: actions/upload-artifact@v6 + with: + name: ${{ matrix.artifact_name }} + path: ${{ matrix.artifact_name }} + + - name: Test + run: | + cd ${GITHUB_WORKSPACE}/opencvsharp/test/OpenCvSharp.Tests + dotnet build -c Release -f net8.0 + mkdir -p ${GITHUB_WORKSPACE}/opencvsharp/test/OpenCvSharp.Tests/bin/Release/net8.0/${{ matrix.runtime_id }}/ + cp ${GITHUB_WORKSPACE}/opencvsharp/nuget/libOpenCvSharpExtern.dylib ${GITHUB_WORKSPACE}/opencvsharp/test/OpenCvSharp.Tests/bin/Release/net8.0/ + cp ${GITHUB_WORKSPACE}/opencvsharp/nuget/libOpenCvSharpExtern.dylib ${GITHUB_WORKSPACE}/opencvsharp/test/OpenCvSharp.Tests/bin/Release/net8.0/${{ matrix.runtime_id }}/ + ls -l ${GITHUB_WORKSPACE}/opencvsharp/test/OpenCvSharp.Tests/bin/Release/net8.0/ + ls -l ${GITHUB_WORKSPACE}/opencvsharp/test/OpenCvSharp.Tests/bin/Release/net8.0/${{ matrix.runtime_id }}/ + export DYLD_LIBRARY_PATH=${GITHUB_WORKSPACE}/opencvsharp/test/OpenCvSharp.Tests/bin/Release/net8.0/${{ matrix.runtime_id }}:${GITHUB_WORKSPACE}/opencvsharp/test/OpenCvSharp.Tests/bin/Release/net8.0:. + export DYLD_PRINT_LIBRARIES=1 + dotnet test OpenCvSharp.Tests.csproj \ + -c Release \ + -f net8.0 \ + --runtime ${{ matrix.runtime_id }} \ + --logger "trx;LogFileName=test-results.trx" < /dev/null + ls + ls TestResults + + - uses: actions/upload-artifact@v6 + with: + name: ${{ matrix.artifact_name }}_test_results + path: opencvsharp/test/OpenCvSharp.Tests/TestResults/test-results.trx diff --git a/.github/workflows/macos10.yml.disabled b/.github/workflows/macos10.yml.disabled deleted file mode 100644 index fa5dd0732..000000000 --- a/.github/workflows/macos10.yml.disabled +++ /dev/null @@ -1,145 +0,0 @@ -name: macOS 10.15 - -on: - pull_request: - types: [synchronize, opened] - push: - branches: - - main - -env: - DEBIAN_FRONTEND: noninteractive - OPENCV_VERSION: 4.8.0 - -jobs: - build: - - runs-on: macos-11 - - steps: - - uses: actions/checkout@v6 - with: - fetch-depth: 1 - - - name: Install build dependencies - run: | - brew install wget pkg-config mono-libgdiplus gtk+ ffmpeg@4 glog yasm harfbuzz jpeg libpng libtiff openjpeg metis openblas opencore-amr protobuf tbb webp # openexr - -# - name: Cache OpenCV -# id: opencv-cache -# uses: actions/cache@v5 -# with: -# path: ${{ github.workspace }}/opencv_macos/ -# key: opencv-${{ env.OPENCV_VERSION }}-macos-rev1 - - - name: Build OpenCV - if: steps.opencv-cache.outputs.cache-hit != 'true' - run: | - pwd - wget https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip -Oopencv-${OPENCV_VERSION}.zip && unzip opencv-${OPENCV_VERSION}.zip - wget https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip -Oopencv_contrib-${OPENCV_VERSION}.zip && unzip opencv_contrib-${OPENCV_VERSION}.zip - cd opencv-${OPENCV_VERSION} && mkdir build && cd build - cmake \ - -DCMAKE_BUILD_TYPE=Release \ - -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \ - -DBUILD_SHARED_LIBS=OFF \ - -DENABLE_CXX11=ON -DBUILD_TESTS=OFF \ - -DBUILD_PERF_TESTS=OFF \ - -DBUILD_DOCS=OFF \ - -DBUILD_EXAMPLES=OFF \ - -DBUILD_JAVA=OFF \ - -DBUILD_opencv_java_bindings_generator=OFF \ - -DBUILD_opencv_python_bindings_generator=OFF \ - -DBUILD_opencv_python_tests=OFF \ - -DBUILD_opencv_ts=OFF \ - -DBUILD_opencv_js=OFF \ - -DBUILD_opencv_js_bindings_generator=OFF \ - -DBUILD_opencv_apps=OFF \ - -DBUILD_opencv_barcode=OFF \ - -DBUILD_opencv_bioinspired=OFF \ - -DBUILD_opencv_ccalib=OFF \ - -DBUILD_opencv_datasets=OFF \ - -DBUILD_opencv_dnn_objdetect=OFF \ - -DBUILD_opencv_dpm=OFF \ - -DBUILD_opencv_fuzzy=OFF \ - -DBUILD_opencv_gapi=ON \ - -DBUILD_opencv_intensity_transform=OFF \ - -DBUILD_opencv_mcc=OFF \ - -DBUILD_opencv_objc_bindings_generator=OFF \ - -DBUILD_opencv_rapid=OFF \ - -DBUILD_opencv_reg=OFF \ - -DBUILD_opencv_stereo=OFF \ - -DBUILD_opencv_structured_light=OFF \ - -DBUILD_opencv_surface_matching=OFF \ - -DBUILD_opencv_wechat_qrcode=ON \ - -DBUILD_opencv_videostab=OFF \ - -DWITH_GSTREAMER=OFF \ - -DWITH_EIGEN=OFF \ - -DWITH_ADE=OFF \ - -DWITH_OPENEXR=OFF \ - -DOPENCV_ENABLE_NONFREE=ON \ - -DCMAKE_INSTALL_PREFIX=${GITHUB_WORKSPACE}/opencv_macos .. - make -j2 - make install - cd ${GITHUB_WORKSPACE} - ls - - - name: Build OpenCvSharpExtern - run: | - pwd - mkdir src/build && cd $_ - cmake -DCMAKE_BUILD_TYPE=Release -D CMAKE_PREFIX_PATH=${GITHUB_WORKSPACE}/opencv_macos .. - make -j2 - ls - ls OpenCvSharpExtern - cp OpenCvSharpExtern/libOpenCvSharpExtern.dylib ${GITHUB_WORKSPACE}/nuget/ - - - name: Check OpenCvSharpExtern - run: | - cd ${GITHUB_WORKSPACE}/nuget/ - otool -L libOpenCvSharpExtern.dylib - nm libOpenCvSharpExtern.dylib - echo -ne "#include \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: '6.0.x' - - - name: Create NuGet package - env: - BETA: "" - run: | - yyyymmdd=`date '+%Y%m%d'` - echo $yyyymmdd - sed -E -i=.bak "s/[0-9]\.[0-9]{1,2}\.[0-9]{1,2}.[0-9]{8}(-beta[0-9]*)?<\/version>/${OPENCV_VERSION}.${yyyymmdd}${BETA}<\/version>/" ${GITHUB_WORKSPACE}/nuget/OpenCvSharp4.runtime.osx.10.15-x64.nuspec - cat ${GITHUB_WORKSPACE}/nuget/OpenCvSharp4.runtime.osx.10.15-x64.nuspec - dotnet pack ${GITHUB_WORKSPACE}/nuget/OpenCvSharp4.runtime.osx.10.15-x64.csproj -o ${GITHUB_WORKSPACE}/artifacts_macos - ls ${GITHUB_WORKSPACE}/artifacts_macos - - - uses: actions/upload-artifact@v3 - with: - name: artifacts_macos_10 - path: artifacts_macos - - - name: Test - run: | - cd ${GITHUB_WORKSPACE}/test/OpenCvSharp.Tests - # ls - dotnet build -c Release -f net8.0 - cp ${GITHUB_WORKSPACE}/nuget/libOpenCvSharpExtern.dylib ${GITHUB_WORKSPACE}/test/OpenCvSharp.Tests/bin/Release/net8.0/ - cp ${GITHUB_WORKSPACE}/nuget/libOpenCvSharpExtern.dylib ${GITHUB_WORKSPACE}/test/OpenCvSharp.Tests/ - # ls ${GITHUB_WORKSPACE}/test/OpenCvSharp.Tests/bin/Release/net8.0/ - # ls - sudo cp ${GITHUB_WORKSPACE}/nuget/libOpenCvSharpExtern.dylib /usr/local/lib/ - LD_LIBRARY_PATH=. - dotnet test OpenCvSharp.Tests.csproj -c Release -f net8.0 --runtime osx-x64 --logger "trx;LogFileName=test-results.trx" < /dev/null - ls - ls TestResults - - - uses: actions/upload-artifact@v1 - with: - name: artifacts_macos_10_test_results - path: test/OpenCvSharp.Tests/TestResults/test-results.trx diff --git a/.github/workflows/publish_nuget.yml b/.github/workflows/publish_nuget.yml index e91f14d34..554bedd9b 100644 --- a/.github/workflows/publish_nuget.yml +++ b/.github/workflows/publish_nuget.yml @@ -58,13 +58,21 @@ jobs: name: artifacts_linux_arm branch: ${{ github.ref_name }} - #- name: Download macos artifact - # uses: dawidd6/action-download-artifact@v14 - # with: - # github_token: ${{secrets.GITHUB_TOKEN}} - # workflow: macos10.yml - # name: artifacts_macos_10 - # branch: ${{ github.ref_name }} + - name: Download macos arm64 artifact + uses: dawidd6/action-download-artifact@v14 + with: + github_token: ${{secrets.GITHUB_TOKEN}} + workflow: macos.yml + name: artifacts_macos_arm64 + branch: ${{ github.ref_name }} + + - name: Download macos x64 artifact + uses: dawidd6/action-download-artifact@v14 + with: + github_token: ${{secrets.GITHUB_TOKEN}} + workflow: macos.yml + name: artifacts_macos_x64 + branch: ${{ github.ref_name }} - name: Download wasm artifact uses: dawidd6/action-download-artifact@v14 diff --git a/nuget/OpenCvSharp4.runtime.osx-arm64.csproj b/nuget/OpenCvSharp4.runtime.osx-arm64.csproj new file mode 100644 index 000000000..50539f935 --- /dev/null +++ b/nuget/OpenCvSharp4.runtime.osx-arm64.csproj @@ -0,0 +1,27 @@ + + + netstandard2.0;netstandard2.1;netcoreapp3.1; + true + false + + + OpenCvSharp4.runtime.osx-arm64 + OpenCvSharp native bindings for macOS ARM64 + shimat,vladkol + Apache-2.0 + https://github.com/shimat/opencvsharp + opencvsharp.png + Internal implementation package for OpenCvSharp to work on macOS ARM64 (Apple Silicon) + Image Processing OpenCV Wrapper FFI opencvsharp macos arm64 apple-silicon + Copyright 2008-2026 + + https://github.com/shimat/opencvsharp.git + git + false + + + + + + + diff --git a/nuget/OpenCvSharp4.runtime.osx-x64.csproj b/nuget/OpenCvSharp4.runtime.osx-x64.csproj new file mode 100644 index 000000000..789b0df26 --- /dev/null +++ b/nuget/OpenCvSharp4.runtime.osx-x64.csproj @@ -0,0 +1,27 @@ + + + netstandard2.0;netstandard2.1;netcoreapp3.1; + true + false + + + OpenCvSharp4.runtime.osx-x64 + OpenCvSharp native bindings for macOS x64 (Intel) + shimat,vladkol + Apache-2.0 + https://github.com/shimat/opencvsharp + opencvsharp.png + Internal implementation package for OpenCvSharp to work on macOS x64 (Intel) + Image Processing OpenCV Wrapper FFI opencvsharp macos x64 intel + Copyright 2008-2026 + + https://github.com/shimat/opencvsharp.git + git + false + + + + + + + diff --git a/nuget/OpenCvSharp4.runtime.osx.10.15-x64.csproj b/nuget/OpenCvSharp4.runtime.osx.10.15-x64.csproj index 1169cdf89..6e2132aad 100644 --- a/nuget/OpenCvSharp4.runtime.osx.10.15-x64.csproj +++ b/nuget/OpenCvSharp4.runtime.osx.10.15-x64.csproj @@ -6,13 +6,13 @@ OpenCvSharp4.runtime.osx.10.15-x64 - OpenCvSharp native bindings for macOS.10.15-x64 + OpenCvSharp native bindings for macOS x64 (Intel) shimat,vladkol Apache-2.0 https://github.com/shimat/opencvsharp opencvsharp.png - Internal implementation package for OpenCvSharp to work on macOS 10 - Image Processing OpenCV Wrapper FFI opencvsharp macos + Internal implementation package for OpenCvSharp to work on macOS x64 (Intel) + Image Processing OpenCV Wrapper FFI opencvsharp macos x64 intel Copyright 2008-2026 https://github.com/shimat/opencvsharp.git