-
Notifications
You must be signed in to change notification settings - Fork 19
164 lines (138 loc) · 4.94 KB
/
rust.yml
File metadata and controls
164 lines (138 loc) · 4.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: Rust CI
on:
push:
branches: [ main, develop ]
paths:
- 'bindings/rust/**'
- 'src/**'
- 'include/**'
- 'CMakeLists.txt'
- '.github/workflows/rust.yml'
pull_request:
branches: [ main, develop ]
paths:
- 'bindings/rust/**'
- 'src/**'
- 'include/**'
- 'CMakeLists.txt'
- '.github/workflows/rust.yml'
env:
CARGO_TERM_COLOR: always
CCAP_SKIP_CAMERA_TESTS: 1
permissions:
contents: read
jobs:
# Job 1: Static Linking (Development Mode)
# Verifies that the crate links correctly against a pre-built C++ library.
static-link:
name: Static Link (Dev)
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 libclang-dev
- name: Install system dependencies (Windows)
if: matrix.os == 'windows-latest'
run: |
choco install cmake llvm -y
- name: Configure LIBCLANG_PATH (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: echo "LIBCLANG_PATH=C:\\Program Files\\LLVM\\bin" >> $env:GITHUB_ENV
- name: Install system dependencies (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install cmake llvm
echo "LIBCLANG_PATH=$(brew --prefix llvm)/lib" >> $GITHUB_ENV
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
components: clippy, rustfmt
cache: false
# Build C++ Library (Linux/macOS)
# We build in build/Debug to match build.rs expectations for Unix Makefiles
- name: Build C library (Unix)
if: runner.os != 'Windows'
run: |
mkdir -p build/Debug
cd build/Debug
cmake -DCMAKE_BUILD_TYPE=Debug -DCCAP_BUILD_EXAMPLES=OFF -DCCAP_BUILD_TESTS=OFF ../..
cmake --build . --config Debug --parallel
# Build C++ Library (Windows)
# Build both Debug and Release versions
# MSVC is a multi-config generator, so we build to build/ and specify config at build time
- name: Build C library (Windows)
if: runner.os == 'Windows'
run: |
mkdir build
cd build
cmake -DCCAP_BUILD_EXAMPLES=OFF -DCCAP_BUILD_TESTS=OFF ..
cmake --build . --config Debug --parallel
cmake --build . --config Release --parallel
- name: Check formatting
if: matrix.os == 'ubuntu-latest'
working-directory: bindings/rust
run: cargo fmt -- --check
- name: Run clippy
if: matrix.os == 'ubuntu-latest'
working-directory: bindings/rust
run: cargo clippy --all-targets --no-default-features --features static-link -- -D warnings
- name: Build Rust bindings
working-directory: bindings/rust
run: cargo build --verbose --no-default-features --features static-link
- name: Run tests
working-directory: bindings/rust
run: cargo test --verbose --no-default-features --features static-link
# Job 2: Source Build (Distribution Mode)
# Verifies that the crate builds correctly from source using the cc crate.
# This is crucial for crates.io distribution.
build-source:
name: Build Source (Dist)
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 build-essential pkg-config
- name: Install system dependencies (macOS)
if: matrix.os == 'macos-latest'
run: brew install llvm
- name: Install system dependencies (Windows)
if: matrix.os == 'windows-latest'
run: |
choco install llvm -y
refreshenv
- name: Configure LIBCLANG_PATH (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: echo "LIBCLANG_PATH=C:\\Program Files\\LLVM\\bin" >> $env:GITHUB_ENV
- name: Configure LIBCLANG_PATH (macOS)
if: matrix.os == 'macos-latest'
run: echo "LIBCLANG_PATH=$(brew --prefix llvm)/lib" >> $GITHUB_ENV
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
cache: false
# The build.rs script should handle it via the 'build-source' feature.
- name: Build Rust bindings (Source)
working-directory: bindings/rust
# Disable default features (static-link) and enable build-source
run: cargo build --verbose --no-default-features --features build-source
- name: Run tests (Source)
working-directory: bindings/rust
run: cargo test --verbose --no-default-features --features build-source