From 66f3198f506620f1daa3afafa46541ad3cf30ec3 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 30 May 2023 23:47:14 -0500 Subject: [PATCH] desktop/web: Increase stack size on Windows and wasm This works around a stack overflow with Bloonts Tower Defense 5, where we have over 400 stack frames at once due to deep `construct_frame` recursion in `goto` execution. --- desktop/build.rs | 8 ++++++++ web/build.rs | 7 +++++++ 2 files changed, 15 insertions(+) create mode 100644 web/build.rs diff --git a/desktop/build.rs b/desktop/build.rs index 137242c8c..39a9cd10d 100644 --- a/desktop/build.rs +++ b/desktop/build.rs @@ -24,6 +24,14 @@ fn main() -> Result<(), Box> { } println!("cargo:rustc-env=CFG_RELEASE_CHANNEL={channel}"); + // Some SWFS have a large amount of recursion (particularly + // around `goto`s). Increase the stack size on Windows + // accommodate this (the default on Linux is high enough). We + // do the same thing for wasm in web/build.rs. + if std::env::var("TARGET").unwrap().contains("windows") { + println!("cargo:rustc-link-arg=/STACK:4000000"); + } + Ok(()) } diff --git a/web/build.rs b/web/build.rs new file mode 100644 index 000000000..17bf70be1 --- /dev/null +++ b/web/build.rs @@ -0,0 +1,7 @@ +fn main() { + // See 'desktop/build.rs' for more information. + if std::env::var("TARGET").unwrap().contains("wasm") { + println!("cargo:rustc-link-arg=-z"); + println!("cargo:rustc-link-arg=stack-size=2000000"); + } +}