Skip to content

Commit 6ec8e84

Browse files
authored
feat(cli.rs): add features arg to dev/build (#1828)
1 parent 2b814e9 commit 6ec8e84

File tree

6 files changed

+55
-10
lines changed

6 files changed

+55
-10
lines changed

.changes/cli.rs-features-arg.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cli.rs": patch
3+
---
4+
5+
Adds `features` argument to the `dev` and `build` commands.

tooling/cli.rs/src/build.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub struct Build {
2424
debug: bool,
2525
verbose: bool,
2626
target: Option<String>,
27+
features: Option<Vec<String>>,
2728
bundles: Option<Vec<String>>,
2829
config: Option<String>,
2930
}
@@ -53,6 +54,11 @@ impl Build {
5354
self
5455
}
5556

57+
pub fn features(mut self, features: Vec<String>) -> Self {
58+
self.features.replace(features);
59+
self
60+
}
61+
5662
pub fn bundles(mut self, bundles: Vec<String>) -> Self {
5763
self.bundles.replace(bundles);
5864
self
@@ -111,7 +117,10 @@ impl Build {
111117
.or(runner_from_config)
112118
.unwrap_or_else(|| "cargo".to_string());
113119

114-
let cargo_features = &config_.build.features;
120+
let mut cargo_features = config_.build.features.clone().unwrap_or_default();
121+
if let Some(features) = self.features {
122+
cargo_features.extend(features);
123+
}
115124

116125
rust::build_project(runner, &self.target, cargo_features, self.debug)
117126
.with_context(|| "failed to build app")?;

tooling/cli.rs/src/build/rust.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,18 @@ struct CargoConfig {
9393
pub fn build_project(
9494
runner: String,
9595
target: &Option<String>,
96-
features: &Option<Vec<String>>,
96+
features: Vec<String>,
9797
debug: bool,
9898
) -> crate::Result<()> {
9999
let mut command = Command::new(&runner);
100-
command.args(["build", "--features=custom-protocol"]);
100+
command.args(&["build", "--features=custom-protocol"]);
101101

102102
if let Some(target) = target {
103103
command.arg("--target");
104104
command.arg(target);
105105
}
106106

107-
if let Some(features) = features {
107+
if !features.is_empty() {
108108
command.arg("--features");
109109
command.arg(features.join(","));
110110
}

tooling/cli.rs/src/cli.yml

+10
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ subcommands:
2929
long: target
3030
about: target triple to build against
3131
multiple: true
32+
- features:
33+
short: f
34+
long: features
35+
about: list of cargo features to activate
36+
multiple: true
3237
- args:
3338
about: Args passed to the binary
3439
index: 1
@@ -65,6 +70,11 @@ subcommands:
6570
long: target
6671
about: target triple to build against
6772
multiple: true
73+
- features:
74+
short: f
75+
long: features
76+
about: list of cargo features to activate
77+
multiple: true
6878
- sign:
6979
about: Tauri updates signer.
7080
args:

tooling/cli.rs/src/dev.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ fn kill_before_dev_process() {
4848
pub struct Dev {
4949
runner: Option<String>,
5050
target: Option<String>,
51+
features: Option<Vec<String>>,
5152
exit_on_panic: bool,
5253
config: Option<String>,
5354
args: Vec<String>,
@@ -68,6 +69,11 @@ impl Dev {
6869
self
6970
}
7071

72+
pub fn features(mut self, features: Vec<String>) -> Self {
73+
self.features.replace(features);
74+
self
75+
}
76+
7177
pub fn config(mut self, config: String) -> Self {
7278
self.config.replace(config);
7379
self
@@ -145,14 +151,18 @@ impl Dev {
145151
}
146152
}
147153

148-
let cargo_features = config
154+
let mut cargo_features = config
149155
.lock()
150156
.unwrap()
151157
.as_ref()
152158
.unwrap()
153159
.build
154160
.features
155-
.clone();
161+
.clone()
162+
.unwrap_or_default();
163+
if let Some(features) = &self.features {
164+
cargo_features.extend(features.clone());
165+
}
156166

157167
let (child_wait_tx, child_wait_rx) = channel();
158168
let child_wait_rx = Arc::new(Mutex::new(child_wait_rx));
@@ -210,7 +220,7 @@ impl Dev {
210220
fn start_app(
211221
&self,
212222
runner: &str,
213-
features: &Option<Vec<String>>,
223+
features: &[String],
214224
child_wait_rx: Arc<Mutex<Receiver<()>>>,
215225
) -> Arc<SharedChild> {
216226
let mut command = Command::new(runner);
@@ -220,7 +230,7 @@ impl Dev {
220230
command.args(&["--target", target]);
221231
}
222232

223-
if let Some(features) = features {
233+
if !features.is_empty() {
224234
command.args(&["--features", &features.join(",")]);
225235
}
226236

tooling/cli.rs/src/main.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,21 @@ fn init_command(matches: &ArgMatches) -> Result<()> {
9292
fn dev_command(matches: &ArgMatches) -> Result<()> {
9393
let runner = matches.value_of("runner");
9494
let target = matches.value_of("target");
95+
let features: Vec<String> = matches
96+
.values_of("features")
97+
.map(|a| a.into_iter().map(|v| v.to_string()).collect())
98+
.unwrap_or_default();
9599
let exit_on_panic = matches.is_present("exit-on-panic");
96100
let config = matches.value_of("config");
97101
let args: Vec<String> = matches
98102
.values_of("args")
99103
.map(|a| a.into_iter().map(|v| v.to_string()).collect())
100104
.unwrap_or_default();
101105

102-
let mut dev_runner = dev::Dev::new().exit_on_panic(exit_on_panic).args(args);
106+
let mut dev_runner = dev::Dev::new()
107+
.exit_on_panic(exit_on_panic)
108+
.args(args)
109+
.features(features);
103110

104111
if let Some(runner) = runner {
105112
dev_runner = dev_runner.runner(runner.to_string());
@@ -117,12 +124,16 @@ fn dev_command(matches: &ArgMatches) -> Result<()> {
117124
fn build_command(matches: &ArgMatches) -> Result<()> {
118125
let runner = matches.value_of("runner");
119126
let target = matches.value_of("target");
127+
let features: Vec<String> = matches
128+
.values_of("features")
129+
.map(|a| a.into_iter().map(|v| v.to_string()).collect())
130+
.unwrap_or_default();
120131
let debug = matches.is_present("debug");
121132
let verbose = matches.is_present("verbose");
122133
let bundles = matches.values_of_lossy("bundle");
123134
let config = matches.value_of("config");
124135

125-
let mut build_runner = build::Build::new();
136+
let mut build_runner = build::Build::new().features(features);
126137
if let Some(runner) = runner {
127138
build_runner = build_runner.runner(runner.to_string());
128139
}

0 commit comments

Comments
 (0)