-
Notifications
You must be signed in to change notification settings - Fork 11
306 lines (247 loc) · 11.6 KB
/
rust-test.yml
File metadata and controls
306 lines (247 loc) · 11.6 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
name: Rust test / linting
env:
TRIGGER_ON_PR_PUSH: true # Set to true to enable triggers on PR pushes
RUSTFLAGS: -C debuginfo=0
RUST_BACKTRACE: 1
on:
push:
branches: [ "master", "development", "dev" ]
paths:
- 'crates/**'
- 'examples/**'
- 'julia/pecos-julia-ffi/**'
- 'Cargo.toml'
- '.github/workflows/rust-test.yml'
- '.pre-commit-config.yaml'
pull_request:
branches: [ "master", "development", "dev" ]
paths:
- 'crates/**'
- 'examples/**'
- 'julia/pecos-julia-ffi/**'
- 'Cargo.toml'
- '.github/workflows/rust-test.yml'
- '.pre-commit-config.yaml'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
rust-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust (for local testing)
run: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
export PATH="$HOME/.cargo/bin:$PATH"
- name: Set up Rust
run: rustup override set stable && rustup update
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref_name == 'master' || github.ref_name == 'development' || github.ref_name == 'dev' }}
- name: Install LLVM 14.0.6 using pecos-llvm
run: |
echo "Installing LLVM using pecos-llvm-utils..."
cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- install
echo "Setting LLVM environment variables..."
export PECOS_LLVM=$(cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- find 2>/dev/null)
export LLVM_SYS_140_PREFIX="$PECOS_LLVM"
echo "PECOS_LLVM=$PECOS_LLVM" >> $GITHUB_ENV
echo "LLVM_SYS_140_PREFIX=$LLVM_SYS_140_PREFIX" >> $GITHUB_ENV
echo "Verifying LLVM installation..."
cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- check
- name: Install rustfmt
run: rustup component add rustfmt
- name: Check formatting
run: cargo fmt --all -- --check
- name: Install clippy
run: rustup component add clippy
- name: Run clippy
run: |
echo "Running clippy with all features (including LLVM)..."
cargo clippy --workspace --exclude pecos --exclude pecos-quest --all-targets --all-features -- -D warnings
echo "Running clippy on pecos with all non-GPU features..."
cargo clippy -p pecos --all-targets --features "llvm,selene,qasm,phir,all-simulators" -- -D warnings
echo "Running clippy on pecos-quest with CPU features only..."
cargo clippy -p pecos-quest --all-targets --features "cpu" -- -D warnings
rust-lint-no-llvm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust (for local testing)
run: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
export PATH="$HOME/.cargo/bin:$PATH"
- name: Set up Rust
run: rustup override set stable && rustup update
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref_name == 'master' || github.ref_name == 'development' || github.ref_name == 'dev' }}
- name: Install rustfmt
run: rustup component add rustfmt
- name: Check formatting
run: cargo fmt --all -- --check
- name: Install clippy
run: rustup component add clippy
- name: Run clippy without LLVM features
run: |
echo "Running clippy without LLVM features..."
# Use --manifest-path to avoid workspace resolution pulling in LLVM dependencies
echo "Testing pecos-core..."
cd crates/pecos-core && cargo clippy --all-targets -- -D warnings && cd ../..
echo "Testing pecos-engines..."
cd crates/pecos-engines && cargo clippy --all-targets -- -D warnings && cd ../..
echo "Testing pecos-qsim..."
cd crates/pecos-qsim && cargo clippy --all-targets -- -D warnings && cd ../..
echo "Testing pecos-programs..."
cd crates/pecos-programs && cargo clippy --all-targets -- -D warnings && cd ../..
echo "Testing pecos-rng..."
cd crates/pecos-rng && cargo clippy --all-targets -- -D warnings && cd ../..
echo "Testing pecos-qasm..."
cd crates/pecos-qasm && cargo clippy --all-targets -- -D warnings && cd ../..
echo "Testing pecos-phir-json..."
cd crates/pecos-phir-json && cargo clippy --all-targets -- -D warnings && cd ../..
echo "Testing pecos-qis-ffi-types..."
cd crates/pecos-qis-ffi-types && cargo clippy --all-targets -- -D warnings && cd ../..
# Test the main pecos crate without default features
echo "Testing pecos without default features..."
cd crates/pecos && cargo clippy --all-targets --no-default-features -- -D warnings && cd ../..
# Note: Skipping crates that require LLVM:
# - pecos-hugr-qis (HUGR to LLVM compiler)
# - pecos-qis-core (has inkwell dependency)
# - pecos-qis-selene (depends on pecos-qis-core with llvm feature)
# - pecos-phir (when hugr feature is enabled, depends on tket-qsystem which pulls in LLVM)
echo "Successfully tested core crates without LLVM!"
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install pre-commit
run: pip install pre-commit
- name: Run pre-commit
run: pre-commit run --all-files --show-diff-on-failure
rust-test:
needs: [pre-commit, rust-lint]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- name: Install Rust (for local testing)
if: matrix.os == 'windows-latest'
run: |
curl -sSf -o rustup-init.exe https://win.rustup.rs
./rustup-init.exe -y --default-toolchain stable --profile minimal
echo "$HOME\.cargo\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
$env:Path += ";$HOME\.cargo\bin"
- name: Install Rust (for local testing)
if: matrix.os != 'windows-latest'
run: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
export PATH="$HOME/.cargo/bin:$PATH"
- name: Set up Rust
run: rustup show
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref_name == 'master' || github.ref_name == 'development' || github.ref_name == 'dev' }}
- name: Install LLVM 14.0.6 using pecos-llvm (Unix)
if: matrix.os != 'windows-latest'
run: |
echo "Installing LLVM using pecos-llvm-utils..."
cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- install
echo "Setting LLVM environment variables..."
export PECOS_LLVM=$(cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- find 2>/dev/null)
export LLVM_SYS_140_PREFIX="$PECOS_LLVM"
echo "PECOS_LLVM=$PECOS_LLVM" >> $GITHUB_ENV
echo "LLVM_SYS_140_PREFIX=$LLVM_SYS_140_PREFIX" >> $GITHUB_ENV
echo "Verifying LLVM installation..."
cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- check
- name: Install LLVM 14.0.6 using pecos-llvm (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
Write-Host "Installing LLVM using pecos-llvm-utils..."
cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- install
Write-Host "Setting LLVM environment variables..."
$env:PECOS_LLVM = (cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- find 2>$null)
$env:LLVM_SYS_140_PREFIX = $env:PECOS_LLVM
"PECOS_LLVM=$env:PECOS_LLVM" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"LLVM_SYS_140_PREFIX=$env:LLVM_SYS_140_PREFIX" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
Write-Host "Verifying LLVM installation..."
cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- check
- name: Set up Visual Studio environment on Windows
if: matrix.os == 'windows-latest'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64
- name: Compile tests (macOS)
if: matrix.os == 'macos-latest'
run: |
# CRITICAL: Prevent Homebrew library paths from being used during linking
# This fixes the "@rpath/libunwind.1.dylib" runtime error on macOS
# Reference: https://github.com/rust-lang/rust/issues/135372
unset LIBRARY_PATH
unset LD_LIBRARY_PATH
unset DYLD_LIBRARY_PATH
unset DYLD_FALLBACK_LIBRARY_PATH
unset PKG_CONFIG_PATH
export LIBRARY_PATH=/usr/lib
echo "RUSTFLAGS: $RUSTFLAGS"
cargo test --no-run --workspace --exclude pecos-quest --exclude pecos-decoders --features llvm
cargo test --no-run -p pecos-quest --features cpu
cargo test --no-run -p pecos-decoders --all-features
- name: Compile tests (Linux/Windows)
if: matrix.os != 'macos-latest'
run: |
cargo test --no-run --workspace --exclude pecos-quest --exclude pecos-decoders --features llvm
cargo test --no-run -p pecos-quest --features cpu
cargo test --no-run -p pecos-decoders --all-features
- name: Run tests (macOS)
if: matrix.os == 'macos-latest'
run: |
# CRITICAL: Prevent Homebrew library paths from being used during linking
# This fixes the "@rpath/libunwind.1.dylib" runtime error on macOS
# Reference: https://github.com/rust-lang/rust/issues/135372
unset LIBRARY_PATH
unset LD_LIBRARY_PATH
unset DYLD_LIBRARY_PATH
unset DYLD_FALLBACK_LIBRARY_PATH
unset PKG_CONFIG_PATH
export LIBRARY_PATH=/usr/lib
cargo test --workspace --exclude pecos-quest --exclude pecos-decoders --features llvm
cargo test -p pecos-quest --features cpu
cargo test -p pecos-decoders --all-features
- name: Run tests (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
cargo test --workspace --exclude pecos-quest --exclude pecos-decoders --features llvm
cargo test -p pecos-quest --features cpu
cargo test -p pecos-decoders --all-features
- name: Run tests (Windows)
if: matrix.os == 'windows-latest'
run: |
# Run all non-doctest tests
cargo test --workspace --exclude pecos-quest --exclude pecos-decoders --exclude pecos-rslib --features llvm --lib --bins --tests --examples
cargo test -p pecos-quest --features cpu --lib --bins --tests --examples
cargo test -p pecos-decoders --all-features --lib --bins --tests --examples
# For Windows, we need to run doctests for the pecos crate specially
# to ensure they run from the crate directory
cd crates/pecos
cargo test --doc --features llvm
cd ../..
# Run doctests for other crates normally
cargo test --workspace --exclude pecos-quest --exclude pecos-decoders --exclude pecos-rslib --exclude pecos --features llvm --doc
cargo test -p pecos-quest --doc
cargo test -p pecos-decoders --all-features --doc