feat(cli.rs): add `features` arg to dev/build (#1828)

This commit is contained in:
Lucas Fernandes Nogueira 2021-05-13 18:10:48 -03:00 committed by GitHub
parent 2b814e9c93
commit 6ec8e84d91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 10 deletions

View File

@ -0,0 +1,5 @@
---
"cli.rs": patch
---
Adds `features` argument to the `dev` and `build` commands.

View File

@ -24,6 +24,7 @@ pub struct Build {
debug: bool,
verbose: bool,
target: Option<String>,
features: Option<Vec<String>>,
bundles: Option<Vec<String>>,
config: Option<String>,
}
@ -53,6 +54,11 @@ impl Build {
self
}
pub fn features(mut self, features: Vec<String>) -> Self {
self.features.replace(features);
self
}
pub fn bundles(mut self, bundles: Vec<String>) -> Self {
self.bundles.replace(bundles);
self
@ -111,7 +117,10 @@ impl Build {
.or(runner_from_config)
.unwrap_or_else(|| "cargo".to_string());
let cargo_features = &config_.build.features;
let mut cargo_features = config_.build.features.clone().unwrap_or_default();
if let Some(features) = self.features {
cargo_features.extend(features);
}
rust::build_project(runner, &self.target, cargo_features, self.debug)
.with_context(|| "failed to build app")?;

View File

@ -93,18 +93,18 @@ struct CargoConfig {
pub fn build_project(
runner: String,
target: &Option<String>,
features: &Option<Vec<String>>,
features: Vec<String>,
debug: bool,
) -> crate::Result<()> {
let mut command = Command::new(&runner);
command.args(["build", "--features=custom-protocol"]);
command.args(&["build", "--features=custom-protocol"]);
if let Some(target) = target {
command.arg("--target");
command.arg(target);
}
if let Some(features) = features {
if !features.is_empty() {
command.arg("--features");
command.arg(features.join(","));
}

View File

@ -29,6 +29,11 @@ subcommands:
long: target
about: target triple to build against
multiple: true
- features:
short: f
long: features
about: list of cargo features to activate
multiple: true
- args:
about: Args passed to the binary
index: 1
@ -65,6 +70,11 @@ subcommands:
long: target
about: target triple to build against
multiple: true
- features:
short: f
long: features
about: list of cargo features to activate
multiple: true
- sign:
about: Tauri updates signer.
args:

View File

@ -48,6 +48,7 @@ fn kill_before_dev_process() {
pub struct Dev {
runner: Option<String>,
target: Option<String>,
features: Option<Vec<String>>,
exit_on_panic: bool,
config: Option<String>,
args: Vec<String>,
@ -68,6 +69,11 @@ impl Dev {
self
}
pub fn features(mut self, features: Vec<String>) -> Self {
self.features.replace(features);
self
}
pub fn config(mut self, config: String) -> Self {
self.config.replace(config);
self
@ -145,14 +151,18 @@ impl Dev {
}
}
let cargo_features = config
let mut cargo_features = config
.lock()
.unwrap()
.as_ref()
.unwrap()
.build
.features
.clone();
.clone()
.unwrap_or_default();
if let Some(features) = &self.features {
cargo_features.extend(features.clone());
}
let (child_wait_tx, child_wait_rx) = channel();
let child_wait_rx = Arc::new(Mutex::new(child_wait_rx));
@ -210,7 +220,7 @@ impl Dev {
fn start_app(
&self,
runner: &str,
features: &Option<Vec<String>>,
features: &[String],
child_wait_rx: Arc<Mutex<Receiver<()>>>,
) -> Arc<SharedChild> {
let mut command = Command::new(runner);
@ -220,7 +230,7 @@ impl Dev {
command.args(&["--target", target]);
}
if let Some(features) = features {
if !features.is_empty() {
command.args(&["--features", &features.join(",")]);
}

View File

@ -92,6 +92,10 @@ fn init_command(matches: &ArgMatches) -> Result<()> {
fn dev_command(matches: &ArgMatches) -> Result<()> {
let runner = matches.value_of("runner");
let target = matches.value_of("target");
let features: Vec<String> = matches
.values_of("features")
.map(|a| a.into_iter().map(|v| v.to_string()).collect())
.unwrap_or_default();
let exit_on_panic = matches.is_present("exit-on-panic");
let config = matches.value_of("config");
let args: Vec<String> = matches
@ -99,7 +103,10 @@ fn dev_command(matches: &ArgMatches) -> Result<()> {
.map(|a| a.into_iter().map(|v| v.to_string()).collect())
.unwrap_or_default();
let mut dev_runner = dev::Dev::new().exit_on_panic(exit_on_panic).args(args);
let mut dev_runner = dev::Dev::new()
.exit_on_panic(exit_on_panic)
.args(args)
.features(features);
if let Some(runner) = runner {
dev_runner = dev_runner.runner(runner.to_string());
@ -117,12 +124,16 @@ fn dev_command(matches: &ArgMatches) -> Result<()> {
fn build_command(matches: &ArgMatches) -> Result<()> {
let runner = matches.value_of("runner");
let target = matches.value_of("target");
let features: Vec<String> = matches
.values_of("features")
.map(|a| a.into_iter().map(|v| v.to_string()).collect())
.unwrap_or_default();
let debug = matches.is_present("debug");
let verbose = matches.is_present("verbose");
let bundles = matches.values_of_lossy("bundle");
let config = matches.value_of("config");
let mut build_runner = build::Build::new();
let mut build_runner = build::Build::new().features(features);
if let Some(runner) = runner {
build_runner = build_runner.runner(runner.to_string());
}