Current recommendations for occasional Windows builds

I'm after some useful recommendations for a relatively simple occasional-use windows build setup. I'm writing this while a new Windows VM is going through install, update, visual studio tools setup, and (eventually) rustup install.

All so I can build a Windows binary of a quickie CLI tool for someone. The last time I did this (for testing something quickly) was long enough ago that that VM image would probably take even longer to update than a fresh install.

What would be a better way? Some thoughts and details that might guide better recommendations:

  • I'm not (particularly) after a CI platform, partly because of extra setup for adhoc projects (that might not even be mine), and partly because I probably want an interactive way to run the generated binary a few times for tests and validation. That said, if there's some basically painless way to do it that works with gitlab runner, I'm interested.
  • I could (and absent better suggestions, will probably) just do roughly what I'm doing now, but with an AWS (or whatever) instance rather than a local VM. At least the initial install will be via a clone, and the updates and disk IO will probably be faster.
  • I use VSCode on Linux, and the remote tools are great to other linux instances. There is some stuff in there I haven't really investigated to launch Azure build instances. I'm sure that includes Windows and they've made the UX pretty slick, but I'm not sure what the availability of Rust is in those platforms. If this install takes much longer, that's probably what I'll go read up on next - but I would welcome any endorsements or cautions from others who have tried it (especially if you use windows regularly and have tripped over something I'm unlikely to know what to do with). Update Windows only available as a part of a VS (not -code) private preview, so far.
  • Other things I haven't thought of?
  • [Edit]: as I have now reached the point where I realise I also need a windows version of git, perhaps what I want is a more automated way of doing the setup - an ansible playbook to install all the needed things would be useful, if it can work unattended.

Unlike C++ and associated languages, Rust's cross-compilation support is superb. You can simply run rustup target add x86_64-pc-windows-gnu, and then build as normal, but with the --target x86_64-pc-windows-gnu flag to Cargo. For example, cargo build --release --target x86_64-pc-windows-gnu. This will work without any further changes for programs that use pure Rust libraries, and many that don't. For those that don't, some wrangling is required, but I have yet to see a case where it isn't possible.

This will, of course, use the GCC toolchain, but in my experience this toolchain works very well, and, of course, it has a more favorable license than MSVC. The only main downside of this technique is that some libraries may require an MSVC toolchain. Note also that the rustup command above will automatically get the MinGW/GCC linker.

EDIT: If you need a Windows VM to test in, this may be of interest, and it includes many developer tools out of the box such as Visual Studio. Make sure to read the license agreement for it though.

I just use the x86_64-pc-windows-gnu target with https://github.com/rust-embedded/cross to cross compile for Windows from Linux. May not work for everything, but I've used it with fairly complicated CLI tool.

Hmm.. I had discounted cross-compilation some time ago. I don't really recall why, probably suspicious about problems with native libraries in at least one of the cases, but it might be worth another look for some uses.

However, as with the CI case, I will still want to run the thing to test that it works on Windows, so this is still only a partial solution.

Did you see the edit at the bottom of my post? Wine can also be helpful, albeit not perfect, on Linux.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.