|
| 1 | +name: macOS Build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + name: macOS arm64 |
| 12 | + runs-on: macos-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Setup Node.js |
| 18 | + uses: actions/setup-node@v4 |
| 19 | + with: |
| 20 | + node-version: '22' |
| 21 | + cache: npm |
| 22 | + |
| 23 | + - name: Setup Rust |
| 24 | + uses: dtolnay/rust-toolchain@stable |
| 25 | + |
| 26 | + - name: Install OpenCV and LLVM |
| 27 | + run: | |
| 28 | + brew install llvm opencv |
| 29 | + LLVM_DIR=$(brew --prefix llvm) |
| 30 | + OPENCV_INC=$(brew --prefix opencv)/include/opencv4 |
| 31 | + echo "LIBCLANG_PATH=${LLVM_DIR}/lib" >> $GITHUB_ENV |
| 32 | + echo "DYLD_FALLBACK_LIBRARY_PATH=${LLVM_DIR}/lib" >> $GITHUB_ENV |
| 33 | +
|
| 34 | + - name: Diagnostics - print header content |
| 35 | + run: | |
| 36 | + OPENCV_INC=$(brew --prefix opencv)/include/opencv4 |
| 37 | + echo "=== OpenCV version ===" |
| 38 | + pkg-config --modversion opencv4 2>/dev/null || true |
| 39 | + echo "=== RotatedRect class ===" |
| 40 | + awk '/^class CV_EXPORTS.*RotatedRect/{p=1} p; /^};/{p=0}' \ |
| 41 | + "$OPENCV_INC/opencv2/core/types.hpp" | head -40 |
| 42 | + echo "=== DMatch class ===" |
| 43 | + awk '/^class CV_EXPORTS.*DMatch/{p=1} p; /^};/{p=0}' \ |
| 44 | + "$OPENCV_INC/opencv2/core/types.hpp" | head -40 |
| 45 | + echo "=== TermCriteria isValid ===" |
| 46 | + grep -n -A8 "isValid" "$OPENCV_INC/opencv2/core/types.hpp" | head -20 |
| 47 | + echo "=== NMSBoxes signature ===" |
| 48 | + grep -n "NMSBoxes" "$OPENCV_INC/opencv2/dnn/dnn.hpp" | head -8 |
| 49 | + echo "=== drawMatches char ===" |
| 50 | + grep -n "drawMatches" "$OPENCV_INC/opencv2/features2d.hpp" | head -5 |
| 51 | +
|
| 52 | + - name: Install npm dependencies |
| 53 | + run: npm install --ignore-scripts |
| 54 | + |
| 55 | + - name: Patch crate and headers |
| 56 | + run: | |
| 57 | + cargo fetch |
| 58 | + CRATE=$(find ~/.cargo/registry/src -name "opencv-0.98.*" -maxdepth 2 -type d | head -1) |
| 59 | + OPENCV_INC=$(brew --prefix opencv)/include/opencv4 |
| 60 | + echo "Crate: $CRATE" |
| 61 | +
|
| 62 | + sed -i '' '/input_output_array_vector! { UMat/d' "$CRATE/src/manual/core/mat.rs" |
| 63 | +
|
| 64 | + perl -i -pe 's/\bCV_WRAP\b\s+//g if /boundingRect2f|isValid/' \ |
| 65 | + "$OPENCV_INC/opencv2/core/types.hpp" 2>/dev/null || true |
| 66 | +
|
| 67 | + perl -i -0pe \ |
| 68 | + 's/(class CV_EXPORTS RotatedRect.*?)(\bCV_WRAP\b\s+)(void points|Rect boundingRect|Rect_<float> boundingRect2f)/$1$3/gse' \ |
| 69 | + "$OPENCV_INC/opencv2/core/types.hpp" 2>/dev/null || true |
| 70 | +
|
| 71 | + perl -i -0pe 's/inline\s+bool\s+isValid\(\)\s+const\s*\{[^}]*\}/bool isValid() const;/s' \ |
| 72 | + "$OPENCV_INC/opencv2/core/types.hpp" 2>/dev/null || true |
| 73 | +
|
| 74 | + perl -i -0pe 's/const\s+std::vector<std::vector<char>>/const std::vector<std::vector<int8_t>>/sg' \ |
| 75 | + "$OPENCV_INC/opencv2/features2d.hpp" 2>/dev/null || true |
| 76 | +
|
| 77 | + if [ -f "$OPENCV_INC/opencv2/tracking.hpp" ]; then |
| 78 | + printf '%s\n' '#pragma once' > "$OPENCV_INC/opencv2/tracking.hpp" |
| 79 | + rm -rf "$OPENCV_INC/opencv2/tracking" |
| 80 | + fi |
| 81 | +
|
| 82 | + perl -i -0pe 's/CV_WRAP\s+static\s+bool\s+waitAny[^;]+;//sg' \ |
| 83 | + "$OPENCV_INC/opencv2/videoio.hpp" 2>/dev/null || true |
| 84 | +
|
| 85 | + STUBS="$OPENCV_INC/opencv2/ocvrs_4_11_stubs.hpp" |
| 86 | + printf '%s\n' \ |
| 87 | + '#pragma once' \ |
| 88 | + '#ifdef OCVRS_PARSING_HEADERS' \ |
| 89 | + '#include <opencv2/core.hpp>' \ |
| 90 | + 'CV_EXPORTS_W void _f32(const std::vector<float>& a, CV_OUT std::vector<float>& b);' \ |
| 91 | + 'CV_EXPORTS_W void _i32(const std::vector<int>& a, CV_OUT std::vector<int>& b);' \ |
| 92 | + 'CV_EXPORTS_W void _r2d(const std::vector<cv::Rect2d>& a);' \ |
| 93 | + 'CV_EXPORTS_W void _vvf(const std::vector<std::vector<float>>& a);' \ |
| 94 | + 'CV_EXPORTS_W void _vvi(const std::vector<std::vector<int>>& a);' \ |
| 95 | + '#endif' > "$STUBS" |
| 96 | + echo '#include <opencv2/ocvrs_4_11_stubs.hpp>' >> "$CRATE/src_cpp/core.hpp" |
| 97 | + printf '%s\n' \ |
| 98 | + '#ifdef OCVRS_PARSING_HEADERS' \ |
| 99 | + '#include <opencv2/dnn/dnn.hpp>' \ |
| 100 | + 'CV_EXPORTS_W void _bknd(const std::vector<cv::Ptr<cv::dnn::BackendNode>>& a);' \ |
| 101 | + '#endif' >> "$CRATE/src_cpp/dnn.hpp" |
| 102 | +
|
| 103 | + echo "=== After patch RotatedRect ===" |
| 104 | + awk '/^class CV_EXPORTS.*RotatedRect/{p=1} p; /^};/{p=0}' \ |
| 105 | + "$OPENCV_INC/opencv2/core/types.hpp" | head -30 |
| 106 | +
|
| 107 | + - name: Build (debug) |
| 108 | + run: npm run build:debug |
| 109 | + |
| 110 | + - name: Run tests |
| 111 | + run: npm test |
0 commit comments