From 51639af48230bb8a4bb7b50105c1bcd270ac0774 Mon Sep 17 00:00:00 2001 From: YuKun Liu <41265098+mrxiaozhuox@users.noreply.github.com> Date: Mon, 6 Jun 2022 00:16:15 +0800 Subject: [PATCH 1/4] feat: add `profile` flag --- src/builder.rs | 5 +++++ src/cli/build/mod.rs | 4 ++++ src/cli/cfg.rs | 8 ++++++++ src/cli/serve/mod.rs | 4 ++++ src/config.rs | 9 +++++++++ 5 files changed, 30 insertions(+) diff --git a/src/builder.rs b/src/builder.rs index 4f6824780..31bb96f46 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -49,6 +49,11 @@ pub fn build(config: &CrateConfig) -> Result<()> { cmd.arg("--release"); } + if config.custom_profile.is_some() { + let custom_profile = config.custom_profile.as_ref().unwrap(); + cmd.arg(format!("--profile {}", custom_profile)); + } + match executable { ExecutableType::Binary(name) => cmd.arg("--bin").arg(name), ExecutableType::Lib(name) => cmd.arg("--lib").arg(name), diff --git a/src/cli/build/mod.rs b/src/cli/build/mod.rs index 4c043091f..7f8c7b420 100644 --- a/src/cli/build/mod.rs +++ b/src/cli/build/mod.rs @@ -19,6 +19,10 @@ impl Build { crate_config.as_example(self.build.example.unwrap()); } + if self.build.profile.is_some() { + crate_config.set_profile(self.build.profile.unwrap()); + } + let platform = self.build.platform.unwrap_or_else(|| { crate_config .dioxus_config diff --git a/src/cli/cfg.rs b/src/cli/cfg.rs index f5ee45b87..11a1603c7 100644 --- a/src/cli/cfg.rs +++ b/src/cli/cfg.rs @@ -16,6 +16,10 @@ pub struct ConfigOptsBuild { #[clap(long)] pub example: Option, + /// Build with custom profile + #[clap(long)] + pub profile: Option, + /// Build platform: support Web & Desktop [default: "default_platform"] #[clap(long)] pub platform: Option, @@ -36,6 +40,10 @@ pub struct ConfigOptsServe { #[serde(default)] pub release: bool, + /// Build with custom profile + #[clap(long)] + pub profile: Option, + /// Build platform: support Web & Desktop [default: "default_platform"] #[clap(long)] pub platform: Option, diff --git a/src/cli/serve/mod.rs b/src/cli/serve/mod.rs index 85bd92c74..1b79284b7 100644 --- a/src/cli/serve/mod.rs +++ b/src/cli/serve/mod.rs @@ -24,6 +24,10 @@ impl Serve { crate_config.as_example(self.serve.example.unwrap()); } + if self.serve.profile.is_some() { + crate_config.set_profile(self.serve.profile.unwrap()); + } + let platform = self.serve.platform.unwrap_or_else(|| { crate_config .dioxus_config diff --git a/src/config.rs b/src/config.rs index 783c72ccd..9679fadaa 100644 --- a/src/config.rs +++ b/src/config.rs @@ -114,6 +114,7 @@ pub struct CrateConfig { pub executable: ExecutableType, pub dioxus_config: DioxusConfig, pub release: bool, + pub custom_profile: Option, } #[derive(Debug, Clone)] @@ -163,6 +164,8 @@ impl CrateConfig { let release = false; + let custom_profile = None; + Ok(Self { out_dir, crate_dir, @@ -173,6 +176,7 @@ impl CrateConfig { executable, release, dioxus_config, + custom_profile, }) } @@ -186,6 +190,11 @@ impl CrateConfig { self } + pub fn set_profile(&mut self, profile: String) -> &mut Self { + self.custom_profile = Some(profile); + self + } + // pub fn with_build_options(&mut self, options: &BuildOptions) { // if let Some(name) = &options.example { // self.as_example(name.clone()); From 6aa609144d4b8dde995749ad2de4aaa8d69f16f4 Mon Sep 17 00:00:00 2001 From: YuKun Liu <41265098+mrxiaozhuox@users.noreply.github.com> Date: Mon, 6 Jun 2022 08:46:16 +0800 Subject: [PATCH 2/4] feat: add `profile` flag --- src/builder.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/builder.rs b/src/builder.rs index 31bb96f46..57738b1bc 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -51,7 +51,8 @@ pub fn build(config: &CrateConfig) -> Result<()> { if config.custom_profile.is_some() { let custom_profile = config.custom_profile.as_ref().unwrap(); - cmd.arg(format!("--profile {}", custom_profile)); + cmd.arg("--profile"); + cmd.arg(custom_profile); } match executable { @@ -194,6 +195,12 @@ pub fn build_desktop(config: &CrateConfig, is_serve: bool) -> Result<()> { cmd.arg("--release"); } + if config.custom_profile.is_some() { + let custom_profile = config.custom_profile.as_ref().unwrap(); + cmd.arg("--profile"); + cmd.arg(custom_profile); + } + match &config.executable { crate::ExecutableType::Binary(name) => cmd.arg("--bin").arg(name), crate::ExecutableType::Lib(name) => cmd.arg("--lib").arg(name), From d20e7ab50815014e67871ec2227413a085762690 Mon Sep 17 00:00:00 2001 From: YuKun Liu <41265098+mrxiaozhuox@users.noreply.github.com> Date: Mon, 6 Jun 2022 18:18:22 +0800 Subject: [PATCH 3/4] feat: add `features` flag --- src/builder.rs | 12 ++++++++++++ src/cli/cfg.rs | 8 ++++++++ src/config.rs | 9 ++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/builder.rs b/src/builder.rs index 57738b1bc..46d4c15f5 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -55,6 +55,12 @@ pub fn build(config: &CrateConfig) -> Result<()> { cmd.arg(custom_profile); } + if config.features.is_some() { + let features_str = config.features.as_ref().unwrap().join(" "); + cmd.arg("--features"); + cmd.arg(features_str); + } + match executable { ExecutableType::Binary(name) => cmd.arg("--bin").arg(name), ExecutableType::Lib(name) => cmd.arg("--lib").arg(name), @@ -201,6 +207,12 @@ pub fn build_desktop(config: &CrateConfig, is_serve: bool) -> Result<()> { cmd.arg(custom_profile); } + if config.features.is_some() { + let features_str = config.features.as_ref().unwrap().join(" "); + cmd.arg("--features"); + cmd.arg(features_str); + } + match &config.executable { crate::ExecutableType::Binary(name) => cmd.arg("--bin").arg(name), crate::ExecutableType::Lib(name) => cmd.arg("--lib").arg(name), diff --git a/src/cli/cfg.rs b/src/cli/cfg.rs index 11a1603c7..b8305e3a8 100644 --- a/src/cli/cfg.rs +++ b/src/cli/cfg.rs @@ -23,6 +23,10 @@ pub struct ConfigOptsBuild { /// Build platform: support Web & Desktop [default: "default_platform"] #[clap(long)] pub platform: Option, + + /// Space separated list of features to activate + #[clap(long)] + pub features: Option>, } #[derive(Clone, Debug, Default, Deserialize, Parser)] @@ -47,6 +51,10 @@ pub struct ConfigOptsServe { /// Build platform: support Web & Desktop [default: "default_platform"] #[clap(long)] pub platform: Option, + + /// Space separated list of features to activate + #[clap(long)] + pub features: Option>, } /// Ensure the given value for `--public-url` is formatted correctly. diff --git a/src/config.rs b/src/config.rs index 9679fadaa..6804ae6cd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -115,6 +115,7 @@ pub struct CrateConfig { pub dioxus_config: DioxusConfig, pub release: bool, pub custom_profile: Option, + pub features: Option>, } #[derive(Debug, Clone)] @@ -163,8 +164,8 @@ impl CrateConfig { let executable = ExecutableType::Binary(output_filename); let release = false; - let custom_profile = None; + let features = None; Ok(Self { out_dir, @@ -177,6 +178,7 @@ impl CrateConfig { release, dioxus_config, custom_profile, + features }) } @@ -195,6 +197,11 @@ impl CrateConfig { self } + pub fn set_features(&mut self, features: Vec) -> &mut Self { + self.features = Some(features); + self + } + // pub fn with_build_options(&mut self, options: &BuildOptions) { // if let Some(name) = &options.example { // self.as_example(name.clone()); From 421d2ed2980d4e4d542f1b7b28c31e9ca279a563 Mon Sep 17 00:00:00 2001 From: YuKun Liu <41265098+mrxiaozhuox@users.noreply.github.com> Date: Mon, 6 Jun 2022 21:48:14 +0800 Subject: [PATCH 4/4] feat: add `verbose` flag --- src/builder.rs | 6 ++++++ src/cli/build/mod.rs | 1 + src/cli/cfg.rs | 10 ++++++++++ src/cli/serve/mod.rs | 1 + src/config.rs | 10 +++++++++- 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/builder.rs b/src/builder.rs index 46d4c15f5..02add84ad 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -48,6 +48,9 @@ pub fn build(config: &CrateConfig) -> Result<()> { if config.release { cmd.arg("--release"); } + if config.verbose { + cmd.arg("--verbose"); + } if config.custom_profile.is_some() { let custom_profile = config.custom_profile.as_ref().unwrap(); @@ -200,6 +203,9 @@ pub fn build_desktop(config: &CrateConfig, is_serve: bool) -> Result<()> { if config.release { cmd.arg("--release"); } + if config.verbose { + cmd.arg("--verbose"); + } if config.custom_profile.is_some() { let custom_profile = config.custom_profile.as_ref().unwrap(); diff --git a/src/cli/build/mod.rs b/src/cli/build/mod.rs index 7f8c7b420..661f17a5a 100644 --- a/src/cli/build/mod.rs +++ b/src/cli/build/mod.rs @@ -14,6 +14,7 @@ impl Build { // change the release state. crate_config.with_release(self.build.release); + crate_config.with_verbose(self.build.verbose); if self.build.example.is_some() { crate_config.as_example(self.build.example.unwrap()); diff --git a/src/cli/cfg.rs b/src/cli/cfg.rs index b8305e3a8..26409c370 100644 --- a/src/cli/cfg.rs +++ b/src/cli/cfg.rs @@ -12,6 +12,11 @@ pub struct ConfigOptsBuild { #[serde(default)] pub release: bool, + // Use verbose output [default: false] + #[clap(long)] + #[serde(default)] + pub verbose: bool, + /// Build a example [default: ""] #[clap(long)] pub example: Option, @@ -44,6 +49,11 @@ pub struct ConfigOptsServe { #[serde(default)] pub release: bool, + // Use verbose output [default: false] + #[clap(long)] + #[serde(default)] + pub verbose: bool, + /// Build with custom profile #[clap(long)] pub profile: Option, diff --git a/src/cli/serve/mod.rs b/src/cli/serve/mod.rs index 1b79284b7..d25aa5bad 100644 --- a/src/cli/serve/mod.rs +++ b/src/cli/serve/mod.rs @@ -19,6 +19,7 @@ impl Serve { // change the relase state. crate_config.with_release(self.serve.release); + crate_config.with_verbose(self.serve.verbose); if self.serve.example.is_some() { crate_config.as_example(self.serve.example.unwrap()); diff --git a/src/config.rs b/src/config.rs index 6804ae6cd..6e855002b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -114,6 +114,7 @@ pub struct CrateConfig { pub executable: ExecutableType, pub dioxus_config: DioxusConfig, pub release: bool, + pub verbose: bool, pub custom_profile: Option, pub features: Option>, } @@ -164,6 +165,7 @@ impl CrateConfig { let executable = ExecutableType::Binary(output_filename); let release = false; + let verbose = false; let custom_profile = None; let features = None; @@ -178,7 +180,8 @@ impl CrateConfig { release, dioxus_config, custom_profile, - features + features, + verbose, }) } @@ -192,6 +195,11 @@ impl CrateConfig { self } + pub fn with_verbose(&mut self, verbose: bool) -> &mut Self { + self.verbose = verbose; + self + } + pub fn set_profile(&mut self, profile: String) -> &mut Self { self.custom_profile = Some(profile); self