Skip to content

Commit 690146e

Browse files
fix(macros): invoke handler stack overflow (#13217)
* Fix invoke handler stack overflow * Format and inline iife in release build * Add change file * The comment should be one level up
1 parent f888502 commit 690146e

2 files changed

Lines changed: 24 additions & 12 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
tauri: patch:bug
3+
---
4+
5+
Fix large number of commands with large structs as parameters causing stack overflow on debug build on Windows

crates/tauri-macros/src/command/wrapper.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -280,18 +280,25 @@ pub fn wrapper(attributes: TokenStream, item: TokenStream) -> TokenStream {
280280
#maybe_macro_export
281281
#[doc(hidden)]
282282
macro_rules! #wrapper {
283-
// double braces because the item is expected to be a block expression
284-
($path:path, $invoke:ident) => {{
285-
#[allow(unused_imports)]
286-
use #root::ipc::private::*;
287-
// prevent warnings when the body is a `compile_error!` or if the command has no arguments
288-
#[allow(unused_variables)]
289-
let #root::ipc::Invoke { message: #message, resolver: #resolver, acl: #acl } = $invoke;
290-
291-
#maybe_span
292-
293-
#body
294-
}};
283+
// double braces because the item is expected to be a block expression
284+
($path:path, $invoke:ident) => {
285+
// The IIFE here is for preventing stack overflow on Windows debug build,
286+
// see https://github.com/tauri-apps/tauri/issues/12488
287+
{
288+
#[cfg_attr(not(debug_assertions), inline(always))]
289+
move || {
290+
#[allow(unused_imports)]
291+
use #root::ipc::private::*;
292+
// prevent warnings when the body is a `compile_error!` or if the command has no arguments
293+
#[allow(unused_variables)]
294+
let #root::ipc::Invoke { message: #message, resolver: #resolver, acl: #acl } = $invoke;
295+
296+
#maybe_span
297+
298+
#body
299+
}
300+
}()
301+
};
295302
}
296303

297304
// allow the macro to be resolved with the same path as the command function

0 commit comments

Comments
 (0)