From 0b0bc81710affc5d2c664589ecec53da313936d8 Mon Sep 17 00:00:00 2001 From: Davis Silverman Date: Mon, 11 Sep 2023 15:59:30 -0400 Subject: [PATCH] Extend context.rs to dynamically find the OUT_DIR for certain assets (#7534) Co-authored-by: Lucas Fernandes Nogueira --- core/tauri-codegen/src/context.rs | 41 +++++++++++++++++++------------ 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/core/tauri-codegen/src/context.rs b/core/tauri-codegen/src/context.rs index 778a7fc29..0ccd8cf72 100644 --- a/core/tauri-codegen/src/context.rs +++ b/core/tauri-codegen/src/context.rs @@ -350,14 +350,11 @@ pub fn context_codegen(data: ContextData) -> Result>( let width = entry.width(); let height = entry.height(); - let out_path = out_dir.join(path.file_name().unwrap()); + let icon_file_name = path.file_name().unwrap(); + let out_path = out_dir.join(icon_file_name); write_if_changed(&out_path, &rgba).map_err(|error| EmbeddedAssetsError::AssetWrite { path: path.to_owned(), error, })?; - let out_path = out_path.display().to_string(); - - let icon = quote!(Some(#root::Icon::Rgba { rgba: include_bytes!(#out_path).to_vec(), width: #width, height: #height })); + let icon_file_name = icon_file_name.to_str().unwrap(); + let icon = quote!(Some( + #root::Icon::Rgba { + rgba: include_bytes!(concat!(std::env!("OUT_DIR"), "/", #icon_file_name)).to_vec(), + width: #width, + height: #height + })); Ok(icon) } @@ -497,9 +499,10 @@ fn raw_icon>(out_dir: &Path, path: P) -> Result>( let width = reader.info().width; let height = reader.info().height; - let out_path = out_dir.join(path.file_name().unwrap()); + let icon_file_name = path.file_name().unwrap(); + let out_path = out_dir.join(icon_file_name); write_if_changed(&out_path, &buffer).map_err(|error| EmbeddedAssetsError::AssetWrite { path: path.to_owned(), error, })?; - let out_path = out_path.display().to_string(); - - let icon = quote!(Some(#root::Icon::Rgba { rgba: include_bytes!(#out_path).to_vec(), width: #width, height: #height })); + let icon_file_name = icon_file_name.to_str().unwrap(); + let icon = quote!(Some( + #root::Icon::Rgba { + rgba: include_bytes!(concat!(std::env!("OUT_DIR"), "/", #icon_file_name)).to_vec(), + width: #width, + height: #height, + } + )); Ok(icon) }