From f62c81ea0dff4b8173a1e36d70933154c9c7b5cd Mon Sep 17 00:00:00 2001 From: rtretter <25963632+rtretter@users.noreply.github.com> Date: Wed, 6 Mar 2024 21:16:51 +0100 Subject: [PATCH 1/2] added automatic platform detection to cli if none is passed --- Cargo.lock | 2 +- packages/cli-config/Cargo.toml | 2 +- packages/cli/src/cli/serve.rs | 24 +++++++++++++++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 81187bf71..20c877a8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2326,7 +2326,7 @@ dependencies = [ name = "dioxus-cli-config" version = "0.5.0-alpha.0" dependencies = [ - "cargo_toml 0.16.3", + "cargo_toml 0.18.0", "clap 4.4.18", "once_cell", "serde", diff --git a/packages/cli-config/Cargo.toml b/packages/cli-config/Cargo.toml index aee78d1c2..64992bcb6 100644 --- a/packages/cli-config/Cargo.toml +++ b/packages/cli-config/Cargo.toml @@ -13,7 +13,7 @@ clap = { version = "4.2", features = ["derive"], optional = true } serde = { version = "1.0.136", features = ["derive"] } serde_json = "1.0.79" toml = { workspace = true, optional = true } -cargo_toml = { version = "0.16.0", optional = true } +cargo_toml = { version = "0.18.0", optional = true } once_cell = "1.18.0" tracing = { workspace = true } diff --git a/packages/cli/src/cli/serve.rs b/packages/cli/src/cli/serve.rs index 3ace461ef..05b07c224 100644 --- a/packages/cli/src/cli/serve.rs +++ b/packages/cli/src/cli/serve.rs @@ -3,6 +3,7 @@ use manganis_cli_support::AssetManifest; use super::*; use std::{fs::create_dir_all, io::Write, path::PathBuf}; +use cargo_toml::Dependency::{Simple, Inherited, Detailed}; /// Run the WASM project on dev-server #[derive(Clone, Debug, Parser)] @@ -41,11 +42,28 @@ impl Serve { crate_config.set_cargo_args(self.serve.cargo_args); - let platform = self + let mut platform = self .serve - .platform - .unwrap_or(crate_config.dioxus_config.application.default_platform); + .platform; + if platform.is_none() { + if let Some(dependency) = &crate_config.manifest.dependencies.get("dioxus") { + let features = match dependency { + Inherited(detail) => detail.features.to_vec(), + Detailed(detail) => detail.features.to_vec(), + Simple(_) => vec![] + }; + + platform = features + .iter() + .next() + .and_then(|first_feature| serde_json::from_str(&format!(r#""{}""#, first_feature)).ok()); + } + } + + let platform = platform + .unwrap_or(crate_config.dioxus_config.application.default_platform); + match platform { Platform::Web => { // start the develop server From 3ffb1facf3f0c7635076dbabd95636bbb98b5dee Mon Sep 17 00:00:00 2001 From: rtretter <25963632+rtretter@users.noreply.github.com> Date: Wed, 6 Mar 2024 21:36:33 +0100 Subject: [PATCH 2/2] search for first valid platform in features --- packages/cli/src/cli/serve.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/cli/src/cli/serve.rs b/packages/cli/src/cli/serve.rs index 05b07c224..ac60d460e 100644 --- a/packages/cli/src/cli/serve.rs +++ b/packages/cli/src/cli/serve.rs @@ -2,8 +2,8 @@ use dioxus_cli_config::Platform; use manganis_cli_support::AssetManifest; use super::*; +use cargo_toml::Dependency::{Detailed, Inherited, Simple}; use std::{fs::create_dir_all, io::Write, path::PathBuf}; -use cargo_toml::Dependency::{Simple, Inherited, Detailed}; /// Run the WASM project on dev-server #[derive(Clone, Debug, Parser)] @@ -42,28 +42,24 @@ impl Serve { crate_config.set_cargo_args(self.serve.cargo_args); - let mut platform = self - .serve - .platform; + let mut platform = self.serve.platform; if platform.is_none() { if let Some(dependency) = &crate_config.manifest.dependencies.get("dioxus") { let features = match dependency { Inherited(detail) => detail.features.to_vec(), Detailed(detail) => detail.features.to_vec(), - Simple(_) => vec![] + Simple(_) => vec![], }; platform = features .iter() - .next() - .and_then(|first_feature| serde_json::from_str(&format!(r#""{}""#, first_feature)).ok()); + .find_map(|platform| serde_json::from_str(&format!(r#""{}""#, platform)).ok()); } } - let platform = platform - .unwrap_or(crate_config.dioxus_config.application.default_platform); - + let platform = platform.unwrap_or(crate_config.dioxus_config.application.default_platform); + match platform { Platform::Web => { // start the develop server