Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 193 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -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 <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./ -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
145 changes: 0 additions & 145 deletions .github/workflows/macos10.yml.disabled

This file was deleted.

22 changes: 15 additions & 7 deletions .github/workflows/publish_nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions nuget/OpenCvSharp4.runtime.osx-arm64.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;</TargetFrameworks>
<NoBuild>true</NoBuild>
<IncludeBuildOutput>false</IncludeBuildOutput>

<!-- NuGet Package Metadata -->
<PackageId>OpenCvSharp4.runtime.osx-arm64</PackageId>
<Title>OpenCvSharp native bindings for macOS ARM64</Title>
<Authors>shimat,vladkol</Authors>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/shimat/opencvsharp</PackageProjectUrl>
<PackageIcon>opencvsharp.png</PackageIcon>
<Description>Internal implementation package for OpenCvSharp to work on macOS ARM64 (Apple Silicon)</Description>
<PackageTags>Image Processing OpenCV Wrapper FFI opencvsharp macos arm64 apple-silicon</PackageTags>
<Copyright>Copyright 2008-2026</Copyright>
<PackageReleaseNotes></PackageReleaseNotes>
<RepositoryUrl>https://github.com/shimat/opencvsharp.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
<None Include="libOpenCvSharpExtern.dylib" Pack="true" PackagePath="runtimes/osx-arm64/native" />
<None Include="icon\opencvsharp.png" Pack="true" PackagePath="" />
</ItemGroup>
</Project>
Loading
Loading