diff --git a/packages/cli/src/build/request.rs b/packages/cli/src/build/request.rs index d944d1f651..4b9eea1af4 100644 --- a/packages/cli/src/build/request.rs +++ b/packages/cli/src/build/request.rs @@ -593,7 +593,18 @@ impl BuildRequest { }, None if !using_dioxus_explicitly => None, None => match enabled_renderers.as_slice() { - [] => None, // Wait until we resolve everything else first then we will resolve it from the triple + // Wait until we resolve everything else first then we will resolve it from the triple if there are no + // default renderers that are compatible with the target args + [] => None, + [(renderer, _)] if !renderer.compatible_with(&args.target, target_alias) => { + // The user passed --target desktop, but the default renderer was web. Disable the web renderer and re-enable the features for the + // desktop or mobile platform later + features.extend(Self::rendererless_features(main_package)); + no_default_features = true; + None + } + + // If there is a single default renderer that is compatible with the current target, use it [(renderer, feature)] => { let targeting_mobile = match (&args.target, target_alias) { (_, TargetAlias::Android | TargetAlias::Ios) => true, @@ -3503,10 +3514,8 @@ impl BuildRequest { } fn is_wasm_or_wasi(&self) -> bool { - matches!( - self.triple.architecture, - target_lexicon::Architecture::Wasm32 | target_lexicon::Architecture::Wasm64 - ) || self.triple.operating_system == target_lexicon::OperatingSystem::Wasi + triple_is_wasm(&self.triple) + || self.triple.operating_system == target_lexicon::OperatingSystem::Wasi } /// Does the app specify: @@ -5064,3 +5073,10 @@ We checked the folders: )) } } + +pub(crate) fn triple_is_wasm(triple: &Triple) -> bool { + matches!( + triple.architecture, + Architecture::Wasm32 | Architecture::Wasm64 + ) +} diff --git a/packages/cli/src/platform.rs b/packages/cli/src/platform.rs index d9aa092b3b..789efc67bb 100644 --- a/packages/cli/src/platform.rs +++ b/packages/cli/src/platform.rs @@ -5,7 +5,7 @@ use std::fmt::Display; use std::str::FromStr; use target_lexicon::{Architecture, Environment, OperatingSystem, Triple}; -use crate::Workspace; +use crate::{triple_is_wasm, Workspace}; #[derive( Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Debug, Default, @@ -278,6 +278,24 @@ impl Renderer { _ => Self::Webview, } } + + pub(crate) fn compatible_with( + &self, + target: &Option, + target_alias: TargetAlias, + ) -> bool { + let web_target = match (target, target_alias) { + (Some(triple), _) if triple_is_wasm(triple) => true, + (None, TargetAlias::Wasm) => true, + _ => false, + }; + // Web builds are only compatible with the web, liveview, and server renderers + if web_target { + matches!(self, Self::Web | Self::Liveview | Self::Server) + } else { + false + } + } } #[derive(Debug)]