Skip to content

Commit fc565cf

Browse files
committed
feat: initial release - OpenCV bindings for Node.js powered by Rust
0 parents  commit fc565cf

31 files changed

Lines changed: 1796 additions & 0 deletions

.github/workflows/linux.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Linux Build
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '22'
20+
21+
- name: Setup Rust
22+
uses: dtolnay/rust-toolchain@stable
23+
24+
- name: Install system dependencies
25+
run: |
26+
sudo apt-get update
27+
sudo apt-get install -y cmake libopencv-dev llvm clang libclang-dev
28+
echo "LIBCLANG_PATH=/usr/lib/x86_64-linux-gnu" >> $GITHUB_ENV
29+
30+
- name: Install npm dependencies
31+
run: npm install --ignore-scripts
32+
33+
- name: Build
34+
run: npm run build
35+
36+
- name: Smoke test
37+
run: |
38+
node -e 'const cv = require("./main.js"); const info = cv.getBuildInformation(); if (!info.includes("OpenCV")) process.exit(1); console.log("OK:", info.split("\n")[0]);'

.github/workflows/mac.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: macOS Build
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
runs-on: macos-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '22'
20+
21+
- name: Setup Rust
22+
uses: dtolnay/rust-toolchain@stable
23+
24+
- name: Install system dependencies
25+
run: |
26+
brew install llvm opencv
27+
LLVM_DIR=$(brew --prefix llvm)
28+
OPENCV_INC=$(brew --prefix opencv)/include/opencv4
29+
for module in surface_matching gapi; do
30+
if [ -f "$OPENCV_INC/opencv2/${module}.hpp" ]; then
31+
echo "#pragma once // stubbed to avoid binding generator crash" > "$OPENCV_INC/opencv2/${module}.hpp"
32+
rm -rf "$OPENCV_INC/opencv2/${module}"
33+
fi
34+
done
35+
echo "LIBCLANG_PATH=${LLVM_DIR}/lib" >> $GITHUB_ENV
36+
echo "DYLD_FALLBACK_LIBRARY_PATH=${LLVM_DIR}/lib" >> $GITHUB_ENV
37+
38+
- name: Install npm dependencies
39+
run: npm install --ignore-scripts
40+
41+
- name: Build
42+
run: npm run build
43+
44+
- name: Smoke test
45+
run: |
46+
node -e 'const cv = require("./main.js"); const info = cv.getBuildInformation(); if (!info.includes("OpenCV")) process.exit(1); console.log("OK:", info.split("\n")[0]);'

.github/workflows/release.yml

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
defaults:
9+
run:
10+
shell: bash
11+
12+
jobs:
13+
build:
14+
name: Build ${{ matrix.target }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
include:
19+
- target: x86_64-unknown-linux-gnu
20+
os: ubuntu-latest
21+
node-file: node-opencv-rs.linux-x64-gnu.node
22+
npm-dir: npm/linux-x64-gnu
23+
24+
- target: aarch64-apple-darwin
25+
os: macos-latest
26+
node-file: node-opencv-rs.darwin-arm64.node
27+
npm-dir: npm/darwin-arm64
28+
29+
- target: x86_64-pc-windows-msvc
30+
os: windows-latest
31+
node-file: node-opencv-rs.win32-x64-msvc.node
32+
npm-dir: npm/win32-x64-msvc
33+
34+
runs-on: ${{ matrix.os }}
35+
36+
steps:
37+
- uses: actions/checkout@v4
38+
39+
- name: Setup Node.js
40+
uses: actions/setup-node@v4
41+
with:
42+
node-version: '22'
43+
44+
- name: Setup Rust
45+
uses: dtolnay/rust-toolchain@stable
46+
with:
47+
targets: ${{ matrix.target }}
48+
49+
- name: Install Linux dependencies
50+
if: matrix.os == 'ubuntu-latest'
51+
run: |
52+
sudo apt-get update
53+
sudo apt-get install -y cmake libopencv-dev llvm clang libclang-dev
54+
echo "LIBCLANG_PATH=/usr/lib/x86_64-linux-gnu" >> $GITHUB_ENV
55+
56+
- name: Install macOS dependencies
57+
if: startsWith(matrix.os, 'macos')
58+
run: |
59+
brew install llvm opencv
60+
LLVM_DIR=$(brew --prefix llvm)
61+
OPENCV_INC=$(brew --prefix opencv)/include/opencv4
62+
# Work around opencv-binding-generator 0.93.x panic on macOS ARM64
63+
# surface_matching and gapi headers cause unreachable code in the generator.
64+
# These modules are not used by this package.
65+
for module in surface_matching gapi; do
66+
if [ -f "$OPENCV_INC/opencv2/${module}.hpp" ]; then
67+
echo "#pragma once // stubbed to avoid binding generator crash" > "$OPENCV_INC/opencv2/${module}.hpp"
68+
rm -rf "$OPENCV_INC/opencv2/${module}"
69+
fi
70+
done
71+
echo "LIBCLANG_PATH=${LLVM_DIR}/lib" >> $GITHUB_ENV
72+
echo "DYLD_FALLBACK_LIBRARY_PATH=${LLVM_DIR}/lib" >> $GITHUB_ENV
73+
74+
- name: Install Windows dependencies
75+
if: matrix.os == 'windows-latest'
76+
shell: pwsh
77+
run: |
78+
$opencvVersion = "4.10.0"
79+
$url = "https://github.com/opencv/opencv/releases/download/$opencvVersion/opencv-$opencvVersion-windows.exe"
80+
Invoke-WebRequest -Uri $url -OutFile "opencv.exe" -TimeoutSec 600
81+
Start-Process -FilePath "opencv.exe" -ArgumentList "-y -o`"D:`"" -Wait
82+
echo "OPENCV_INCLUDE_PATHS=D:\opencv\build\include" | Out-File -FilePath $env:GITHUB_ENV -Append
83+
echo "OPENCV_LINK_LIBS=opencv_world4100" | Out-File -FilePath $env:GITHUB_ENV -Append
84+
echo "OPENCV_LINK_PATHS=D:\opencv\build\x64\vc16\lib" | Out-File -FilePath $env:GITHUB_ENV -Append
85+
echo "D:\opencv\build\x64\vc16\bin" | Out-File -FilePath $env:GITHUB_PATH -Append
86+
87+
- name: Install npm dependencies
88+
run: npm install --ignore-scripts
89+
90+
- name: Build
91+
run: npm run build
92+
93+
- name: Smoke test
94+
run: |
95+
node -e 'const cv = require("./main.js"); const info = cv.getBuildInformation(); if (!info.includes("OpenCV")) process.exit(1); console.log("OK:", info.split("\n")[0]);'
96+
97+
- name: Rename artifact
98+
run: mv node-opencv-rs.node ${{ matrix.node-file }}
99+
100+
- name: Upload artifact
101+
uses: actions/upload-artifact@v4
102+
with:
103+
name: ${{ matrix.node-file }}
104+
path: ${{ matrix.node-file }}
105+
retention-days: 1
106+
107+
publish:
108+
name: Publish to npm and GitHub Releases
109+
needs: build
110+
runs-on: ubuntu-latest
111+
permissions:
112+
contents: write
113+
114+
steps:
115+
- uses: actions/checkout@v4
116+
117+
- name: Setup Node.js
118+
uses: actions/setup-node@v4
119+
with:
120+
node-version: '22'
121+
registry-url: 'https://registry.npmjs.org'
122+
123+
- name: Download all artifacts
124+
uses: actions/download-artifact@v4
125+
with:
126+
path: artifacts
127+
128+
- name: Get version from tag
129+
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
130+
131+
- name: Create GitHub Release
132+
uses: softprops/action-gh-release@v2
133+
with:
134+
generate_release_notes: true
135+
files: artifacts/**/*.node
136+
137+
- name: Set versions in all packages
138+
run: |
139+
npm version $VERSION --no-git-tag-version --allow-same-version
140+
for dir in npm/linux-x64-gnu npm/darwin-arm64 npm/win32-x64-msvc; do
141+
cd "$dir"
142+
npm version $VERSION --no-git-tag-version --allow-same-version
143+
cd ../..
144+
done
145+
146+
- name: Publish linux-x64-gnu
147+
run: |
148+
cp artifacts/node-opencv-rs.linux-x64-gnu.node/node-opencv-rs.linux-x64-gnu.node npm/linux-x64-gnu/
149+
cd npm/linux-x64-gnu
150+
npm publish --access public
151+
env:
152+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
153+
154+
- name: Publish darwin-arm64
155+
if: hashFiles('artifacts/node-opencv-rs.darwin-arm64.node/node-opencv-rs.darwin-arm64.node') != ''
156+
run: |
157+
cp artifacts/node-opencv-rs.darwin-arm64.node/node-opencv-rs.darwin-arm64.node npm/darwin-arm64/
158+
cd npm/darwin-arm64
159+
npm publish --access public
160+
env:
161+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
162+
163+
- name: Publish win32-x64-msvc
164+
run: |
165+
cp artifacts/node-opencv-rs.win32-x64-msvc.node/node-opencv-rs.win32-x64-msvc.node npm/win32-x64-msvc/
166+
cd npm/win32-x64-msvc
167+
npm publish --access public
168+
env:
169+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
170+
171+
- name: Publish main package
172+
run: npm publish --access public
173+
env:
174+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/windows.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Windows Build
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
runs-on: windows-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Setup Rust
17+
uses: dtolnay/rust-toolchain@stable
18+
19+
- name: Set up Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '22'
23+
24+
- name: Download and Install OpenCV
25+
shell: pwsh
26+
run: |
27+
$opencvVersion = "4.10.0"
28+
$url = "https://github.com/opencv/opencv/releases/download/$opencvVersion/opencv-$opencvVersion-windows.exe"
29+
Invoke-WebRequest -Uri $url -OutFile "opencv.exe" -TimeoutSec 600
30+
Start-Process -FilePath "opencv.exe" -ArgumentList "-y -o`"D:`"" -Wait
31+
echo "OPENCV_INCLUDE_PATHS=D:\opencv\build\include" | Out-File -FilePath $env:GITHUB_ENV -Append
32+
echo "OPENCV_LINK_LIBS=opencv_world4100" | Out-File -FilePath $env:GITHUB_ENV -Append
33+
echo "OPENCV_LINK_PATHS=D:\opencv\build\x64\vc16\lib" | Out-File -FilePath $env:GITHUB_ENV -Append
34+
echo "D:\opencv\build\x64\vc16\bin" | Out-File -FilePath $env:GITHUB_PATH -Append
35+
36+
- name: Install npm dependencies
37+
run: npm install --ignore-scripts
38+
39+
- name: Build
40+
run: npm run build
41+
42+
- name: Smoke test
43+
shell: bash
44+
run: |
45+
node -e 'const cv = require("./main.js"); const info = cv.getBuildInformation(); if (!info.includes("OpenCV")) process.exit(1); console.log("OK:", info.split("\n")[0]);'

0 commit comments

Comments
 (0)