Skip to content
Open
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
119 changes: 119 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: Rust CI

on:
push:
branches: [ main, develop ]
paths: [ 'bindings/rust/**' ]
pull_request:
branches: [ main, develop ]
paths: [ 'bindings/rust/**' ]

env:
CARGO_TERM_COLOR: always

jobs:
build:
name: Build and Test
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake build-essential pkg-config

- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
components: clippy, rustfmt

- name: Build C library
run: |
mkdir -p build/Debug
cd build/Debug
cmake -DCMAKE_BUILD_TYPE=Debug -DCCAP_BUILD_EXAMPLES=ON -DCCAP_BUILD_TESTS=OFF ../..
make -j$(nproc)

- name: Check formatting
working-directory: bindings/rust
run: cargo fmt -- --check

- name: Run clippy
working-directory: bindings/rust
run: cargo clippy --all-targets --all-features -- -D warnings

- name: Build Rust bindings
working-directory: bindings/rust
run: cargo build --verbose

- name: Run tests
working-directory: bindings/rust
run: cargo test --verbose

- name: Build examples
working-directory: bindings/rust
run: |
cargo build --example print_camera
cargo build --example minimal_example
cargo build --example capture_grab
cargo build --example capture_callback

cross-platform:
name: Cross-platform Build
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install system dependencies (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y cmake build-essential pkg-config

- name: Install system dependencies (Windows)
if: matrix.os == 'windows-latest'
run: |
choco install cmake

- name: Install system dependencies (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install cmake

- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable

- name: Build C library (Ubuntu/macOS)
if: matrix.os != 'windows-latest'
run: |
mkdir -p build/Debug
cd build/Debug
cmake -DCMAKE_BUILD_TYPE=Debug -DCCAP_BUILD_EXAMPLES=ON -DCCAP_BUILD_TESTS=OFF ../..
make -j$(nproc || echo 4)

- name: Build C library (Windows)
if: matrix.os == 'windows-latest'
run: |
mkdir build/Debug
cd build/Debug
cmake -DCMAKE_BUILD_TYPE=Debug -DCCAP_BUILD_EXAMPLES=ON -DCCAP_BUILD_TESTS=OFF ../..
cmake --build . --config Debug

- name: Build Rust bindings
working-directory: bindings/rust
run: cargo build --verbose

- name: Run tests
working-directory: bindings/rust
run: cargo test --verbose
100 changes: 100 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,106 @@
"command": ".\\4-example_with_glfw_c.exe",
"problemMatcher": "$msCompile"
}
},
{
"label": "Run Rust print_camera",
"type": "shell",
"command": "cargo",
"args": [
"run",
"--example",
"print_camera"
],
"options": {
"cwd": "${workspaceFolder}/bindings/rust"
},
"group": "build",
"problemMatcher": "$rustc"
},
{
"label": "Run Rust minimal_example",
"type": "shell",
"command": "cargo",
"args": [
"run",
"--example",
"minimal_example"
],
"options": {
"cwd": "${workspaceFolder}/bindings/rust"
},
"group": "build",
"problemMatcher": "$rustc"
},
{
"label": "Run Rust capture_grab",
"type": "shell",
"command": "cargo",
"args": [
"run",
"--example",
"capture_grab"
],
"options": {
"cwd": "${workspaceFolder}/bindings/rust"
},
"group": "build",
"problemMatcher": "$rustc"
},
{
"label": "Run Rust capture_callback",
"type": "shell",
"command": "cargo",
"args": [
"run",
"--example",
"capture_callback"
],
"options": {
"cwd": "${workspaceFolder}/bindings/rust"
},
"group": "build",
"problemMatcher": "$rustc"
},
{
"label": "Build Rust Bindings",
"type": "shell",
"command": "cargo",
"args": [
"build"
],
"options": {
"cwd": "${workspaceFolder}/bindings/rust"
},
"group": "build",
"problemMatcher": "$rustc"
},
{
"label": "Build Rust Examples",
"type": "shell",
"command": "cargo",
"args": [
"build",
"--examples"
],
"options": {
"cwd": "${workspaceFolder}/bindings/rust"
},
"group": "build",
"problemMatcher": "$rustc"
},
{
"label": "Test Rust Bindings",
"type": "shell",
"command": "cargo",
"args": [
"test"
],
"options": {
"cwd": "${workspaceFolder}/bindings/rust"
},
"group": "build",
"problemMatcher": "$rustc"
}
]
}
3 changes: 2 additions & 1 deletion bindings/rust/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
target/
target/
image_capture/
4 changes: 3 additions & 1 deletion bindings/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ fn main() {

#[cfg(target_os = "linux")]
{
println!("cargo:rustc-link-lib=v4l2");
// v4l2 might not be available on all systems
// println!("cargo:rustc-link-lib=v4l2");
println!("cargo:rustc-link-lib=stdc++");
}

#[cfg(target_os = "windows")]
Expand Down
82 changes: 0 additions & 82 deletions bindings/rust/examples/async_capture.rs

This file was deleted.

Loading