瀏覽代碼

feat: add `profile` flag

YuKun Liu 3 年之前
父節點
當前提交
51639af482
共有 5 個文件被更改,包括 30 次插入0 次删除
  1. 5 0
      src/builder.rs
  2. 4 0
      src/cli/build/mod.rs
  3. 8 0
      src/cli/cfg.rs
  4. 4 0
      src/cli/serve/mod.rs
  5. 9 0
      src/config.rs

+ 5 - 0
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),

+ 4 - 0
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

+ 8 - 0
src/cli/cfg.rs

@@ -16,6 +16,10 @@ pub struct ConfigOptsBuild {
     #[clap(long)]
     pub example: Option<String>,
 
+    /// Build with custom profile
+    #[clap(long)]
+    pub profile: Option<String>,
+
     /// Build platform: support Web & Desktop [default: "default_platform"]
     #[clap(long)]
     pub platform: Option<String>,
@@ -36,6 +40,10 @@ pub struct ConfigOptsServe {
     #[serde(default)]
     pub release: bool,
 
+    /// Build with custom profile
+    #[clap(long)]
+    pub profile: Option<String>,
+
     /// Build platform: support Web & Desktop [default: "default_platform"]
     #[clap(long)]
     pub platform: Option<String>,

+ 4 - 0
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

+ 9 - 0
src/config.rs

@@ -114,6 +114,7 @@ pub struct CrateConfig {
     pub executable: ExecutableType,
     pub dioxus_config: DioxusConfig,
     pub release: bool,
+    pub custom_profile: Option<String>,
 }
 
 #[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());