Skip to content

Commit dbb8c87

Browse files
authored
feat(cli): watch Cargo workspaces in the dev command, closes #4222 (#4572)
1 parent edb9ab2 commit dbb8c87

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

.changes/watch-cargo-workspace.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"cli.rs": patch
3+
"cli.js": patch
4+
---
5+
6+
Watch for Cargo workspace members in the `dev` file watcher.

tooling/cli/src/interface/rust.rs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use anyhow::Context;
2121
#[cfg(target_os = "linux")]
2222
use heck::ToKebabCase;
2323
use log::warn;
24+
use log::{debug, info};
2425
use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher};
2526
use serde::Deserialize;
2627
use shared_child::SharedChild;
@@ -461,20 +462,43 @@ impl Rust {
461462
let process = Arc::new(Mutex::new(child));
462463
let (tx, rx) = channel();
463464
let tauri_path = tauri_dir();
465+
let workspace_path = get_workspace_dir(&tauri_path);
466+
467+
let watch_folders = if tauri_path == workspace_path {
468+
vec![tauri_path]
469+
} else {
470+
let cargo_settings = CargoSettings::load(&workspace_path)?;
471+
cargo_settings
472+
.workspace
473+
.as_ref()
474+
.map(|w| {
475+
w.members
476+
.clone()
477+
.unwrap_or_default()
478+
.into_iter()
479+
.map(|p| workspace_path.join(p))
480+
.collect()
481+
})
482+
.unwrap_or_else(|| vec![tauri_path])
483+
};
464484

465485
let mut watcher = watcher(tx, Duration::from_secs(1)).unwrap();
466-
lookup(&tauri_path, |file_type, path| {
467-
if path != tauri_path {
468-
let _ = watcher.watch(
469-
path,
470-
if file_type.is_dir() {
471-
RecursiveMode::Recursive
472-
} else {
473-
RecursiveMode::NonRecursive
474-
},
475-
);
476-
}
477-
});
486+
for path in watch_folders {
487+
info!("Watching {} for changes...", path.display());
488+
lookup(&path, |file_type, p| {
489+
if p != path {
490+
debug!("Watching {} for changes...", p.display());
491+
let _ = watcher.watch(
492+
p,
493+
if file_type.is_dir() {
494+
RecursiveMode::Recursive
495+
} else {
496+
RecursiveMode::NonRecursive
497+
},
498+
);
499+
}
500+
});
501+
}
478502

479503
loop {
480504
let on_exit = on_exit.clone();

0 commit comments

Comments
 (0)