diff --git a/packages/cli/src/build/request.rs b/packages/cli/src/build/request.rs index 78ff4ec7a..24139af92 100644 --- a/packages/cli/src/build/request.rs +++ b/packages/cli/src/build/request.rs @@ -344,7 +344,6 @@ use std::{ use target_lexicon::{OperatingSystem, Triple}; use tempfile::{NamedTempFile, TempDir}; use tokio::{io::AsyncBufReadExt, process::Command}; -use toml_edit::Item; use uuid::Uuid; use super::HotpatchModuleCache; @@ -442,10 +441,6 @@ pub struct BuildArtifacts { pub(crate) patch_cache: Option>, } -pub(crate) static PROFILE_WASM: &str = "wasm-dev"; -pub(crate) static PROFILE_ANDROID: &str = "android-dev"; -pub(crate) static PROFILE_SERVER: &str = "server-dev"; - impl BuildRequest { /// Create a new build request. /// @@ -591,13 +586,7 @@ impl BuildRequest { // We might want to move some of these profiles into dioxus.toml and make them "virtual". let profile = match args.profile.clone() { Some(profile) => profile, - None if args.release => "release".to_string(), - None => match platform { - Platform::Android => PROFILE_ANDROID.to_string(), - Platform::Web => PROFILE_WASM.to_string(), - Platform::Server => PROFILE_SERVER.to_string(), - _ => "dev".to_string(), - }, + None => platform.profile_name(args.release), }; // Determining release mode is based on the profile, actually, so we need to check that @@ -2087,6 +2076,9 @@ impl BuildRequest { fn cargo_build_arguments(&self, ctx: &BuildContext) -> Vec { let mut cargo_args = Vec::with_capacity(4); + // Set the `--config profile.{profile}.{key}={value}` flags for the profile, filling in adhoc profile + cargo_args.extend(self.profile_args()); + // Add required profile flags. --release overrides any custom profiles. cargo_args.push("--profile".to_string()); cargo_args.push(self.profile.to_string()); @@ -2834,54 +2826,6 @@ impl BuildRequest { }) } - // The `opt-level=1` increases build times, but can noticeably decrease time - // between saving changes and being able to interact with an app (for wasm/web). The "overall" - // time difference (between having and not having the optimization) can be - // almost imperceptible (~1 s) but also can be very noticeable (~6 s) — depends - // on setup (hardware, OS, browser, idle load). - // - // Find or create the client and server profiles in the top-level Cargo.toml file - // todo(jon): we should/could make these optional by placing some defaults somewhere - pub(crate) fn initialize_profiles(&self) -> crate::Result<()> { - let config_path = self.workspace_dir().join("Cargo.toml"); - let mut config = match std::fs::read_to_string(&config_path) { - Ok(config) => config.parse::().map_err(|e| { - crate::Error::Other(anyhow::anyhow!("Failed to parse Cargo.toml: {}", e)) - })?, - Err(_) => Default::default(), - }; - - if let Item::Table(table) = config - .as_table_mut() - .entry("profile") - .or_insert(Item::Table(Default::default())) - { - if let toml_edit::Entry::Vacant(entry) = table.entry(PROFILE_WASM) { - let mut client = toml_edit::Table::new(); - client.insert("inherits", Item::Value("dev".into())); - client.insert("opt-level", Item::Value(1.into())); - entry.insert(Item::Table(client)); - } - - if let toml_edit::Entry::Vacant(entry) = table.entry(PROFILE_SERVER) { - let mut server = toml_edit::Table::new(); - server.insert("inherits", Item::Value("dev".into())); - entry.insert(Item::Table(server)); - } - - if let toml_edit::Entry::Vacant(entry) = table.entry(PROFILE_ANDROID) { - let mut android = toml_edit::Table::new(); - android.insert("inherits", Item::Value("dev".into())); - entry.insert(Item::Table(android)); - } - } - - std::fs::write(config_path, config.to_string()) - .context("Failed to write profiles to Cargo.toml")?; - - Ok(()) - } - /// Return the version of the wasm-bindgen crate if it exists fn wasm_bindgen_version(&self) -> Option { self.workspace @@ -3689,10 +3633,6 @@ impl BuildRequest { pub(crate) async fn verify_tooling(&self, ctx: &BuildContext) -> Result<()> { ctx.status_installing_tooling(); - self - .initialize_profiles() - .context("Failed to initialize profiles - dioxus can't build without them. You might need to initialize them yourself.")?; - match self.platform { Platform::Web => self.verify_web_tooling().await?, Platform::Ios => self.verify_ios_tooling().await?, @@ -4193,4 +4133,67 @@ r#"