mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-10 14:44:12 +00:00
warn the user if they try to launch without a renderer selected
This commit is contained in:
parent
49f3b8235d
commit
f42bc61288
2 changed files with 56 additions and 2 deletions
47
packages/dioxus/build.rs
Normal file
47
packages/dioxus/build.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
fn main() {
|
||||
// Warn the user if they enabled the launch feature without any renderers
|
||||
if feature_enabled("launch") {
|
||||
let liveview_renderers = [
|
||||
"liveview",
|
||||
"axum",
|
||||
"salvo",
|
||||
"warp",
|
||||
"rocket",
|
||||
];
|
||||
let fullstack_renderers = [
|
||||
"axum",
|
||||
"salvo",
|
||||
"warp",
|
||||
];
|
||||
let client_renderers = [
|
||||
"desktop",
|
||||
"mobile",
|
||||
"web",
|
||||
"tui",
|
||||
];
|
||||
let client_renderer_selected = client_renderers.iter().any(|renderer| feature_enabled(renderer));
|
||||
if feature_enabled("fullstack") {
|
||||
let server_fullstack_enabled = fullstack_renderers.iter().any(|renderer| feature_enabled(renderer));
|
||||
if !server_fullstack_enabled && !client_renderer_selected {
|
||||
println!("cargo:warning=You have enabled the launch and fullstack features, but have not enabled any renderers. The application will not be able to launch. Try enabling one of the following renderers: {} for the server or one of the following renderers: {} for the client.", fullstack_renderers.join(", "), client_renderers.join(", "));
|
||||
}
|
||||
}
|
||||
|
||||
if feature_enabled("liveview") {
|
||||
let server_selected = liveview_renderers.iter().any(|renderer| feature_enabled(renderer));
|
||||
if !server_selected {
|
||||
println!("cargo:warning=You have enabled the launch and liveview features, but have not enabled any liveview renderers. The application will not be able to launch. Try enabling one of the following renderers: {}", liveview_renderers.join(", "));
|
||||
}
|
||||
}
|
||||
|
||||
if !client_renderer_selected {
|
||||
println!("cargo:warning=You have enabled the launch feature, but have not enabled any client renderers. The application will not be able to launch. Try enabling one of the following renderers: {}, fullstack or liveview", client_renderers.join(", "));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn feature_enabled(feature: &str) -> bool {
|
||||
let feature = "CARGO_FEATURE_".to_owned() + &feature.to_uppercase().replace("-", "_");
|
||||
println!("cargo:rerun-if-env-changed={}", feature);
|
||||
std::env::var(feature).is_ok()
|
||||
}
|
|
@ -161,15 +161,18 @@ mod current_platform {
|
|||
#[cfg(all(feature = "desktop", not(feature = "fullstack")))]
|
||||
pub use dioxus_desktop::launch::*;
|
||||
|
||||
#[cfg(all(feature = "mobile", not(feature = "fullstack")))]
|
||||
pub use dioxus_desktop::launch::*;
|
||||
|
||||
#[cfg(feature = "fullstack")]
|
||||
pub use dioxus_fullstack::launch::*;
|
||||
|
||||
#[cfg(all(feature = "web", not(any(feature = "desktop", feature = "fullstack"))))]
|
||||
#[cfg(all(feature = "web", not(any(feature = "desktop", feature = "mobile", feature = "fullstack"))))]
|
||||
pub use dioxus_web::launch::*;
|
||||
|
||||
#[cfg(all(
|
||||
feature = "liveview",
|
||||
not(any(feature = "web", feature = "desktop", feature = "fullstack"))
|
||||
not(any(feature = "web", feature = "desktop", feature = "mobile", feature = "fullstack"))
|
||||
))]
|
||||
pub use dioxus_liveview::launch::*;
|
||||
|
||||
|
@ -179,6 +182,7 @@ mod current_platform {
|
|||
feature = "liveview",
|
||||
feature = "web",
|
||||
feature = "desktop",
|
||||
feature = "mobile",
|
||||
feature = "fullstack"
|
||||
))
|
||||
))]
|
||||
|
@ -187,6 +191,7 @@ mod current_platform {
|
|||
#[cfg(not(any(
|
||||
feature = "liveview",
|
||||
feature = "desktop",
|
||||
feature = "mobile",
|
||||
feature = "web",
|
||||
feature = "tui",
|
||||
feature = "fullstack"
|
||||
|
@ -196,6 +201,7 @@ mod current_platform {
|
|||
#[cfg(not(any(
|
||||
feature = "liveview",
|
||||
feature = "desktop",
|
||||
feature = "mobile",
|
||||
feature = "web",
|
||||
feature = "tui",
|
||||
feature = "fullstack"
|
||||
|
@ -205,6 +211,7 @@ mod current_platform {
|
|||
contexts: Vec<Box<super::ValidContext>>,
|
||||
platform_config: (),
|
||||
) {
|
||||
panic!("No platform feature enabled. Please enable one of the following features: liveview, desktop, mobile, web, tui, fullstack to use the launch API.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue