-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Link against minimal/unversioned msvcrt.dll for Windows binaries #2355
Comments
If you want to do this you can use the Difficulties when deploying can be solved by either statically linking, or by using the universal CRT, a version-less CRT that is up-to-date, supported by the MSVC toolchain, and is a built-in windows component. |
The universal crt is very nice, but unfortunately it is restricted to Windows 10 and up. Some older versions of Windows can run apps linking against the universal crt, but only after installing the redistributable, which defeats the purpose of using it. |
If you're using
https://msdn.microsoft.com/en-us/library/abx4dbyh(v=vs.120).aspx
https://blogs.msdn.microsoft.com/oldnewthing/20140411-00/?p=1273 |
You're not saying anything I didn't already say in my first post. I listed all these caveats upfront, I am neither unaware about them nor attempting to hide them. I wouldn't advise using It all depends on how much rust depends on the CRT for. You do yourself and others a disfavor if scaremongering people into thinking the signatures for Many of these functions are either formal or de facto standards, either universally or in the Windows world. Again, it all depends on how much rust relies on the CRT for. If rust is using it for simd operations and advanced intrinsics, then I would be against linking against the unversioned Using the GNU target, the versioned MSVCRT, or the Universal CRT are complete non-starters in this discussion. What would have been a helpful alternative suggestion would have been to compile the rust runtime against the userspace DDK, directly using the NT kernel APIs exposed to userland that |
I just wanted to provide some references for a clarified position on msvcrt.dll.
Some are pretty safe sure, but a single one that isn't, is enough that everything falls apart.
Assuming you mean kernel32 and such (and not direct NT-syscalls), sure one could do that, but it's work not providing much added value for the common user and someone has to look into it and do it. You can already link the CRT statically, if you really do not want to ship it after all, is there any usecase that this is not enough/suboptimal for? |
cc @retep998 for expertise. |
I am opposed to trying to link to
There are no upsides to this change, and the downsides would make life hell for programmers not understanding why their program is getting linker errors or crashing at runtime due to CRT incompatibilities. Also, Rust does not currently prevent you from choosing to use your custom |
Alright, given @retep998's review I'll elect to close this issue at this time; if you think more discussion is necessary, feel free to reraise the issue on http://internals.rust-lang.org/. |
https://github.com/Chuyu-Team/VC-LTL/releases VC-LTL is an open source CRT library based on the MS VCRT. |
That repo has quite a lot of files starting with
... |
VC-LTL is compatible with rust |
Given rust's very minimal VC runtime usage on Windows, this is a proposal to have rust's default Windows toolchain link against the unversioned
msvcrt.dll
that has shipped with all versions of Windows rather than the toolchain-specific Visual C++ runtime (msvcrtXX.dll
). This will eliminate completely any dependence on a specific toolchain/dll on end-user systems and allow Win32 binaries generated via rust to be deployed more portably and with greater ease across all Windows platforms.Some background:
msvcrt.dll
is not intended for use by user applications as it does not have a stable API and Microsoft makes no guarantee as to the availability or the behavior of any particular methods it exposes, as such, Microsoft does not ship amsvcrt.lib
for dynamically linking againstmsvcrt.dll
- instead, it advises that developers either statically link their binaries against msvcrtXX.lib tied to a specific release of the Visual C runtime (updated with each Visual Studio release) or link against that same dll dynamically and distribute a copy of said DLL with the resulting binary (as was the norm in the early 2000s) or distribute a copy of the VC runtime installer and execute that as needed during the deployment phase.Since rust only uses very minimal functionality from the runtime library (allocation, basic string functions, etc) I believe we should be able to limit ourselves to the surface area of the msvcrt api that has been around since at least Windows XP and hasn't changed (for example, many of Microsoft's own single-binary tools target this version of msvcrt to provide universal binary functionality without the hassle of dependency management or a complicated setup routine).
I have open sourced a script to generate a
msvcrt.lib
file from the publicly exposed APIs found in anymsvcrt.dll
, this can be used to generate a (freely redistributable, but no need to redistribute it) themsvcrt.lib
library stub that can be used by the MSVC compiler to become aware of the APIs exposed bymsvcrt.dll
and to link against them dynamically (without needing toLoadLibrary
etc at runtime): msvcrt.lib (readme forthcoming)FWIW, at NeoSmart Technologies we've been linking against
msvcrt.dll
for many years now with a variety of applications for the most basic CRT requirements (basically, standard C functions) and we haven't had any issues or complaints. Binaries produced many years back on Windows XP still run without problem on the latest Windows 10 builds, and applications built today on Windows 10 run on Windows XP just fine.The text was updated successfully, but these errors were encountered: