Rust on Windows

  1. Does Rust still require Microsoft Build Tools etc.?

  2. Is the GNU triplet on Windows still not tier 1?

  3. Are Rust builds slower than on Linux (has this been improved?)

Is development using Rust better on Linux in general? (I have that impression, especially with 1.90 - lld linker for build performance.)

1 Like
  1. You can supposedly use mingw, without needing the MS tools.
  2. According to the rustc book, x86_64-pc-windows-gnu is Tier 1.
  3. I would say yes. We support Windows, macOS and Linux for most of our projects and while compilation is noticeably slower on Windows, the linking of large binaries can take a surprising amount of time (even without LTO).

Personally I have no problem developing on Windows most of the time. The only time I switch to my mac or a Linux system is if the project's binary is large and I need to iterate a lot (edit-build-test loop).

1 Like

...-windows-gnu Tier 1 - great - thanks!

RE build times:

  1. Does gnu vs msvc make a difference?
  2. Large binaries - does dynamic vs static linking with libs make a difference?

I wonder what is the chance to use third party linkers to improve the build time. for instance, the linker from the rad debugger project claims to be compatible with msvc linker command line and is optimized to be fast especially for large binaries.

1 Like
  1. I don't know -- I haven't use mingw myself. Now that you mention it, perhaps I should give it a try.
  2. I haven't used dynamic linking on Windows, so I can't really answer that. With that said, one of our employees used bevy's dynamic linking support on Windows for a test project and he hasn't complained about the linking time in that project. So cautiously ... maybe?

Regarding build times on Windows -- I don't think the major problem is Rust, to be honest. We have a pretty large C++ project that we support on all three major platforms, and it's similarly much slower to build on Windows. We can cut down the build time pretty substantially by using Ninja (vs msbuild), but even with that it's much slower than on mac and Linux. There have been some discussions about what exactly is causing slower builds over the years; some people say it's the filesystem, others say it's that process creation is much slower, and there are a bunch of other theories. Personally, I believe it's a combination of several factors..

Apparently Windows nowadays has a special "developer drive" (ReFS with some custom tuning). I haven't tried this, but maybe that helps?

If you think the build time will become a problem, I would probably suggest going with Linux. But also, keep in mind that the Windows build times bother me because I move between systems a lot, so I notice how much slower Windows builds are. We have Windows-only devs who don't think Windows builds are slow. So maybe the trick is to only use Windows, so you don't know how much faster it can be. :slight_smile:

1 Like

Hm -- that looks super interesting, I know Epic are quite concerned about build times (Unreal Engine binaries can easily balloon to several hundreds of MB). I'm going to give that a try.

I was using Linux, but my new internet service gateway only has WiFi, and Windows can be installed without an ethernet connection. (My WiFi card is LinkSys and the Linux kernel doesn't have a default driver for that.) Windows still has some advantages on the desktop, so I reinstalled it (despite efforts to escape Windows on three different occasions :slight_smile: ). Chrome OS Flex is also great but same issue with WiFi drivers and installation. So, alas, I have the Windows "golden handcuffs" as they say :slight_smile:

The tip about ReFS for Rust builds is great and I may try the gnu. The info specifically mentions Rust builds:
Set up a Dev Drive on Windows 11

Thanks kindly for all the info.

I use Rust on Windows daily. Say more, I updated several projects on Windows machine just today, the compilation here is a light speed fast.

1 Like

Thank you. Great to know. You are using the standard Windows Rust toolchain?
Set up your dev environment on Windows for Rust

Rust ships lld on Windows, but it's not default enabled yet. I don't believe it's a huge difference to MSVC link, at least for more recent versions (2019+?)

External dependencies are sometimes annoying, but IMO no worse than Linux for anything even slightly notable. Lots of -sys crates will vendor the sources you need and use that by default, but make sure to read your readmes and error output carefully.

Using Dev Drive makes a good difference, just make sure you also put CARGO_HOME there too. It's still notably worse than WSL by default but it's more like 10% than 100% slower. You can completely disable Defender on it to scrape a bit more performance out, I think, but I'm not sure it's worth it.

Otherwise it's actually a pretty decent experience overall, you can do all the fancy vim setup and everything.

RE: pc-windows-gnu

I'm not sure, but I think that x86_64-pc-windows-gnu (as well as x86_64-pc-windows-msvc) can be configured to use lld to give the build performance boost that is new with Rust 1.90. That would be exciting. @simonbuchan, perhaps you could comment on this (particularly vs gnu ld)?

A google search also indicates that static linking is slower than dynamic, such that for dynamic linking, the difference between linkers is not as pronounced.

Rust ships lld on Windows
Thank You.

Using Dev Drive makes a good difference, just make sure you also put CARGO_HOME there too. It's still notably worse than WSL by default...
Thank You.

...vim setup...

Yes, but for pc-windows-msvc, Microsoft only allows use of the build tools for code written using Visual Studio or VS Code License Terms | Microsoft Diagnostic Build Tools for Visual Studio 2022 - Visual Studio (The one exception is build-only for dependencies).

I tried lld on Windows and while it was consistently faster, the difference was quite small. It shaved a second or two off a large:ish egui application build that takes around 45 seconds to complete with ms' linker. (I didn't time the linking separately, just did a full build each time).

There's also a new flavor that is somewhere in between MSVC and MinGW toolchains:

2 Likes

I use GNU version of Rust because I simply have no development tools on the Windows machine, although I am Windows fan boy and did programming for Windows for my entire life and even wrote a book about it. Using GNU makes your executable minimally 4MB comparing to 700KB on Linux and Mac, but it's okay with me.

Good info. Thanks much! Perhaps the gnullvm provides the Version 1.90 lld linker build performance benefits?

I suspect any performance differences between Linux and Windows lld are down to the file system and code getting linked, I wouldn't imagine the gnullvm target would change much for either of those (the main difference from MSVC AFAIK is replacing the latter's vcruntime.lib which contains exception handling and other very low level compiler-aware stuff)

Probably better to think of the recent Linux improvement being that GNU ld was just that bad!

Logical. Thank You!

Is this possible?:

[target.x86_64-pc-windows-msvc]
linker = "rust-lld.exe"

A google search indicated that this is a good way to get the lld link performance with msvc. The llvmgnu toolchain on Windows is also indicated to have the better lld linker performance. If true, good news!

The Windows gnullvm toolset is Tier 2.

It does have advantages to the windows Tier 1 gnu:

  1. The gnullvm uses the ucrt instead of the old msvcrt
  2. (Perhaps better build performance than msvc? Granted, msvc and this gnullvm may both be better than gnu linker [as stated earlier].)

Promote 64-bit windows-gnullvm Targets to Tier 2 with Host Tools · Issue #877 · rust-lang/compiler-team

... From what I can tell, they are more reliable than some of tier 1 host toolchains. ...

For the pluses of gnullvm, the Tier 2 may not be a major trade-off. If C++ ABI is an issue, I don't think that I need C++ ABI compatibility as I am mainly interested in pure Rust development using Rust and C libraries.

Note that the beta has host tools (the official release doesn't [yet]).
windows-gnullvm - The rustc book

If gnullvm becomes Tier 1, will it be the standard toolchain for Rust on Windows?