diff --git a/crates/puffin-cli/src/main.rs b/crates/puffin-cli/src/main.rs index 4d6645c0ab188..7410166f2c934 100644 --- a/crates/puffin-cli/src/main.rs +++ b/crates/puffin-cli/src/main.rs @@ -1,3 +1,4 @@ +use std::env; use std::path::PathBuf; use std::process::ExitCode; use std::str::FromStr; @@ -710,9 +711,31 @@ async fn inner() -> Result { } } -#[tokio::main] -async fn main() -> ExitCode { - match inner().await { +fn tokio_main() -> Result { + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build() + .expect("Failed building the Runtime") + .block_on(inner()) +} + +fn main() -> ExitCode { + let result = if let Ok(stack_max) = env::var("PUFFIN_STACK_SIZE") { + // Artificially limit the stack size to test for stack overflows. Windows has a default stack size of 1MB, + // which is lower than the linux and mac default. + // https://learn.microsoft.com/en-us/cpp/build/reference/stack-stack-allocations?view=msvc-170 + std::thread::Builder::new() + .stack_size(stack_max.parse().expect("Invalid stack size")) + .spawn(tokio_main) + .expect("Tokio executor failed, was there a panic?") + .join() + .expect("Tokio executor failed, was there a panic?") + } else { + tokio_main() + }; + + // Wait for thread to join + match result { Ok(code) => code.into(), Err(err) => { #[allow(clippy::print_stderr)]