diff --git a/packages/cli/src/cli/bundle.rs b/packages/cli/src/cli/bundle.rs index 7a7bafcfe..cf8314614 100644 --- a/packages/cli/src/cli/bundle.rs +++ b/packages/cli/src/cli/bundle.rs @@ -183,7 +183,35 @@ impl Bundle { bail!("\n\nBundle publisher was not provided in `Dioxus.toml`. Add it as:\n\n[bundle]\npublisher = \"MyCompany\"\n\n"); } + /// Resolve an icon path relative to the crate dir + fn canonicalize_icon_path(build: &BuildRequest, icon: &mut String) -> Result<(), Error> { + let icon_path = build + .crate_dir() + .join(&icon) + .canonicalize() + .with_context(|| format!("Failed to canonicalize path to icon {icon:?}"))?; + *icon = icon_path.to_string_lossy().to_string(); + Ok(()) + } + + // Resolve bundle.icon relative to the crate dir + if let Some(icons) = bundle_settings.icon.as_mut() { + for icon in icons.iter_mut() { + canonicalize_icon_path(build, icon)?; + } + } + + #[allow(deprecated)] if cfg!(windows) { + // Resolve bundle.windows.icon_path relative to the crate dir + let mut windows_icon_path = bundle_settings + .windows + .icon_path + .to_string_lossy() + .to_string(); + canonicalize_icon_path(build, &mut windows_icon_path)?; + bundle_settings.windows.icon_path = PathBuf::from(&windows_icon_path); + let windows_icon_override = krate.config.bundle.windows.as_ref().map(|w| &w.icon_path); if windows_icon_override.is_none() { let icon_path = bundle_settings @@ -197,18 +225,6 @@ impl Bundle { } } - // resolve the icon relative to the crate, not the current working directory - if let Some(icons) = bundle_settings.icon.as_mut() { - for icon in icons { - let icon_path = build - .crate_dir() - .join(&icon) - .canonicalize() - .with_context(|| format!("Failed to canonicalize path to icon {icon:?}"))?; - *icon = icon_path.to_string_lossy().to_string(); - } - } - if bundle_settings.resources_map.is_none() { bundle_settings.resources_map = Some(HashMap::new()); }