Skip to content

Commit 934d7b5

Browse files
committed
MSVC: Prepare for MinGW-w64-based libs support
I got a std.stdio hello-world executable to work on Win64 using the Visual C++ 2015 DLLs, with both MS linker and -link-internally, see dlang/installer#346. It still requires a couple of extra command-line args, but will in the end enable us to get rid of all external dependencies for building on Windows (via -link-internally and the MinGW-w64-based import libs, which will only add a few MB to the prebuilt packages). The Visual C++ 2015 *runtime* will need to be installed when running binaries linked against the MinGW libs.
1 parent b0ec558 commit 934d7b5

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

driver/linker-msvc.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ void addMscrtLibs(std::vector<std::string> &args) {
3636

3737
args.push_back(("/DEFAULTLIB:" + mscrtlibName).str());
3838

39+
// We need the vcruntime lib for druntime's exception handling (ldc.eh_msvc).
40+
// Pick one of the 4 variants matching the selected main UCRT lib.
41+
42+
if (mscrtlibName.contains_lower("vcruntime")) {
43+
return;
44+
}
45+
3946
const bool isStatic = mscrtlibName.startswith_lower("libcmt");
4047
const bool isDebug =
4148
mscrtlibName.endswith_lower("d") || mscrtlibName.endswith_lower("d.lib");

runtime/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ if("${TARGET_SYSTEM}" MATCHES "MSVC")
307307
# We want to be able to link against all 4 C runtime variants (libcmt[d] / msvcrt[d]).
308308
string(REGEX REPLACE "(^| )[/-]M[TD]d?( |$)" "\\2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
309309
append("/MT /Zl" CMAKE_C_FLAGS_RELEASE)
310+
# Disable buffer overflow checks to prevent dependencies on special C symbols
311+
# not available in the MinGW-w64 libs.
312+
append("/GS-" CMAKE_C_FLAGS_RELEASE)
310313
# warning C4100: unreferenced formal parameter
311314
# warning C4127: conditional expression is constant
312315
# warning C4131: uses old-style declarator

runtime/druntime

0 commit comments

Comments
 (0)