Why is msvc the default toolchain?

When you install Rust with rustup (as it is recommended) by default it installs the -msvc toolchain.

As far as I understand -msvc has some disadvantages:
- Debugging doesn't work
- You have to install "Microsoft C++ Build Tools" which is huge and sometimes not available for download

It's easy to switch to the -gnu toolchain, but why isn't that the default? Are there things that don't work with the -gnu toolchain?

Many libraries are compiled for the -msvc toolchain and thus don't work with the -gnu toolchain.

You mean crates?

No, I mean .dll libraries like user32.dll or dxguid.dll.

The MSVC toolchain is the native toolchain for the Windows platform, whereas the GNU toolchain is not.

6 Likes

I don't understand. MessageBoxW() is from user32.dll, isn't it? I can still use it with the -gnu toolchain:

When compiling for -gnu, winapi statically links to the mingw equivalents of user32.dll and other system libraries that are bundled with winapi itself instead of dynamically linking to the official version in C:\Windows\System32.

The equivalent of user32.dll is for example https://github.com/retep998/winapi-rs/blob/0.3/x86_64/lib/libwinapi_onecore-user32.a.

To be clear here, user32.dll is part of the OS and is loaded at runtime. Both GNU and MSVC must load the same .dll. If they didn't they would only work on one specific version of Windows

The difference between MSVC and GNU is user32.lib. This is an "import library". It's essentially no more than a list of functions with the name of the DLL that has to be loaded at runtime. The linker uses this information to add to the binary's import table.

1 Like

This is wrong; the real difference is just that debug symbols are stored in a different format, so you need to use a different debugger than GDB. I usually just use Visual Studio's, as it's actually quite nice in general, but there are plenty to choose from, both first and third-party!

What this comes down to in general is that the whole MinGW toolchain simply does not try to be compatible with the Windows platform's usual formats, ABIs, etc. As its name ("Minimalist GNU for Windows") implies, it is more of a set of shims to get GNU-targeting software running on Windows without too much adjustment.

This means that, for simple things like MessageBoxW in user32.dll, things work out okay thanks to MinGW's import libs, but in the general case you simply can't expect it to be compatible with first or third-party libraries or platform APIs which actually follow the standard platform conventions.

Truly supporting Windows means supporting Windows' formats and ABIs, so Rust's default Windows toolchain is the one that does that.

9 Likes

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.