diff --git a/.changes/fix-nsis-resources-cross-compiling.md b/.changes/fix-nsis-resources-cross-compiling.md new file mode 100644 index 00000000..45b3c6ca --- /dev/null +++ b/.changes/fix-nsis-resources-cross-compiling.md @@ -0,0 +1,6 @@ +--- +"cargo-packager": patch +"@crabnebula/packager": patch +--- + +Fixes resources paths on NSIS when cross compiling. \ No newline at end of file diff --git a/crates/packager/src/package/nsis/mod.rs b/crates/packager/src/package/nsis/mod.rs index bb43ee95..c554d542 100644 --- a/crates/packager/src/package/nsis/mod.rs +++ b/crates/packager/src/package/nsis/mod.rs @@ -66,6 +66,21 @@ const NSIS_REQUIRED_FILES_HASH: &[(&str, &str, &str, HashAlgorithm)] = &[( type DirectoriesSet = BTreeSet; type ResourcesMap = BTreeMap; +#[cfg(windows)] +fn normalize_resource_path>(path: P) -> PathBuf { + path.as_ref().to_owned() +} + +// We need to convert / to \ for nsis to move the files into the correct dirs +#[cfg(not(windows))] +fn normalize_resource_path>(path: P) -> PathBuf { + path.as_ref() + .display() + .to_string() + .replace('/', "\\") + .into() +} + #[tracing::instrument(level = "trace", skip(config))] fn generate_resource_data(config: &Config) -> crate::Result<(DirectoriesSet, ResourcesMap)> { let mut directories = BTreeSet::new(); @@ -77,11 +92,11 @@ fn generate_resource_data(config: &Config) -> crate::Result<(DirectoriesSet, Res // since `INSTDIR` is already created. if let Some(parent) = r.target.parent() { if parent.as_os_str() != "" { - directories.insert(parent.to_path_buf()); + directories.insert(normalize_resource_path(parent)); } } - resources_map.insert(r.src, r.target); + resources_map.insert(r.src, normalize_resource_path(r.target)); } Ok((directories, resources_map)) } @@ -485,6 +500,7 @@ fn build_nsis_app_installer(ctx: &Context, nsis_path: &Path) -> crate::Result