Building for `x86_64-pc-windows-msvc` in GitLab CI

To create release builds for Windows in my pipeline, I currently use the official Rust Docker image and install the mingw-w64 package to build with the x86_64-pc-windows-gnu toolchain. It being a level 2 toolchain has now caused the pain point that I need to compile v8 from source for the Windows release build only.

So I would like to switch to the x86_64-pc-windows-msvc in the pipeline as it is what I'm using locally anyway.
I've seen various guides floating around how to get this toolchain up and running, but I'm wondering what the standard for dealing with it nowadays is.

I'm not familiar with gitlab, but I assume you need to cross compile from Linux rather than do a native build on Windows?

There is however a project for this:
GitHub - rust-cross/cargo-xwin: Cross compile Cargo project to Windows MSVC target with ease (I have not tried it myself as I mostly target only Linux, or I build on github CI which have native Windows runners).

(For completeness: For cross compiling to other Unixes/Linux flavours I recommend GitHub - cross-rs/cross: “Zero setup” cross compilation and “cross testing” of Rust crates or GitHub - rust-cross/cargo-zigbuild: Compile Cargo project with zig as linker. I believe there is also ways to get cross compiling working for MacOS X, but I have heard that is very hacky.)

Another option for your use case might be to pre-build and cache v8, so that you don't need to build it from scratch every time.

why not just use a windows ci host? rust is not pre-insalled on their hosted VMs, but visual C++ build tool is, and installing rustup is super easy.

it's way less friction to use a native toolchain than cross compiling it from a linux host.

also, you can setup your own windows machine as your ci runner.

Not sure what do you mean here? At least the rustc book shows it as "Tier 1 with host tools".

1 Like

you might be thinking of how i686-pc-windows-gnu was demoted to tier 2, but x86_64-pc-windows-gnu is still tier 1

Apologies, a v8 contributer told me that the Windows GNU toolchain was not a first class target and I mistakenly thought that was because the toolchain was a tier 2, but it seems to be a project-internal thing.

I'm using a self-hosted GitLab in my organisation and it seems like they only provide Linux runners. Might see if it's worth setting up our own runner on our local machine.

I'll give cargo-xwin a try and report back!