Warn if cli-config is not available at compile time (#2135)

* warn if a package relies on the CLI config, but it is not built with the CLI

* fix default features

---------

Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
Evan AlmloffandJonathan Kelley authored and GitHub committed 2024-03-26 19:10:26 -07:00
1 parent 1b03bed20a
commit 460a685fa3
9 files changed
+24 -7

No files matched your search

+2 -1
View File
@@ -22,5 +22,6 @@ tauri-bundler = { version = "=1.4.0", features = ["native-tls-vendored"], option
tauri-utils = { version = "=1.5.*", optional = true }
[features]
default = []
default = ["read-config"]
cli = ["tauri-bundler", "tauri-utils", "clap", "toml", "cargo_toml"]
read-config = []
+11
View File
@@ -0,0 +1,11 @@
// warn if the "read-config" feature is enabled, but the DIOXUS_CONFIG environment variable is not set
// This means that some library is trying to access the crate's configuration, but the dioxus CLI was not used to build the application.
fn main() {
println!("cargo:rerun-if-env-changed=DIOXUS_CONFIG");
let dioxus_config = std::env::var("DIOXUS_CONFIG");
let built_with_dioxus = dioxus_config.is_ok();
if cfg!(feature = "read-config") && !built_with_dioxus {
println!("cargo:warning=A library is trying to access the crate's configuration, but the dioxus CLI was not used to build the application. Information about the Dioxus CLI is available at https://dioxuslabs.com/learn/0.5/CLI/installation");
}
}
+2
View File
@@ -42,6 +42,7 @@ impl std::fmt::Display for DioxusCLINotUsed {
impl std::error::Error for DioxusCLINotUsed {}
#[cfg(feature = "read-config")]
/// The current crate's configuration.
pub static CURRENT_CONFIG: once_cell::sync::Lazy<
Result<crate::config::CrateConfig, DioxusCLINotUsed>,
@@ -54,5 +55,6 @@ pub static CURRENT_CONFIG: once_cell::sync::Lazy<
})
});
#[cfg(feature = "read-config")]
/// The current crate's configuration.
pub const CURRENT_CONFIG_JSON: Option<&str> = std::option_env!("DIOXUS_CONFIG");