Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Resources for nsis installer when cross compiled are added to installer.nsi script with current OS separators #9656

Closed
jemmyw opened this issue May 4, 2024 · 2 comments
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@jemmyw
Copy link

jemmyw commented May 4, 2024

Describe the bug

I found that when cross compiling / bundling from Mac for Windows, the resources I added that were not in the root directory ended up in the root directory after install on Windows, even though the subdirectories had been created.

The reason for this is that in the installer.nsi file it does this:

  {{#each resources}}
    File /a "/oname={{this.[1]}}" "{{@key}}"
  {{/each}}

Where this.[1] is a PathBuf generated by generate_resource_data in nsis.rs. When bundling on Windows this will render with a \ and when bundling on *nix it will bundle with a /. Nsis always expects the path separators to be a \ and it appears to just ignore /

I've fixed it for myself by adding a handlebars helper:

  handlebars.register_helper(
    "win-path",
    Box::new(
      |h: &handlebars::Helper<'_, '_>,
       _: &Handlebars<'_>,
       _: &handlebars::Context,
       _: &mut handlebars::RenderContext<'_, '_>,
       out: &mut dyn handlebars::Output|
       -> handlebars::HelperResult {
        let param = h.param(0).unwrap();
        let value = param.value().render();
        let path = value.replace(MAIN_SEPARATOR_STR, "\\");
        out.write(&path)?;
        Ok(())
      },
    ),
  );

and changing the installer.nsi line:

    File /a "/oname={{win-path this.[1]}}" "{{@key}}"

which might not be the optimal fix but it proves the problem.

Reproduction

Add a resource in a subdirectory like:

      "resources": [
        "db/structure.sql"
      ],

in tauri.conf.json and then bundle on windows as per https://tauri.app/v1/guides/building/cross-platform

Expected behavior

Resources should end up in the same location regardless of platform the installer is built on

Full tauri info output

[✔] Environment
    - OS: Mac OS 14.4.1 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.77.2 (25ef9e3d8 2024-04-09)
    ✔ cargo: 1.77.2 (e52e36006 2024-03-26)
    ✔ rustup: 1.27.0 (bbb9276d2 2024-03-08)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 20.8.1
    - pnpm: 9.0.4
    - npm: 10.1.0

[-] Packages
    - tauri [RUST]: 1.6.1
    - tauri-build [RUST]: 1.5.1
    - wry [RUST]: 0.24.7
    - tao [RUST]: 0.16.7
    - @tauri-apps/api : not installed!
    - @tauri-apps/cli [NPM]: 1.5.11 (outdated, latest: 1.5.12)


### Stack trace

_No response_

### Additional context

_No response_
@jemmyw jemmyw added status: needs triage This issue needs to triage, applied to new issues type: bug labels May 4, 2024
@FabianLars
Copy link
Member

according to tauri info your cli is 1.5.11, can you update that to 1.5.12 and try again? This should have been fixed as part of #9281 which was part of 1.5.12 assuming of course i didn't miss anything...

@jemmyw
Copy link
Author

jemmyw commented May 5, 2024

Thanks, that looks like the fix I need!

@jemmyw jemmyw closed this as completed May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

No branches or pull requests

2 participants