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

feat(bundler): Add support for creating NSIS bundles on unix hosts #5788

Merged
merged 33 commits into from
Jan 19, 2023

Conversation

FabianLars
Copy link
Member

@FabianLars FabianLars commented Dec 8, 2022

This should not be merged into the nsis branch directly, i just used it as a base here for a better diff view


This adds support for building nsis setup bundles (including the updater bundle) on Linux hosts. macos should hopefully work too but i am not sure how to get makensis there.

I explicitly have only the msvc toolchain in mind when talking about windows targets, even when cross compiling so the setup is a little bit more involved:

  • Install nsis, for example on ubuntu the command is sudo apt install nsis
  • the default MS linker doesn't work on Linux so we also need the LLD linker, on ubuntu it's just sudo apt install lld
  • add the msvc rust target rustup target add x86_64-pc-windows-msvc
  • Install the windows sdks:
    cargo install xwin
    xwin --accept-license splat --output ~/xwin
  • Add or modify .cargo/config.toml with these contents:
[target.x86_64-pc-windows-msvc]
linker = "lld"
rustflags = [
  "-Lnative=/home/username/xwin/crt/lib/x86_64",
  "-Lnative=/home/username/xwin/sdk/lib/um/x86_64",
  "-Lnative=/home/username/xwin/sdk/lib/ucrt/x86_64"
]

Now to the fun part:

  • Install this branch from git: cargo install tauri-cli --git https://github.com/tauri-apps/tauri --branch feat/nsis-linux
  • run cargo tauri build --target x86_64-pc-windows-msvc

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Docs
  • New Binding issue #___
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change?

  • Yes, and the changes were approved in issue #___
  • No, nopefully not.

Checklist

  • When resolving issues, they are referenced in the PR's title (e.g fix: remove a typo, closes #___, #___)
  • A change file is added if any packages will require a version bump due to this PR per the instructions in the readme.
  • I have added a convincing reason for adding this feature, if necessary

Copy link
Member

@amrbashir amrbashir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than these two nit-picks, I think this PR is ready

tooling/bundler/src/bundle.rs Outdated Show resolved Hide resolved
tooling/bundler/src/bundle.rs Outdated Show resolved Hide resolved
Base automatically changed from nsis to dev January 3, 2023 17:29
@FabianLars FabianLars marked this pull request as ready for review January 3, 2023 22:25
@FabianLars FabianLars requested a review from a team as a code owner January 3, 2023 22:25
@FabianLars
Copy link
Member Author

Should we maybe add a log output saying that cross compilation is experimental/unsupported or something? i have a feeling that saying this in the docs won't be enough x)

@FabianLars
Copy link
Member Author

oh and another thing, should nsis' verbose logging be tied to the --verbose flag?

@amrbashir
Copy link
Member

Should we maybe add a log output saying that cross compilation is experimental/unsupported or something? i have a feeling that saying this in the docs won't be enough x)

Sounds good!

oh and another thing, should nsis' verbose logging be tied to the --verbose flag?

by default, nsis is executed with maximum logging /V4, and will be presented with --verbose

@FabianLars
Copy link
Member Author

by default, nsis is executed with maximum logging /V4, and will be presented with --verbose

Ah yeah you're right. i always used the --verbose flag in my tests 😂 stupid muscle memory

@@ -33,17 +33,21 @@ tempfile = "3.3.0"
log = { version = "0.4.17", features = [ "kv_unstable" ] }
dirs-next = "2.0"

[target."cfg(target_os = \"windows\")".dependencies]
# dependencies for Windows targets
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

covector will strip this later :( so sad

@FabianLars
Copy link
Member Author

The timing of the warning may be a bit weird. It prints after cargo build, before it starts creating the bundles, so if tauri build fails at the actual compilation step already then this warning won't be seen, but at least it's not spammed away from the compiler output, and it's next to the other bundler logs.

Or maybe it needs some rephrasing so that it's more about the bundling step and not just cross-platform compilation 🤔

@lucasfernog
Copy link
Member

For macOS:

Install nsis:
brew install nsis

Install the lld linker:
brew install llvm
(also add /opt/homebrew/opt/llvm/bin to your PATH like suggested in the install output

add the msvc rust target:
rustup target add x86_64-pc-windows-msvc

Install the windows sdks:
cargo install xwin
xwin --accept-license splat --output ~/xwin --disable-symlinks

(I had to add the disable-symlinks flag otherwise it failed to run)

Add or modify .cargo/config.toml with these contents:

[target.x86_64-pc-windows-msvc]
linker = "lld"
rustflags = [
  "-Lnative=/Users/username/xwin/crt/lib/x86_64",
  "-Lnative=/Users/username/xwin/sdk/lib/um/x86_64",
  "-Lnative=/Users/username/xwin/sdk/lib/ucrt/x86_64"
]

@FabianLars FabianLars marked this pull request as draft January 4, 2023 15:28
@FabianLars
Copy link
Member Author

FabianLars commented Jan 4, 2023

marked it as draft again because of missing cross-compilation support in tauri-build. Going to look how we can add it with winres/winresource.

Edit: I think i found a way to use mingw's windres with the msvc setup from above. going to create tauri-winres tomorrow and update tauri-build accordingly.

@FabianLars
Copy link
Member Author

On Linux we now also need to do sudo apt install binutils-mingw-w64 - this will install the resource compiler for both 32 and 64 bit.
I'm also not 100% sure about the consequences of the winres changes, but that's why we print the warning i guess 😂

Now the problem is macOS, looks like you have to install the whole mingw-w64 toolchain :/ (brew install mingw-w64 ?)

@FabianLars FabianLars marked this pull request as ready for review January 5, 2023 21:54
@lucasfernog
Copy link
Member

Still works on Linux, and also works on macOS without downloading any extra dependency @FabianLars 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants