8 releases

0.1.2 Aug 9, 2019
0.1.1 Mar 12, 2019
0.1.0 Nov 15, 2018
0.0.5 May 10, 2018
0.0.2 Dec 12, 2017

#40 in Cargo plugins

Download history 18/week @ 2019-04-26 23/week @ 2019-05-03 20/week @ 2019-05-10 33/week @ 2019-05-17 26/week @ 2019-05-24 8/week @ 2019-05-31 75/week @ 2019-06-07 41/week @ 2019-06-14 140/week @ 2019-06-21 39/week @ 2019-06-28 67/week @ 2019-07-05 77/week @ 2019-07-12 19/week @ 2019-07-19 31/week @ 2019-07-26 30/week @ 2019-08-02

202 downloads per month

MIT/Apache

316KB
4.5K SLoC

Rust 4K SLoC // 0.3% comments Mustache 449 SLoC // 0.1% comments

cargo-wix: A cargo subcommand to create Windows installers

A subcommand for Cargo that builds a Windows installer (msi) using the Wix Toolset from the release build of a Rust binary project. It also supports signing the Windows installer if a code signing certificate is available using the SignTool application available in the Windows 10 SDK.

Crates.io GitHub release Crates.io

Quick Start

Start a command prompt (cmd.exe) and then execute the following commands:

C:\>cargo install cargo-wix
C:\>cd Path\To\Project
C:\Path\To\Project\>cargo wix init
C:\Path\To\Project\>cargo wix

The Windows installer (msi) for the project will be in the C:\Path\To\Project\target\wix folder.

Installation

The cargo-wix project can be installed on any platform supported by the Rust programming language, but the Wix Toolset is Windows only; thus, this project is only useful when installed on a Windows machine. Ensure the following dependencies are installed before proceeding. Note, Cargo is installed automatically when installing the Rust programming language. The stable-x86_64-pc-windows-msvc toolchain is recommended.

After installing and configuring the dependencies, execute the following command to install the cargo-wix subcommand:

C:\> cargo install cargo-wix

Usage

Start a command prompt, such as cmd.exe, the Developer Prompt installed with the VC Build Tools (recommended), or git bash, and navigate to the project's root folder. Run the subcommand:

C:\Path\to\Project> cargo wix init

This will create the wix folder in the project's root (along side the Cargo.toml file) and then it will create the wix\main.wxs file from the WiX Source (wxs) embedded within the subcommand. The generated wix\main.wxs file can be used without modification with the following command to create an installer for the project:

C:\Path\to\Project> cargo wix

The cargo wix subcommand without any arguments searches for a wix\main.wxs file, relative to the project's root. It will compile the wix\main.wxs file and then link the object file (target\wix\build\main.wixobj) to create the Windows installer (msi). The installer will be located in the target\wix folder. All artifacts of the installer compilation and linking process are placed within the target\wix folder. Paths in the wix\main.wxs file should be relative to the project's root, i.e. the same location as the Cargo.toml manifest file.

A different WiX Source (wxs) file from the wix\main.wxs file can be used by specifying a path to it as an argument to the subcommand as follows:

C:\Path\to\Project> cargo wix Path\to\WiX\Source\File.wxs

The print <template> subcommand, which prints one of the embedded templates to stdout, can be used to create the main.wxs file. A WXS template file specifically designed to work with this subcommand is embedded within the cargo-wix binary during installation. Use the following commands to create a WiX Source file and use it to create an installer with this subcommand.

C:\Path\to\Project> cargo wix print wxs > example.wxs
C:\Path\to\Project> cargo wix example.wxs

The WiX source file can be customized using a text editor, but modification of the XML preprocessor variables should be avoided to ensure the cargo wix command works properly.

To sign the installer (msi) as part of the build process, ensure the signtool command is available in the PATH system environment variable or use the Developer Prompt that was installed with the Windows 10 SDK, and use the sign sub-subcommand as follows:

C:\Path\to\Project> cargo wix sign

Use the -h,--help flag to display information about additional options and features.

C:\Path\to\Project> cargo wix -h

Tests

The tests can be run using the cargo test -- --test-threads=1 command from the root folder of the project, i.e. the same location as the Cargo.toml file. The --test-threads=1 option appears to be needed when running the integration tests because sometimes if the integration tests are run in parallel (default without the option) some of the tests will fail. I believe this is related to creating temporary test projects using Cargo. There appears to be some kind of race condition that causes Cargo to not create separate projects for each of the integration tests.

License

The cargo-wix project is licensed under either the MIT license or Apache 2.0 license. See the LICENSE-MIT or LICENSE-APACHE files for more information about licensing and copyright.

Dependencies

~6MB
~110K SLoC