Skip to content

Commit 295904a

Browse files
committed
Add GitHub Actions workflow for Rust tests
Adds three CI jobs: - rust-tests: Pure Rust workspace tests on Linux, macOS, Windows - rust-ffi-tests: C++ test suite running against Rust FFI on Linux, macOS - rust-lint: Clippy and rustfmt checks
1 parent 4924fef commit 295904a

1 file changed

Lines changed: 140 additions & 0 deletions

File tree

.github/workflows/rust.yml

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
name: Rust
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
push:
8+
branches:
9+
- 'main'
10+
pull_request:
11+
types: [opened, synchronize, reopened]
12+
13+
env:
14+
CARGO_TERM_COLOR: always
15+
16+
jobs:
17+
# Pure Rust tests
18+
rust-tests:
19+
name: Rust Tests
20+
runs-on: ${{ matrix.os }}
21+
strategy:
22+
matrix:
23+
os: [ubuntu-latest, macos-latest, windows-latest]
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
with:
28+
fetch-depth: '0'
29+
30+
- name: Download SPIRV-Headers
31+
run: python3 utils/git-sync-deps
32+
33+
- name: Install Rust
34+
uses: dtolnay/rust-toolchain@stable
35+
36+
- name: Cache Cargo
37+
uses: actions/cache@v4
38+
with:
39+
path: |
40+
~/.cargo/bin/
41+
~/.cargo/registry/index/
42+
~/.cargo/registry/cache/
43+
~/.cargo/git/db/
44+
rust/target/
45+
key: ${{ runner.os }}-cargo-${{ hashFiles('rust/Cargo.lock') }}
46+
restore-keys: |
47+
${{ runner.os }}-cargo-
48+
49+
- name: Build Rust workspace
50+
working-directory: rust
51+
run: cargo build --workspace
52+
53+
- name: Run Rust tests
54+
working-directory: rust
55+
run: cargo test --workspace
56+
57+
# Rust FFI pretending to be C++ - runs C++ test suite against Rust implementation
58+
rust-ffi-tests:
59+
name: Rust FFI (C++ Test Suite)
60+
runs-on: ${{ matrix.os }}
61+
strategy:
62+
matrix:
63+
os: [ubuntu-latest, macos-latest]
64+
65+
steps:
66+
- uses: actions/checkout@v4
67+
with:
68+
fetch-depth: '0'
69+
70+
- name: Download dependencies
71+
run: python3 utils/git-sync-deps
72+
73+
- name: Install Rust
74+
uses: dtolnay/rust-toolchain@stable
75+
76+
- name: Cache Cargo
77+
uses: actions/cache@v4
78+
with:
79+
path: |
80+
~/.cargo/bin/
81+
~/.cargo/registry/index/
82+
~/.cargo/registry/cache/
83+
~/.cargo/git/db/
84+
rust/target/
85+
key: ${{ runner.os }}-cargo-ffi-${{ hashFiles('rust/Cargo.lock') }}
86+
restore-keys: |
87+
${{ runner.os }}-cargo-ffi-
88+
89+
- name: Configure CMake
90+
run: |
91+
cmake -B build \
92+
-DSPIRV_BUILD_FUZZER=OFF \
93+
-DSPIRV_USE_RUST_FFI=ON \
94+
-DCMAKE_BUILD_TYPE=Release
95+
96+
- name: Build C++ with Rust FFI
97+
run: cmake --build build --config Release -j $(nproc 2>/dev/null || sysctl -n hw.ncpu)
98+
99+
- name: Run C++ tests (backed by Rust)
100+
working-directory: build
101+
run: ctest --output-on-failure -j $(nproc 2>/dev/null || sysctl -n hw.ncpu)
102+
103+
# Clippy and format checks
104+
rust-lint:
105+
name: Rust Lint
106+
runs-on: ubuntu-latest
107+
108+
steps:
109+
- uses: actions/checkout@v4
110+
with:
111+
fetch-depth: '0'
112+
113+
- name: Download SPIRV-Headers
114+
run: python3 utils/git-sync-deps
115+
116+
- name: Install Rust
117+
uses: dtolnay/rust-toolchain@stable
118+
with:
119+
components: clippy, rustfmt
120+
121+
- name: Cache Cargo
122+
uses: actions/cache@v4
123+
with:
124+
path: |
125+
~/.cargo/bin/
126+
~/.cargo/registry/index/
127+
~/.cargo/registry/cache/
128+
~/.cargo/git/db/
129+
rust/target/
130+
key: ${{ runner.os }}-cargo-lint-${{ hashFiles('rust/Cargo.lock') }}
131+
restore-keys: |
132+
${{ runner.os }}-cargo-lint-
133+
134+
- name: Check formatting
135+
working-directory: rust
136+
run: cargo fmt --all -- --check
137+
138+
- name: Run Clippy
139+
working-directory: rust
140+
run: cargo clippy --workspace --all-targets -- -D warnings

0 commit comments

Comments
 (0)