Skip to content

Commit 86a23ff

Browse files
added support for cargo workspaces for dev command (#1827)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent 754c2e7 commit 86a23ff

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

.changes/cli.rs-dev-workspaces.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cli.rs": patch
3+
---
4+
5+
Watch workspace crates on `dev` command.

tooling/cli.rs/src/dev.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use crate::helpers::{
66
app_paths::{app_dir, tauri_dir},
77
config::{get as get_config, reload as reload_config},
8-
manifest::rewrite_manifest,
8+
manifest::{get_workspace_members, rewrite_manifest},
99
Logger,
1010
};
1111

@@ -157,6 +157,12 @@ impl Dev {
157157
watcher.watch(tauri_path.join("Cargo.toml"), RecursiveMode::Recursive)?;
158158
watcher.watch(tauri_path.join("tauri.conf.json"), RecursiveMode::Recursive)?;
159159

160+
for member in get_workspace_members()? {
161+
let workspace_path = tauri_path.join(member);
162+
watcher.watch(workspace_path.join("src"), RecursiveMode::Recursive)?;
163+
watcher.watch(workspace_path.join("Cargo.toml"), RecursiveMode::Recursive)?;
164+
}
165+
160166
loop {
161167
if let Ok(event) = rx.recv() {
162168
let event_path = match event {

tooling/cli.rs/src/helpers/manifest.rs

+37-7
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,27 @@ use toml_edit::{Array, Document, InlineTable, Item, Value};
1010
use std::{
1111
fs::File,
1212
io::{Read, Write},
13+
path::Path,
1314
};
1415

1516
pub struct Manifest {
1617
pub features: Vec<String>,
1718
}
1819

20+
fn read_manifest(manifest_path: &Path) -> crate::Result<Document> {
21+
let mut manifest_str = String::new();
22+
23+
let mut manifest_file = File::open(manifest_path)
24+
.with_context(|| format!("failed to open `{:?}` file", manifest_path))?;
25+
manifest_file.read_to_string(&mut manifest_str)?;
26+
27+
let manifest: Document = manifest_str
28+
.parse::<Document>()
29+
.with_context(|| "failed to parse Cargo.toml")?;
30+
31+
Ok(manifest)
32+
}
33+
1934
fn features_to_vec(features: &Array) -> Vec<String> {
2035
let mut string_features = Vec::new();
2136
for feat in features.iter() {
@@ -28,13 +43,7 @@ fn features_to_vec(features: &Array) -> Vec<String> {
2843

2944
pub fn rewrite_manifest(config: ConfigHandle) -> crate::Result<Manifest> {
3045
let manifest_path = tauri_dir().join("Cargo.toml");
31-
let mut manifest_str = String::new();
32-
let mut manifest_file = File::open(&manifest_path)
33-
.with_context(|| format!("failed to open `{:?}` file", manifest_path))?;
34-
manifest_file.read_to_string(&mut manifest_str)?;
35-
let mut manifest: Document = manifest_str
36-
.parse::<Document>()
37-
.with_context(|| "failed to parse Cargo.toml")?;
46+
let mut manifest = read_manifest(&manifest_path)?;
3847
let dependencies = manifest
3948
.as_table_mut()
4049
.entry("dependencies")
@@ -127,3 +136,24 @@ pub fn rewrite_manifest(config: ConfigHandle) -> crate::Result<Manifest> {
127136
features: features_to_vec(&features),
128137
})
129138
}
139+
140+
pub fn get_workspace_members() -> crate::Result<Vec<String>> {
141+
let mut manifest = read_manifest(&tauri_dir().join("Cargo.toml"))?;
142+
let workspace = manifest.as_table_mut().entry("workspace").as_table_mut();
143+
144+
match workspace {
145+
Some(workspace) => {
146+
let members = workspace
147+
.entry("members")
148+
.as_array()
149+
.expect("workspace members aren't an array");
150+
Ok(
151+
members
152+
.iter()
153+
.map(|v| v.as_str().unwrap().to_string())
154+
.collect(),
155+
)
156+
}
157+
None => Ok(vec![]),
158+
}
159+
}

0 commit comments

Comments
 (0)