mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-02-06 11:22:04 +00:00
fix(codegen): Context generation with custom assets (#14883)
when custom assets are provided (`tauri::generate_context!(assets = my_assets)`) we can't use the fn inner logic directly and capture variables - we must pass them as arguments
This commit is contained in:
parent
540c5b4e59
commit
eb5d88427a
5
.changes/codegen-custom-context-assets-fix.md
Normal file
5
.changes/codegen-custom-context-assets-fix.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri-codegen": patch:bug
|
||||
---
|
||||
|
||||
Fix `tauri::Context` code generation failing with `can't capture dynamic environment in a fn item` when custom assets are provided.
|
||||
@ -453,7 +453,7 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult<TokenStream> {
|
||||
#[allow(unused_mut, clippy::let_and_return)]
|
||||
let mut context = #root::Context::new(
|
||||
#config,
|
||||
::std::boxed::Box::new(#assets),
|
||||
::std::boxed::Box::new(assets),
|
||||
#default_window_icon,
|
||||
#app_icon,
|
||||
#package_info,
|
||||
@ -468,14 +468,16 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult<TokenStream> {
|
||||
context
|
||||
});
|
||||
|
||||
Ok(quote!({
|
||||
// Wrapping in a function to make rust analyzer faster,
|
||||
// see https://github.com/tauri-apps/tauri/pull/14457
|
||||
fn inner<R: #root::Runtime>() -> #root::Context<R> {
|
||||
// Wrapping in a function to make rust analyzer faster,
|
||||
// see https://github.com/tauri-apps/tauri/pull/14457
|
||||
// We take the assets as an argument so when the caller provides custom `assets` the closure
|
||||
// does not capture from the caller's scope ("can't capture dynamic environment in a fn item").
|
||||
let output = quote!({
|
||||
fn inner<R: #root::Runtime, A: #root::Assets<R> + 'static>(assets: A) -> #root::Context<R> {
|
||||
let thread = ::std::thread::Builder::new()
|
||||
.name(String::from("generated tauri context creation"))
|
||||
.stack_size(8 * 1024 * 1024)
|
||||
.spawn(|| #context)
|
||||
.spawn(move || #context)
|
||||
.expect("unable to create thread with 8MiB stack");
|
||||
|
||||
match thread.join() {
|
||||
@ -486,8 +488,10 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult<TokenStream> {
|
||||
}
|
||||
}
|
||||
}
|
||||
inner()
|
||||
}))
|
||||
inner(#assets)
|
||||
});
|
||||
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
fn find_icon(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user