Skip to content

Commit

Permalink
fix(tauri-build): rerun if assets or icons change (#4910)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Aug 10, 2022
1 parent 0e925fd commit ff8fd76
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changes/build-codegen-rerun.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-build": patch
---

Rerun codegen if assets or icons change.
35 changes: 35 additions & 0 deletions core/tauri-build/src/codegen/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{
path::PathBuf,
};
use tauri_codegen::{context_codegen, ContextData};
use tauri_utils::config::{AppUrl, WindowUrl};

// TODO docs
/// A builder for generating a Tauri application context during compile time.
Expand Down Expand Up @@ -92,6 +93,40 @@ impl CodegenContext {
/// Non-panicking [`Self::build`]
pub fn try_build(self) -> Result<PathBuf> {
let (config, config_parent) = tauri_codegen::get_config(&self.config_path)?;

// rerun if changed
let app_url = if self.dev {
&config.build.dev_path
} else {
&config.build.dist_dir
};
match app_url {
AppUrl::Url(WindowUrl::App(p)) => {
println!("cargo:rerun-if-changed={}", config_parent.join(p).display());
}
AppUrl::Files(files) => {
for path in files {
println!(
"cargo:rerun-if-changed={}",
config_parent.join(path).display()
);
}
}
_ => (),
}
for icon in &config.tauri.bundle.icon {
println!(
"cargo:rerun-if-changed={}",
config_parent.join(icon).display()
);
}
if let Some(tray_icon) = config.tauri.system_tray.as_ref().map(|t| &t.icon_path) {
println!(
"cargo:rerun-if-changed={}",
config_parent.join(tray_icon).display()
);
}

let code = context_codegen(ContextData {
dev: self.dev,
config,
Expand Down
4 changes: 0 additions & 4 deletions core/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,6 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
)?;
}

for icon in &config.tauri.bundle.icon {
println!("cargo:rerun-if-changed={}", icon);
}

#[allow(unused_mut, clippy::redundant_clone)]
let mut resources = config.tauri.bundle.resources.clone().unwrap_or_default();
#[cfg(windows)]
Expand Down

0 comments on commit ff8fd76

Please sign in to comment.