Skip to content

Commit

Permalink
fix(nsis): resources paths when cross compiling (#283)
Browse files Browse the repository at this point in the history
* fix(nsis): resources paths when cross compiling

* update change file

* fix fn
  • Loading branch information
lucasfernog-crabnebula authored Oct 9, 2024
1 parent 2d198f3 commit 4523722
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changes/fix-nsis-resources-cross-compiling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"cargo-packager": patch
"@crabnebula/packager": patch
---

Fixes resources paths on NSIS when cross compiling.
20 changes: 18 additions & 2 deletions crates/packager/src/package/nsis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ const NSIS_REQUIRED_FILES_HASH: &[(&str, &str, &str, HashAlgorithm)] = &[(
type DirectoriesSet = BTreeSet<PathBuf>;
type ResourcesMap = BTreeMap<PathBuf, PathBuf>;

#[cfg(windows)]
fn normalize_resource_path<P: AsRef<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<P: AsRef<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();
Expand All @@ -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))
}
Expand Down Expand Up @@ -485,6 +500,7 @@ fn build_nsis_app_installer(ctx: &Context, nsis_path: &Path) -> crate::Result<Ve
data.insert("out_file", to_json(out_file));

let (resources_dirs, resources) = generate_resource_data(config)?;
println!("{:?} {:?}", resources_dirs, resources);
data.insert("resources_dirs", to_json(resources_dirs));
data.insert("resources", to_json(&resources));

Expand Down

0 comments on commit 4523722

Please sign in to comment.