From 1ed66a54ccb1bea750ee8dd6cdb91bb45b5d33cd Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Tue, 14 Nov 2023 15:50:04 -0600 Subject: [PATCH] fix cli configuration environment variable --- packages/cli-config/Cargo.toml | 1 + packages/cli-config/src/assets/dioxus.toml | 74 ---------------------- packages/cli-config/src/bundle.rs | 1 + packages/cli-config/src/lib.rs | 11 +++- packages/cli/src/builder.rs | 6 +- packages/cli/src/main.rs | 1 + 6 files changed, 13 insertions(+), 81 deletions(-) delete mode 100644 packages/cli-config/src/assets/dioxus.toml diff --git a/packages/cli-config/Cargo.toml b/packages/cli-config/Cargo.toml index 2ef7ce8e6..376dd3240 100644 --- a/packages/cli-config/Cargo.toml +++ b/packages/cli-config/Cargo.toml @@ -19,6 +19,7 @@ cargo_toml = "0.16.0" tauri-bundler = { version = "=1.3.0", features = ["native-tls-vendored"], optional = true } tauri-utils = { version = "=1.4.*", optional = true } once_cell = "1.18.0" +tracing.workspace = true [features] default = [] diff --git a/packages/cli-config/src/assets/dioxus.toml b/packages/cli-config/src/assets/dioxus.toml deleted file mode 100644 index 892a6cdf8..000000000 --- a/packages/cli-config/src/assets/dioxus.toml +++ /dev/null @@ -1,74 +0,0 @@ -[application] - -# dioxus project name -name = "{{project-name}}" - -# default platfrom -# you can also use `dx serve/build --platform XXX` to use other platform -# value: web | desktop -default_platform = "{{default-platform}}" - -# Web `build` & `serve` dist path -out_dir = "dist" - -# resource (static) file folder -asset_dir = "public" - -[web.app] - -# HTML title tag content -title = "Dioxus | An elegant GUI library for Rust" - -[web.watcher] - -index_on_404 = true - -watch_path = ["src", "examples"] - -# include `assets` in web platform -[web.resource] - -# CSS style file -style = [] - -# Javascript code file -script = [] - -[web.resource.dev] - -# Javascript code file -# serve: [dev-server] only -script = [] - -[application.plugins] - -available = true - -required = [] - -[bundler] -# Bundle identifier -identifier = "io.github.{{project-name}}" - -# Bundle publisher -publisher = "{{project-name}}" - -# Bundle icon -icon = ["icons/icon.png"] - -# Bundle resources -resources = ["public/*"] - -# Bundle copyright -copyright = "" - -# Bundle category -category = "Utility" - -# Bundle short description -short_description = "An amazing dioxus application." - -# Bundle long description -long_description = """ -An amazing dioxus application. -""" \ No newline at end of file diff --git a/packages/cli-config/src/bundle.rs b/packages/cli-config/src/bundle.rs index cdae4539b..4f44036d7 100644 --- a/packages/cli-config/src/bundle.rs +++ b/packages/cli-config/src/bundle.rs @@ -231,6 +231,7 @@ pub enum WebviewInstallMode { FixedRuntime { path: PathBuf }, } +#[cfg(feature = "cli")] impl WebviewInstallMode { fn into(self) -> tauri_utils::config::WebviewInstallMode { match self { diff --git a/packages/cli-config/src/lib.rs b/packages/cli-config/src/lib.rs index b7b505760..776d1d10c 100644 --- a/packages/cli-config/src/lib.rs +++ b/packages/cli-config/src/lib.rs @@ -46,8 +46,13 @@ impl std::error::Error for DioxusCLINotUsed {} pub static CURRENT_CONFIG: once_cell::sync::Lazy< Result, > = once_cell::sync::Lazy::new(|| { - std::env::var(crate::__private::CONFIG_ENV) - .ok() + CURRENT_CONFIG_JSON .and_then(|config| serde_json::from_str(&config).ok()) - .ok_or(DioxusCLINotUsed) + .ok_or_else(|| { + tracing::error!("A library is trying to access the crate's configuration, but the dioxus CLI was not used to build the application."); + DioxusCLINotUsed + }) }); + +/// The current crate's configuration. +pub const CURRENT_CONFIG_JSON: Option<&str> = std::option_env!("DIOXUS_CONFIG"); diff --git a/packages/cli/src/builder.rs b/packages/cli/src/builder.rs index 1492e0868..a2ee2c73f 100644 --- a/packages/cli/src/builder.rs +++ b/packages/cli/src/builder.rs @@ -47,6 +47,7 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result { let ignore_files = build_assets(config)?; let t_start = std::time::Instant::now(); + let _guard = dioxus_cli_config::__private::save_config(config); // [1] Build the .wasm module log::info!("🚅 Running build command..."); @@ -90,8 +91,6 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result { ExecutableType::Example(name) => cmd.arg("--example").arg(name), }; - let _ = dioxus_cli_config::__private::save_config(config); - let warning_messages = prettier_build(cmd)?; // [2] Establish the output directory structure @@ -254,6 +253,7 @@ pub fn build_desktop(config: &CrateConfig, _is_serve: bool) -> Result Result cmd.arg("--example").arg(name), }; - let _ = dioxus_cli_config::__private::save_config(config); - let warning_messages = prettier_build(cmd)?; let release_type = match config.release { diff --git a/packages/cli/src/main.rs b/packages/cli/src/main.rs index fe860a0e6..51b884a9a 100644 --- a/packages/cli/src/main.rs +++ b/packages/cli/src/main.rs @@ -1,3 +1,4 @@ +use dioxus_cli_config::DioxusConfig; use std::path::PathBuf; use anyhow::anyhow;