Skip to content

Commit ff8fd76

Browse files
authored
fix(tauri-build): rerun if assets or icons change (#4910)
1 parent 0e925fd commit ff8fd76

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

.changes/build-codegen-rerun.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-build": patch
3+
---
4+
5+
Rerun codegen if assets or icons change.

core/tauri-build/src/codegen/context.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::{
1010
path::PathBuf,
1111
};
1212
use tauri_codegen::{context_codegen, ContextData};
13+
use tauri_utils::config::{AppUrl, WindowUrl};
1314

1415
// TODO docs
1516
/// A builder for generating a Tauri application context during compile time.
@@ -92,6 +93,40 @@ impl CodegenContext {
9293
/// Non-panicking [`Self::build`]
9394
pub fn try_build(self) -> Result<PathBuf> {
9495
let (config, config_parent) = tauri_codegen::get_config(&self.config_path)?;
96+
97+
// rerun if changed
98+
let app_url = if self.dev {
99+
&config.build.dev_path
100+
} else {
101+
&config.build.dist_dir
102+
};
103+
match app_url {
104+
AppUrl::Url(WindowUrl::App(p)) => {
105+
println!("cargo:rerun-if-changed={}", config_parent.join(p).display());
106+
}
107+
AppUrl::Files(files) => {
108+
for path in files {
109+
println!(
110+
"cargo:rerun-if-changed={}",
111+
config_parent.join(path).display()
112+
);
113+
}
114+
}
115+
_ => (),
116+
}
117+
for icon in &config.tauri.bundle.icon {
118+
println!(
119+
"cargo:rerun-if-changed={}",
120+
config_parent.join(icon).display()
121+
);
122+
}
123+
if let Some(tray_icon) = config.tauri.system_tray.as_ref().map(|t| &t.icon_path) {
124+
println!(
125+
"cargo:rerun-if-changed={}",
126+
config_parent.join(tray_icon).display()
127+
);
128+
}
129+
95130
let code = context_codegen(ContextData {
96131
dev: self.dev,
97132
config,

core/tauri-build/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,6 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
293293
)?;
294294
}
295295

296-
for icon in &config.tauri.bundle.icon {
297-
println!("cargo:rerun-if-changed={}", icon);
298-
}
299-
300296
#[allow(unused_mut, clippy::redundant_clone)]
301297
let mut resources = config.tauri.bundle.resources.clone().unwrap_or_default();
302298
#[cfg(windows)]

0 commit comments

Comments
 (0)