burtonageo / cargo-bundle

Wrap rust executables in OS-specific app bundles
Other
1.03k stars 69 forks source link

Implement .msi support for Windows targets #116

Open John-Nagle opened 2 years ago

John-Nagle commented 2 years ago

Windows support is still unavailable, after four years.

Anyone doing that?

Discussion: https://internals.rust-lang.org/t/cross-platform-bundling/16773

Useful crate for reading and writing .msi files: "rust-msi".

I'd like to have minimal .msi support - install, uninstall, maybe upgrade. No registry keys, no signing. Enough that a cross-plaform program can be made a first-class Windows application without difficulty.

(It's sort of possible to do this with the Wix or Tauri toolchains, but those are whole systems that bypass or wrap Cargo. There used to be "tauri-bundler", but it's been discontinued, and it relies on "candle.exe" and "flame.exe" from Wix, which are also being discontinued as those systems become more monolithic.)

mdsteele commented 2 years ago

I'm not aware of anyone currently working on this. PRs would be very welcome!

A while back I took an initial stab in src/bundle/msi_bundle.rs at using the msi crate to create a minimal installer, but I lacked the background knowledge to know exactly which tables need to be populated and how, and I don't have a Windows machine readily available for testing, so of course I didn't get very far.

If someone wants to try getting MSI bundling working, the code currently in msi_bundle.rs should give some idea of how to go about using the msi crate to populate the installer tables, but don't hesitate to completely rewrite what's already in there if needed.

John-Nagle commented 2 years ago

but I lacked the background knowledge to know exactly which tables need to be populated and how, and I don't have a Windows machine readily available for testing, so of course I didn't get very far.

That's where I am. I took a look at this, and it clearly requires a lot of Microsoft-specific knowledge. A minimal bundler, just taking the info from Cargo.toml and generating a .msi file, would be very useful, and probably not too hard for someone who works in the Microsoft ecosystem. There are lots of other things you can do in a .msi file, most of which are not essential to making cross-platform Rust programs.

JessicaTegner commented 1 year ago

hi I can't help but notice that there is an inconsistency in what we want here.

On MacOS, we get an .app bundle, which is essentially just a folder, while as on Windows (and for that matter also linux) we want, or are already getting a package like format.

What is the end goal? To "just" get a package format? In that case, #113 would probably also need to be implemented to be consistent throughout platforms. If we "only" want a folder that another tool can then package up as needed (fx: zip, tar etc) we would need to rethink Windows support and change how Linux are done.

In any case, my primary OS is Windows and I have some experience on the MS side, so I would be happy to give this a stap, just wondering which way we are going.

John-Nagle commented 1 year ago

The goal is to create a file in the format which most users of the platform would consider a normal application to be installed.

JessicaTegner commented 1 year ago

But that can be anything, as there's no singular truth to what format to expect for a Windows installer.

It can be a .msi, an .exe, made with Wix,, MSI, NSIS, 7ZIP or any other number of tools.

mdsteele commented 1 year ago

I think there's room for supporting multiple packaging options for a given OS (selectable via command-line flag). The main reason for wanting to support MSI installers in particular (rather than just a plain .exe) is to allow for bundling resources/libraries that the main executable depends on. But if someone wants to try implementing a different Windows packaging scheme instead of (or in addition to) MSI, that would be great too.

John-Nagle commented 1 year ago

The general idea is to have a distribution format which which non-technical Windows users are comfortable. This excludes raw .exe and .zip. It should be something that doesn't generate scary security warning messages on installation. Ideally, something you could submit to the Windows app store.

JessicaTegner commented 1 year ago

maybe it's worth taking a look at https://github.com/tauri-apps/tauri/tree/dev/tooling/bundler since it's based on this. In addition, they seem to be using WIX (an easier to use, xml version of msi). It sitll produces MSI, but has a toolset to easily generate them based on a xml configuration file.

John-Nagle commented 1 year ago

maybe it's worth taking a look at https://github.com/tauri-apps/tauri/tree/dev/tooling/bundler since it's based on this.

That's not cross platform. You can only build Windows executables on Windows. It uses DLLs from an old version of Wix. See https://github.com/tauri-apps/tauri/blob/dev/tooling/bundler/src/bundle/windows/msi.rs

If you're running on Windows, you can use a Microsoft tool to do this.

The goal here is to be able to generate installables for all the Rust-supported desktop platforms without having one of each on your desk. Rust can generate executables, but the last step, the installer, isn't portable yet.

avsaase commented 1 year ago

I've been following this issue for a while so I'll give my 2c.

The compilation step is already not completely cross platform because you cannot cross-compile for MacOS. So in practice if you want to support all platforms you're already working with multiple machines or something like GitHub Actions.

For a side project I'm using cargo-bundle for the Mac app bundle and cargo-wix for the Windows msi installer. The latter is not really maintained anymore and requires quite a bit of fiddling with xml files. It would already be a huge win if all the configuration of the bundling/installer compilation could be handled by cargo-bundle, even if the process is not cross platform.

JessicaTegner commented 1 year ago

Just chiming in again with the following. What do you think @burtonageo

We could implement a NSIS package option for Windows Target as was briefly talked about in tauri-apps/tauri#6474 as WIX is a pain to work with. And before we restart the whole cross platform support thing, which we all agree is a valid point, it looks like NSIS (makensis) can be installed from homebrew or macports. I know it's not pure, without external dependencies, but I feel this is the best solution from the simple fact that it's 10x easier to implement, customize, theme and it comes with everything that MSI/WIX comes with and much, much more.

And bonus point: I feel if we ask nicely, we could get the tauri people to assist on this, since they already have it done (and are also pushing people toward that for the same reasons)