Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRust, Windows, and MSVC #1061
Comments
This comment has been minimized.
This comment has been minimized.
retep998
changed the title
Support MSVC toolchain on Windows
Rust, Windows, and MSVC
Apr 17, 2015
This comment has been minimized.
This comment has been minimized.
|
Thanks @retep998. This is going to be a big focus this year and we need to get clear on what the goals are. |
brson
self-assigned this
Apr 17, 2015
larsbergstrom
referenced this issue
Apr 17, 2015
Closed
Tracking issue for Rust feature requests #2854
This comment has been minimized.
This comment has been minimized.
|
cc me |
This comment has been minimized.
This comment has been minimized.
alexchandel
commented
May 3, 2015
|
The best solution for |
This comment has been minimized.
This comment has been minimized.
|
Why does rust require a CRT at all on windows? It's rust not C, it can (and AFAIK, does in most places) just call windows APIs directly? Also, which license prevents open source projects from using the redistributable msvcrt.dlls? |
This comment has been minimized.
This comment has been minimized.
|
@Diggsey GPL does not allow you to link GPL code with proprietary code, unless it is a system library in which case there is an exception for that. Since there's no GPL compatible CRTs on Windows, this means the only option for such software is to link dynamically to the system |
This comment has been minimized.
This comment has been minimized.
|
@retep998 Thanks for the explanation, although after doing some reading, it seems that the "system library" exception explicitly includes compiler runtimes, from the GPL:
And apparantly other people are interpretting it this way: So as long as you aren't actually distributing msvcrt.dll you could still be GPL compatible. Since the redistributable can be freely downloaded from the microsoft site, it should be possible to prompt the user to install that first as part of any install process? |
This comment has been minimized.
This comment has been minimized.
|
@Diggsey Given that, then we should at least be able to use other versions of the CRT so long as we link dynamically. |
This comment has been minimized.
This comment has been minimized.
|
I am getting very confused here... What does msvcrt.dll have to do with GPL?? |
This comment has been minimized.
This comment has been minimized.
|
@vadimcn GPL forbids distribution of software that falls under GPL if it has any components which are not GPL-compatible, unless they are system libraries which are not distributed with the software. Which means GPL software has to be dynamically linked to msvcrt and cannot be distributed with the CRT redistributable. |
This comment has been minimized.
This comment has been minimized.
|
@vadimcn Programs built using VC++ link to msvcrt.dll for their C runtime library, which is the "correct" runtime library to use for new programs: because it's versioned it means microsoft can release new versions without breaking all existing programs. However, programs built using the mingw toolchain link to msvcrt.dll, which is unversioned and only exists for backwards compatibility reasons. The reason is that msvcrt.dll comes preinstalled on all windows machines, whereas versioned crts must be installed separately, and the GPL prohibits you from distributing the proprietary msvcrt.dll with GPL software. Ideally there would be an open source C runtime for windows which would solve all the problems, but AFAIK that doesn't exist. |
This comment has been minimized.
This comment has been minimized.
|
@retep998: I kinda doubt that's the reason. All GCC libs, that Rust binaries are linked with, are covered by the GCC runtime library linking exception. |
This comment has been minimized.
This comment has been minimized.
|
@vadimcn The problem is not the GCC libraries we use, but rather if someone wants to build GPL software on Windows using Rust. |
This comment has been minimized.
This comment has been minimized.
gkoz
commented
May 4, 2015
Where does it make any distinction about whether you distribute the "system libraries"? |
This comment has been minimized.
This comment has been minimized.
kini
commented
May 4, 2015
|
IIRC in this context the term "system library" is just conservatively interpreted to mean "library that is so prevalent on systems that it need not be shipped", so shipping a library might cause it to be viewed as not being a "system library" and therefore not subject to the exemption. |
This comment has been minimized.
This comment has been minimized.
gkoz
commented
May 4, 2015
|
I can see it in the GPLv2 now. So discussing the GPL isn't very meaningful without specifying its version it seems... The language there is a bit ambiguous (is the second "component" the same as the first?):
|
This comment has been minimized.
This comment has been minimized.
alexchandel
commented
May 5, 2015
|
@retep998 Just to be clear, it is jemalloc that drags in the |
This comment has been minimized.
This comment has been minimized.
|
Perhaps we should break the issue into chunks? I believe jemalloc can be disabled, so we can try to get a working version of MSVC Rust sans jemalloc and debuginfo, then go on to jemalloc, then debuginfo. |
This comment has been minimized.
This comment has been minimized.
ricky26
commented
May 5, 2015
|
From a technical point of view I managed to build a rust program into an exe using link.exe and the MSVC toolchain in LLVM (it's a hack, but it's in my branch listed above) - there were a couple of things I didn't expect going in:
|
This comment has been minimized.
This comment has been minimized.
|
In VS 2015, the CRT is being refactored into a VC runtime and a Universal CRT. |
This comment has been minimized.
This comment has been minimized.
abonander
commented
May 16, 2015
|
I have already found a need for integration with Windows resource scripts. When creating executables that link to Common Controls, it's necessary to create a manifest file that tells what version of the Also, it would be nice to be able to add icon files directly to executables in Windows, which I believe is facilitated by resource scripts as well. |
alexcrichton
added
the
T-dev-tools
label
May 18, 2015
bors
added a commit
to rust-lang/rust
that referenced
this issue
May 20, 2015
alexcrichton
added
the
P-high
label
May 26, 2015
This comment has been minimized.
This comment has been minimized.
|
I've reorganized the description of this issue slightly and am going to be using it as a sort of metabug to track sub-bugs. |
This comment has been minimized.
This comment has been minimized.
|
Based on a binary that @alexcrichton sent me that was built using the new msvc target, it seems that the CRT is being statically linked. Considering we are explicitly linking |
This comment has been minimized.
This comment has been minimized.
|
I just disassembled both |
This comment has been minimized.
This comment has been minimized.
|
Regarding the universal CRT on Windows XP, it should entirely be possible to install the universal CRT on XP and then run programs that link against it on XP (so long as they passed the correct |
This comment has been minimized.
This comment has been minimized.
alexchandel
commented
Oct 18, 2015
|
@retep998 Yeah it's quite possible this DLL is ancient, and unlike the others. VC6 is the least common denominator, though it's only 17 years old. Sadly it still sees widespread use in certain areas, thanks to the fact that MS goes out of their way not to break it. I don't plan on compiling LLVM with it; I'm using it only for its libraries, because LLD is capable of cross-linking So it's possible to successfully link against missing symbols from Rust when targeting XP, using MS's currently supported libraries?
Update: so, linking rustc's output with VC6's |
This comment has been minimized.
This comment has been minimized.
You can successfully link against any symbol so long as some import library exports it. The program will still crash at runtime if the specified DLL doesn't exist or it doesn't have that symbol. Telling The recommended way to cross-compile to Windows is using the MinGW toolchain as several people have done it successfully, although it is poorly documented. Feel free to talk to @steveklabnik about getting better documentation on the cross-compiling fiasco. |
This comment has been minimized.
This comment has been minimized.
You can distribute the universal CRT without statically linking: Microsoft recently caved to popular demand and added support for distributing the universal CRT in DLL form alongside your application, in addition to the other methods (windows update or separate UCRT installer). The only requirement is that the DLLs be in the same directory as your executable. |
This comment has been minimized.
This comment has been minimized.
alexchandel
commented
Oct 18, 2015
|
@retep998 I've never had success crossing from OSX to 32bit windows via MinGW. The lack of SEH support (I don't think it's acceptable to pass around a But this is working well. The trouble was really figuring out which of the infinite permutations would work. I didn't try, but linking against UCRT instead of VC6 may work too. It's too bad Microsoft can't just provide a minimalist zip file that we could redistribute for cross-compiling: the VS2015 download I extracted the Win10 libraries & headers from was multiple gigabytes of bloat. |
This comment has been minimized.
This comment has been minimized.
alexchandel
commented
Oct 18, 2015
|
@Diggsey That's pretty amusing. They deserve all the trouble they're enduring and more for not having included a stable C library in their os 30 years ago. It's a "code smell" to me to deliver shared objects alongside executables, especially when they're things like the standard C library, but I managed to link against the evil |
This comment has been minimized.
This comment has been minimized.
Windows has always included a stable C library, the problems stem from the fact that it must maintain binary compatibility across all versions of windows, and that it combines both the compiler runtime and the language runtime in one. The compiler runtime must, necessarily, be updated for each new version of the compiler. That means the entire runtime must be versioned according to the compiler version, so frequently you need a runtime that is newer than the version of windows on which you are running. This means you can't rely on it being pre-installed, and that is grounds for discounting it as a "core system component", which makes it incompatible with the GPL. The UCRT solves the problem by splitting the compiler runtime and C runtime into separate DLLs, which allows the C runtime part to be the same regardless of the compiler version. Linux doesn't have the problem only because it doesn't attempt to maintain binary compatibility for programs which rely on shared libraries: you can't just copy a program from one linux machine to another and have any guarantee of it working, unless absolutely everything is statically linked and the kernel versions match. For platforms where most software is distributed only in binary form, this obviously can't work. |
This comment has been minimized.
This comment has been minimized.
alexchandel
commented
Oct 21, 2015
|
@Diggsey Then it is not stable. It is an incorrect presumption that the compiler runtime "must, necessarily, be updated for each new version". I can use an (x86) crt1 Mach-O crosscompiled for OS X 10.1 with El Capitan's
This is so false that I don't even. Linux famously does not break userspace, so kernel versions aren't generally a problem. Moreover, except for rare cases, glibc maintains backwards compatibility. As does OS X, which also guarantees |
This comment has been minimized.
This comment has been minimized.
The compiler runtime is completely different from the C runtime... Obviously using an old CRT will work, that's the whole point: the CRT has a stable API, the compiler runtime does not. Windows does have a stable C runtime, because as long as you only use the C runtime parts (of any version of msvcrt) it will continue to work forever. The part that changes is the compiler runtime.
Make up your mind, either there is a guarantee or there's not. If there isn't a guarantee, than what I said is true. Windows does provide backwards compatibility guarantees, to a fault. You seem to be missing the important distinction between should work, and does work. |
This comment has been minimized.
This comment has been minimized.
alexchandel
commented
Oct 25, 2015
If you examine the rest of that sentence, instead of cutting it out for cute rhetorical purposes like "Make up your mind", you'd see I'm referring to
Wrong for clang/libSystem. There are (non-MS) platforms that do not make these distinctions, and the existence of the former demonstrates that the latter should not be necessary. Binary compatibility does not have to be an issue, and distinguishing "compiler runtimes" from other stable components is meaningless or inconsequential on platforms that don't suffer from the nuanced design flaws of Windows. Not everyone is forced to accept MS's terminology, nor their justifications for instability. And just to hammer the point home (and because you clearly misunderstood this), the functions in Apple's |
This comment has been minimized.
This comment has been minimized.
|
It's worth noting that
|
This comment has been minimized.
This comment has been minimized.
alexchandel
commented
Dec 1, 2015
|
@retep998 Hah that's quite a good list. But OS X puts all of those in a DLL too. For example for the C++ exception stuff, Edit: But There is simply no justifiable reason for what Microsoft did. |
liigo
referenced this issue
Jun 22, 2016
Closed
msvc: rustc produces invalid .exe (Windows XP) #34407
This comment has been minimized.
This comment has been minimized.
|
@retep998 What's the state of this metabug? Looks a bit stale. Can remaining items be moved to rust-lang/rust as individual bugs? |
brson
removed
the
P-high
label
Jun 23, 2016
This comment has been minimized.
This comment has been minimized.
|
I went ahead and dropped the P-high tag since this bug is inactive. |
This comment has been minimized.
This comment has been minimized.
|
I do update the issue every so often. Feel free to point out anything you feel should be added or was completed and I'll update the list. |
This comment has been minimized.
This comment has been minimized.
|
What's left to do re: the first wishlist item? |
This comment has been minimized.
This comment has been minimized.
|
I'm not sure. I'll have to try debugging a Rust program and see how good the local variable info is. |
This comment has been minimized.
This comment has been minimized.
briansmith
commented
Jun 23, 2016
I have noticed when debugging with MSVC's debugger, stepping into any line that uses |
This comment has been minimized.
This comment has been minimized.
alexchandel
commented
Jun 24, 2016
|
All of the "Remaining tasks" still appear unfinished, so presumably it's still active. Perhaps the metabug itself could be moved to rust-lang/rust. |
This comment has been minimized.
This comment has been minimized.
alexchandel
commented
Jul 12, 2016
|
@retep998 I've heard that the COM ABI is slightly different from the usual Win32 ABI, in ways that resulted in MSVC's C (not C++) compiler historically not being able to call it correctly. Is this true / does rustc need to do anything to support it? |
This comment has been minimized.
This comment has been minimized.
|
@alexchandel stdcall for C++ methods is slightly different than stdcall for regular functions. Since COM is based on C++ methods, that means that for some of those COM methods, the C equivalent is in fact incorrect. I already opened an issue for this #1342 which is even listed in this meta issue. |
brson
removed their assignment
Jul 21, 2016
This comment has been minimized.
This comment has been minimized.
liranringel
commented
Oct 20, 2018
|
Could someone elaborate in what way the quality of PDB debug info should be improved? |
This comment has been minimized.
This comment has been minimized.
|
#2625 covers |
retep998 commentedApr 13, 2015
•
edited
High priority tasks
kind=static-nobundlestable, or changekind=staticto behave likekind=static-nobundle.env_clearactually work. rust-lang/rust#31259Lower priority tasks
dllimportproperly, or just get rid of thedylibcrate type. rust-lang/rust#27438clwith/GLcan be linked properly. Or just stopkind=staticfrom bundling. rust-lang/rust#26003-msvcdistribution. rust-lang/rust#31816Commandwork better. rust-lang/rust#37519Completed tasks
dllimportproperly. #1717dllexport. rust-lang/rust#7196libgccand use native/llvm unwinding stuff.librustc_backhow to invokelink.exe.Wishlist
lldfor cross compilation to Windows with a new pure Rust target without any CRT bits at all. rust-lang/rust#9367Related links
Commandbehave better. rust-lang/rust#37519rust-lang/rust#1768