From 88bc357325ba278527d8cba956e828f5744c8a34 Mon Sep 17 00:00:00 2001 From: chip Date: Fri, 23 Aug 2024 13:46:23 +0200 Subject: [PATCH] fix: generate `Context` inside a thread (#10734) * generate `Context` inside a thread fix #9882 this is a workaround for #9882 due to windows having a small stack size for the main thread (1MiB) versus other platforms which have 8MiB. the true fix would be to lower the generated code stack size, but with lots a plugins, there are lots of ACL configurations. * add change file [skip ci] --------- Co-authored-by: Lucas Nogueira --- .changes/fix-context-stack-size.md | 5 +++++ core/tauri-codegen/src/context.rs | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .changes/fix-context-stack-size.md diff --git a/.changes/fix-context-stack-size.md b/.changes/fix-context-stack-size.md new file mode 100644 index 00000000000..72c2aba66d5 --- /dev/null +++ b/.changes/fix-context-stack-size.md @@ -0,0 +1,5 @@ +--- +"tauri-codegen": patch:bug +--- + +Generate context in a separate thread to prevent a stack overflow. diff --git a/core/tauri-codegen/src/context.rs b/core/tauri-codegen/src/context.rs index fd06092f301..ecbbc136023 100644 --- a/core/tauri-codegen/src/context.rs +++ b/core/tauri-codegen/src/context.rs @@ -489,7 +489,7 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult { quote!() }; - Ok(quote!({ + let context = quote!({ #[allow(unused_mut, clippy::let_and_return)] let mut context = #root::Context::new( #config, @@ -507,6 +507,22 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult { #maybe_config_parent_setter context + }); + + Ok(quote!({ + let thread = ::std::thread::Builder::new() + .name(String::from("generated tauri context creation")) + .stack_size(8 * 1024 * 1024) + .spawn(|| #context) + .expect("unable to create thread with 8MiB stack"); + + match thread.join() { + Ok(context) => context, + Err(_) => { + eprintln!("the generated Tauri `Context` panicked during creation"); + ::std::process::exit(101); + } + } })) }