diff --git a/Cargo.toml b/Cargo.toml index 0e0965e32..61a7964fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,7 +72,7 @@ dioxus-check = { path = "packages/check", version = "0.5.0-alpha.2" } dioxus-rsx = { path = "packages/rsx", version = "0.5.0-alpha.2" } rsx-rosetta = { path = "packages/rsx-rosetta", version = "0.5.0-alpha.2" } dioxus-signals = { path = "packages/signals", version = "0.5.0-alpha.2" } -dioxus-cli-config = { path = "packages/cli-config", version = "0.5.0-alpha.2" } +dioxus-cli-config = { path = "packages/cli-config", version = "0.5.0-alpha.2", default-features = false} generational-box = { path = "packages/generational-box", version = "0.5.0-alpha.2" } dioxus-hot-reload = { path = "packages/hot-reload", version = "0.5.0-alpha.2" } dioxus-fullstack = { path = "packages/fullstack", version = "0.5.0-alpha.2" } diff --git a/packages/cli-config/Cargo.toml b/packages/cli-config/Cargo.toml index 64992bcb6..8e31b21b9 100644 --- a/packages/cli-config/Cargo.toml +++ b/packages/cli-config/Cargo.toml @@ -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 = [] diff --git a/packages/cli-config/build.rs b/packages/cli-config/build.rs new file mode 100644 index 000000000..06741a669 --- /dev/null +++ b/packages/cli-config/build.rs @@ -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"); + } +} diff --git a/packages/cli-config/src/lib.rs b/packages/cli-config/src/lib.rs index da7446918..fcb5cd04c 100644 --- a/packages/cli-config/src/lib.rs +++ b/packages/cli-config/src/lib.rs @@ -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, @@ -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"); diff --git a/packages/cli/Cargo.toml b/packages/cli/Cargo.toml index 7a0938dd1..99d0c9eaa 100644 --- a/packages/cli/Cargo.toml +++ b/packages/cli/Cargo.toml @@ -15,7 +15,10 @@ thiserror = { workspace = true } wasm-bindgen-cli-support = "0.2" wasm-bindgen-shared = "0.2" colored = "2.0.0" -dioxus-cli-config = { workspace = true, features = ["cli"] } +dioxus-cli-config = { workspace = true, features = ["cli"], default-features = false } + +# features +log = "0.4.14" fern = { version = "0.6.0", features = ["colored"] } serde = { version = "1.0.136", features = ["derive"] } serde_json = "1.0.79" diff --git a/packages/desktop/Cargo.toml b/packages/desktop/Cargo.toml index aaa148823..c9fd2323d 100644 --- a/packages/desktop/Cargo.toml +++ b/packages/desktop/Cargo.toml @@ -18,7 +18,7 @@ dioxus-html = { workspace = true, features = [ "eval", ] } dioxus-interpreter-js = { workspace = true, features = ["binary-protocol"] } -dioxus-cli-config = { workspace = true } +dioxus-cli-config = { workspace = true, features = ["read-config"] } generational-box = { workspace = true } serde = "1.0.136" diff --git a/packages/fullstack/Cargo.toml b/packages/fullstack/Cargo.toml index 98eac307b..8f117b7e5 100644 --- a/packages/fullstack/Cargo.toml +++ b/packages/fullstack/Cargo.toml @@ -57,7 +57,7 @@ tower = { workspace = true, features = ["util"], optional = true } tower-layer = { version = "0.3.2", optional = true } web-sys = { version = "0.3.61", optional = true, features = ["Window", "Document", "Element", "HtmlDocument", "Storage", "console"] } -dioxus-cli-config = { workspace = true, optional = true } +dioxus-cli-config = { workspace = true, features = ["read-config"], optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] tokio = { workspace = true, features = ["rt", "sync"], optional = true } diff --git a/packages/liveview/Cargo.toml b/packages/liveview/Cargo.toml index 6e3036c3c..714f05aed 100644 --- a/packages/liveview/Cargo.toml +++ b/packages/liveview/Cargo.toml @@ -27,7 +27,7 @@ rustc-hash = { workspace = true } dioxus-core = { workspace = true, features = ["serialize"] } dioxus-interpreter-js = { workspace = true, features = ["binary-protocol"] } dioxus-hot-reload = { workspace = true, optional = true } -dioxus-cli-config = { workspace = true } +dioxus-cli-config = { workspace = true, features = ["read-config"] } generational-box = { workspace = true } # axum diff --git a/packages/router/Cargo.toml b/packages/router/Cargo.toml index d34376237..df4ee9d09 100644 --- a/packages/router/Cargo.toml +++ b/packages/router/Cargo.toml @@ -28,7 +28,7 @@ dioxus-liveview = { workspace = true, optional = true } dioxus-ssr = { workspace = true, optional = true } dioxus-fullstack = { workspace = true, optional = true } tokio = { workspace = true, features = ["full"], optional = true } -dioxus-cli-config = { workspace = true } +dioxus-cli-config = { workspace = true, features = ["read-config"] } [features] default = []