Skip to content

Commit 6b741bc

Browse files
authored
Fix Windows backend import condition to match cfg_if! logic (#137)
* Fix Windows backend import condition to match cfg_if! logic When running under Miri on Windows, the cfg_if! block in backends/mod.rs selects the fallback backend (because miri is checked first), but the conditional import at line 178 was only checking #[cfg(windows)], causing a compilation error when the windows module wasn't compiled. This fix ensures the import condition matches the cfg_if! logic by using #[cfg(all(windows, not(miri)))] instead of #[cfg(windows)], so the windows backend is only imported when it's actually compiled. Fixes compilation error: could not find 'windows' in 'backends' * Add Miri testing to CI workflow Adds a new miri-test job that runs Miri tests on Ubuntu, Windows, and macOS for both stacker and psm manifests. This will help catch conditional compilation issues like the one fixed in the previous commit. * Limit Miri tests to stacker crate only The psm crate has test compilation issues unrelated to this fix. Focus Miri testing on the main stacker crate where the cfg condition fix applies. * Skip heavy recursion tests under Miri Deep recursion tests are too slow under Miri's interpreter. These tests are skipped under Miri while still validating that the code compiles correctly (which was the main goal - catching the cfg condition mismatch). * Update Miri test conditions in smoke.rs Modified the deep test to include Miri in the target architecture check, allowing for better handling of recursion limits under Miri. This change ensures that the test is appropriately limited when running in the Miri environment, addressing performance concerns.
1 parent a9fc568 commit 6b741bc

4 files changed

Lines changed: 27 additions & 3 deletions

File tree

.github/workflows/test.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,25 @@ jobs:
397397
echo "${{ runner.tool_cache }}/wasmtime-v24.0.0-x86_64-linux" >> $GITHUB_PATH
398398
echo "CARGO_TARGET_WASM32_WASIP1_RUNNER=wasmtime run --" >> $GITHUB_ENV
399399
- run: cargo test --target wasm32-wasip1 --all -- --nocapture
400+
401+
miri-test:
402+
name: Test stacker with Miri on ${{ matrix.os }}
403+
runs-on: ${{ matrix.os }}
404+
strategy:
405+
fail-fast: false
406+
matrix:
407+
os: [ubuntu-latest, windows-latest, macos-latest]
408+
timeout-minutes: 10
409+
steps:
410+
- uses: actions/checkout@v4
411+
- name: Install Rust nightly with Miri
412+
uses: actions-rs/toolchain@v1
413+
with:
414+
toolchain: nightly
415+
profile: minimal
416+
components: miri
417+
default: true
418+
- name: Setup Miri
419+
run: cargo miri setup
420+
- name: Test with Miri
421+
run: cargo miri test -- --nocapture

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ psm_stack_manipulation! {
169169
}
170170

171171
no {
172-
#[cfg(not(windows))]
172+
#[cfg(not(all(windows, not(miri))))]
173173
fn _grow(stack_size: usize, callback: &mut dyn FnMut()) {
174174
let _ = stack_size;
175175
callback();
176176
}
177-
#[cfg(windows)]
177+
#[cfg(all(windows, not(miri)))]
178178
use backends::windows::_grow;
179179
}
180180
}

tests/simple.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ fn recurse(n: usize) {
1818
}
1919

2020
#[test]
21+
#[cfg_attr(miri, ignore)] // Too slow under Miri's interpreter
2122
fn foo() {
2223
let limit = if cfg!(target_arch = "wasm32") {
2324
2000

tests/smoke.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn deep() {
2121
}
2222
}
2323

24-
let limit = if cfg!(target_arch = "wasm32") {
24+
let limit = if cfg!(target_arch = "wasm32") || cfg!(miri) {
2525
2000
2626
} else {
2727
256 * 1024
@@ -31,6 +31,7 @@ fn deep() {
3131

3232
#[test]
3333
#[cfg_attr(target_arch = "wasm32", ignore)]
34+
#[cfg_attr(miri, ignore)] // Too slow under Miri's interpreter
3435
fn panic() {
3536
fn foo(n: usize, s: &mut [u8]) {
3637
__stacker_black_box(s.as_ptr());

0 commit comments

Comments
 (0)