From cb80e24f2edeb823fc8bb30ac892eb0c08f0cc1b Mon Sep 17 00:00:00 2001 From: Tony Date: Sat, 12 Apr 2025 23:45:29 +0800 Subject: [PATCH 1/4] Fix invoke handler stack overflow --- crates/tauri-macros/src/command/wrapper.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/tauri-macros/src/command/wrapper.rs b/crates/tauri-macros/src/command/wrapper.rs index 768cb8c62110..57f4388f1bc0 100644 --- a/crates/tauri-macros/src/command/wrapper.rs +++ b/crates/tauri-macros/src/command/wrapper.rs @@ -281,7 +281,7 @@ pub fn wrapper(attributes: TokenStream, item: TokenStream) -> TokenStream { #[doc(hidden)] macro_rules! #wrapper { // double braces because the item is expected to be a block expression - ($path:path, $invoke:ident) => {{ + ($path:path, $invoke:ident) => {(move || { #[allow(unused_imports)] use #root::ipc::private::*; // prevent warnings when the body is a `compile_error!` or if the command has no arguments @@ -291,7 +291,7 @@ pub fn wrapper(attributes: TokenStream, item: TokenStream) -> TokenStream { #maybe_span #body - }}; + })()}; } // allow the macro to be resolved with the same path as the command function From e22d6e810de9c0c5ea4447139664c475c10d83fc Mon Sep 17 00:00:00 2001 From: Tony Date: Sun, 13 Apr 2025 17:29:30 +0800 Subject: [PATCH 2/4] Format and inline iife in release build --- crates/tauri-macros/src/command/wrapper.rs | 31 +++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/crates/tauri-macros/src/command/wrapper.rs b/crates/tauri-macros/src/command/wrapper.rs index 57f4388f1bc0..8cee42e11132 100644 --- a/crates/tauri-macros/src/command/wrapper.rs +++ b/crates/tauri-macros/src/command/wrapper.rs @@ -280,18 +280,25 @@ pub fn wrapper(attributes: TokenStream, item: TokenStream) -> TokenStream { #maybe_macro_export #[doc(hidden)] macro_rules! #wrapper { - // double braces because the item is expected to be a block expression - ($path:path, $invoke:ident) => {(move || { - #[allow(unused_imports)] - use #root::ipc::private::*; - // prevent warnings when the body is a `compile_error!` or if the command has no arguments - #[allow(unused_variables)] - let #root::ipc::Invoke { message: #message, resolver: #resolver, acl: #acl } = $invoke; - - #maybe_span - - #body - })()}; + // double braces because the item is expected to be a block expression + ($path:path, $invoke:ident) => { + { + // The IIFE here is for preventing stack overflow on Windows debug build, + // see https://github.com/tauri-apps/tauri/issues/12488 + #[cfg_attr(not(debug_assertions), inline(always))] + move || { + #[allow(unused_imports)] + use #root::ipc::private::*; + // prevent warnings when the body is a `compile_error!` or if the command has no arguments + #[allow(unused_variables)] + let #root::ipc::Invoke { message: #message, resolver: #resolver, acl: #acl } = $invoke; + + #maybe_span + + #body + } + }() + }; } // allow the macro to be resolved with the same path as the command function From 852710a5769e4f9daafe5855c49ccb2cd9162e1c Mon Sep 17 00:00:00 2001 From: Tony Date: Sun, 13 Apr 2025 17:31:14 +0800 Subject: [PATCH 3/4] Add change file --- .changes/invoke-handler-stack-overflow-on-debug.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changes/invoke-handler-stack-overflow-on-debug.md diff --git a/.changes/invoke-handler-stack-overflow-on-debug.md b/.changes/invoke-handler-stack-overflow-on-debug.md new file mode 100644 index 000000000000..5f89ae2f1a38 --- /dev/null +++ b/.changes/invoke-handler-stack-overflow-on-debug.md @@ -0,0 +1,5 @@ +--- +tauri: patch:bug +--- + +Fix large number of commands with large structs as parameters causing stack overflow on debug build on Windows From e05c624a7974b271ce9c4d03c8ea01a90b91fbf9 Mon Sep 17 00:00:00 2001 From: Tony Date: Sun, 13 Apr 2025 17:36:25 +0800 Subject: [PATCH 4/4] The comment should be one level up --- crates/tauri-macros/src/command/wrapper.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/tauri-macros/src/command/wrapper.rs b/crates/tauri-macros/src/command/wrapper.rs index 8cee42e11132..683e9f6f5f93 100644 --- a/crates/tauri-macros/src/command/wrapper.rs +++ b/crates/tauri-macros/src/command/wrapper.rs @@ -282,9 +282,9 @@ pub fn wrapper(attributes: TokenStream, item: TokenStream) -> TokenStream { macro_rules! #wrapper { // double braces because the item is expected to be a block expression ($path:path, $invoke:ident) => { + // The IIFE here is for preventing stack overflow on Windows debug build, + // see https://github.com/tauri-apps/tauri/issues/12488 { - // The IIFE here is for preventing stack overflow on Windows debug build, - // see https://github.com/tauri-apps/tauri/issues/12488 #[cfg_attr(not(debug_assertions), inline(always))] move || { #[allow(unused_imports)]