|
@@ -11,19 +11,23 @@ pub use bundle::*;
|
|
mod serve;
|
|
mod serve;
|
|
pub use serve::*;
|
|
pub use serve::*;
|
|
|
|
|
|
|
|
+mod build_info;
|
|
|
|
+
|
|
#[doc(hidden)]
|
|
#[doc(hidden)]
|
|
pub mod __private {
|
|
pub mod __private {
|
|
use crate::DioxusConfig;
|
|
use crate::DioxusConfig;
|
|
|
|
|
|
|
|
+ pub(crate) const DIOXUS_CLI_VERSION: &str = "DIOXUS_CLI_VERSION";
|
|
pub(crate) const CONFIG_ENV: &str = "DIOXUS_CONFIG";
|
|
pub(crate) const CONFIG_ENV: &str = "DIOXUS_CONFIG";
|
|
pub(crate) const CONFIG_BASE_PATH_ENV: &str = "DIOXUS_CONFIG_BASE_PATH";
|
|
pub(crate) const CONFIG_BASE_PATH_ENV: &str = "DIOXUS_CONFIG_BASE_PATH";
|
|
|
|
|
|
- pub fn save_config(config: &DioxusConfig) -> CrateConfigDropGuard {
|
|
|
|
|
|
+ pub fn save_config(config: &DioxusConfig, cli_version: &str) -> CrateConfigDropGuard {
|
|
std::env::set_var(CONFIG_ENV, serde_json::to_string(config).unwrap());
|
|
std::env::set_var(CONFIG_ENV, serde_json::to_string(config).unwrap());
|
|
std::env::set_var(
|
|
std::env::set_var(
|
|
CONFIG_BASE_PATH_ENV,
|
|
CONFIG_BASE_PATH_ENV,
|
|
config.web.app.base_path.clone().unwrap_or_default(),
|
|
config.web.app.base_path.clone().unwrap_or_default(),
|
|
);
|
|
);
|
|
|
|
+ std::env::set_var(DIOXUS_CLI_VERSION, cli_version);
|
|
CrateConfigDropGuard
|
|
CrateConfigDropGuard
|
|
}
|
|
}
|
|
|
|
|
|
@@ -34,6 +38,7 @@ pub mod __private {
|
|
fn drop(&mut self) {
|
|
fn drop(&mut self) {
|
|
std::env::remove_var(CONFIG_ENV);
|
|
std::env::remove_var(CONFIG_ENV);
|
|
std::env::remove_var(CONFIG_BASE_PATH_ENV);
|
|
std::env::remove_var(CONFIG_BASE_PATH_ENV);
|
|
|
|
+ std::env::remove_var(DIOXUS_CLI_VERSION);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -61,11 +66,28 @@ pub static CURRENT_CONFIG: once_cell::sync::Lazy<
|
|
Result<crate::config::DioxusConfig, DioxusCLINotUsed>,
|
|
Result<crate::config::DioxusConfig, DioxusCLINotUsed>,
|
|
> = once_cell::sync::Lazy::new(|| {
|
|
> = once_cell::sync::Lazy::new(|| {
|
|
CURRENT_CONFIG_JSON
|
|
CURRENT_CONFIG_JSON
|
|
- .and_then(|config| serde_json::from_str(config).ok())
|
|
|
|
- .ok_or_else(|| {
|
|
|
|
- tracing::warn!("A library is trying to access the crate's configuration, but the dioxus CLI was not used to build the application.");
|
|
|
|
- DioxusCLINotUsed
|
|
|
|
- })
|
|
|
|
|
|
+ .ok_or_else(|| {
|
|
|
|
+ tracing::warn!("A library is trying to access the crate's configuration, but the dioxus CLI was not used to build the application.");
|
|
|
|
+ DioxusCLINotUsed
|
|
|
|
+}).and_then(
|
|
|
|
+ |config|
|
|
|
|
+ match serde_json::from_str(config) {
|
|
|
|
+ Ok(config) => Ok(config),
|
|
|
|
+ Err(err) => {
|
|
|
|
+ let mut cli_version = crate::build_info::PKG_VERSION.to_string();
|
|
|
|
+
|
|
|
|
+ if let Some(hash) = crate::build_info::GIT_COMMIT_HASH_SHORT {
|
|
|
|
+ let hash = &hash.trim_start_matches('g')[..4];
|
|
|
|
+ cli_version.push_str(&format!("-{hash}"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let dioxus_version = std::option_env!("DIOXUS_CLI_VERSION").unwrap_or("unknown");
|
|
|
|
+
|
|
|
|
+ tracing::warn!("Failed to parse the CLI config file. This is likely caused by a mismatch between the version of the CLI and the dioxus version.\nCLI version: {cli_version}\nDioxus version: {dioxus_version}\nSerialization error: {err}");
|
|
|
|
+ Err(DioxusCLINotUsed)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+)
|
|
});
|
|
});
|
|
|
|
|
|
#[cfg(feature = "read-config")]
|
|
#[cfg(feature = "read-config")]
|