From 15d369f10f1a51bff877dc8ef705548fac06966b Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Wed, 23 Jul 2025 19:47:41 -0500 Subject: [PATCH] Fix asset location for linux bundles (#4460) * fix linux bundle * fix release mode * fix resource path * only use asset dir if it exists * add comment about directory structure * don't unwrap parent --- packages/asset-resolver/src/lib.rs | 21 ++++++++++++++++++++- packages/cli-config/src/lib.rs | 6 ++++++ packages/cli/src/build/request.rs | 3 ++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/asset-resolver/src/lib.rs b/packages/asset-resolver/src/lib.rs index a5bc28250..aa442873f 100644 --- a/packages/asset-resolver/src/lib.rs +++ b/packages/asset-resolver/src/lib.rs @@ -80,7 +80,7 @@ pub fn serve_asset(path: &str) -> Result>, AssetServeError> { /// - [x] Windows /// - [x] Linux (appimage) /// - [ ] Linux (rpm) -/// - [ ] Linux (deb) +/// - [x] Linux (deb) /// - [ ] Android #[allow(unreachable_code)] fn get_asset_root() -> PathBuf { @@ -96,6 +96,25 @@ fn get_asset_root() -> PathBuf { .join("Resources"); } + #[cfg(target_os = "linux")] + { + // In linux bundles, the assets are placed in the lib/$product_name directory + // bin/ + // main + // lib/ + // $product_name/ + // assets/ + if let Some(product_name) = dioxus_cli_config::product_name() { + let lib_asset_path = || { + let path = cur_exe.parent()?.parent()?.join("lib").join(product_name); + path.exists().then_some(path) + }; + if let Some(asset_dir) = lib_asset_path() { + return asset_dir; + } + } + } + // For all others, the structure looks like this: // app.(exe/appimage) // main.exe diff --git a/packages/cli-config/src/lib.rs b/packages/cli-config/src/lib.rs index 4eca501d3..e3092266a 100644 --- a/packages/cli-config/src/lib.rs +++ b/packages/cli-config/src/lib.rs @@ -64,6 +64,7 @@ pub const DEVSERVER_PORT_ENV: &str = "DIOXUS_DEVSERVER_PORT"; pub const ALWAYS_ON_TOP_ENV: &str = "DIOXUS_ALWAYS_ON_TOP"; pub const ASSET_ROOT_ENV: &str = "DIOXUS_ASSET_ROOT"; pub const APP_TITLE_ENV: &str = "DIOXUS_APP_TITLE"; +pub const PRODUCT_NAME_ENV: &str = "DIOXUS_PRODUCT_NAME"; #[deprecated(since = "0.6.0", note = "The CLI currently does not set this.")] #[doc(hidden)] @@ -327,3 +328,8 @@ pub fn build_id() -> u64 { .unwrap_or(0) } } + +/// The product name of the bundled application. +pub fn product_name() -> Option { + read_env_config!("DIOXUS_PRODUCT_NAME") +} diff --git a/packages/cli/src/build/request.rs b/packages/cli/src/build/request.rs index 346204606..ed1a9cfe7 100644 --- a/packages/cli/src/build/request.rs +++ b/packages/cli/src/build/request.rs @@ -323,7 +323,7 @@ use crate::{ use anyhow::{bail, Context}; use cargo_metadata::diagnostic::Diagnostic; use depinfo::RustcDepInfo; -use dioxus_cli_config::format_base_path_meta_element; +use dioxus_cli_config::{format_base_path_meta_element, PRODUCT_NAME_ENV}; use dioxus_cli_config::{APP_TITLE_ENV, ASSET_ROOT_ENV}; use dioxus_cli_opt::{process_file_to, AssetManifest}; use itertools::Itertools; @@ -2423,6 +2423,7 @@ impl BuildRequest { env_vars.push((ASSET_ROOT_ENV.into(), base_path.to_string())); } env_vars.push((APP_TITLE_ENV.into(), self.config.web.app.title.clone())); + env_vars.push((PRODUCT_NAME_ENV.into(), self.bundled_app_name())); } // Assemble the rustflags by peering into the `.cargo/config.toml` file