From 4045bf90689773d894dcc90f37780728e453cb27 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 7 Feb 2025 14:31:06 +0000 Subject: [PATCH] Support running on miri --- psm/build.rs | 8 +++++++- src/lib.rs | 10 ++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/psm/build.rs b/psm/build.rs index 4f3121f..0201308 100644 --- a/psm/build.rs +++ b/psm/build.rs @@ -5,7 +5,6 @@ fn find_assembly( env: &str, masm: bool, ) -> Option<(&'static str, bool)> { - println!("cargo:rustc-check-cfg=cfg(switchable_stack,asm,link_asm)"); match (arch, endian, os, env) { // The implementations for stack switching exist, but, officially, doing so without Fibers // is not supported in Windows. For x86_64 the implementation actually works locally, @@ -58,6 +57,13 @@ fn find_assembly( fn main() { use std::env::var; + println!("cargo:rustc-check-cfg=cfg(switchable_stack,asm,link_asm)"); + + if var("CARGO_CFG_MIRI").is_ok() { + // Miri doesn't have a stack limit and the inline asm wouldn't work on miri anyway. + return; + } + let arch = var("CARGO_CFG_TARGET_ARCH").unwrap(); let env = var("CARGO_CFG_TARGET_ENV").unwrap(); let os = var("CARGO_CFG_TARGET_OS").unwrap(); diff --git a/src/lib.rs b/src/lib.rs index 389e6d1..9f61d7f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -268,14 +268,20 @@ psm_stack_manipulation! { no { #[cfg(not(windows))] fn _grow(stack_size: usize, callback: &mut dyn FnMut()) { - drop(stack_size); + let _ = stack_size; callback(); } } } cfg_if! { - if #[cfg(windows)] { + if #[cfg(miri)] { + // Miri doesn't have a stack limit + #[inline(always)] + unsafe fn guess_os_stack_limit() -> Option { + None + } + } else if #[cfg(windows)] { use std::ptr; use std::io; use libc::c_void;