Skip to content

Commit a3ca4ab

Browse files
committed
Fix MSVC Runtime options
1 parent aa908ad commit a3ca4ab

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

Sources/SwiftDriver/Jobs/WindowsToolchain+LinkerSupport.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,21 @@ extension WindowsToolchain {
8282
commandLine.appendFlag("-nostartfiles")
8383
if let crt = parsedOptions.getLastArgument(.libc) {
8484
switch crt.asSingle {
85-
case "MT": commandLine.appendFlags("-Xlinker", "-defaultlib:libcmt")
86-
case "MTd": commandLine.appendFlags("-Xlinker", "-defaultlib:libcmtd")
87-
case "MD": commandLine.appendFlags("-Xlinker", "-defaultlib:msvcrt")
88-
case "MDd": commandLine.appendFlags("-Xlinker", "-defaultlib:msvcrtd")
89-
default: fatalError("Invalid C runtime value should be filtered")
85+
case "MT", "MultiThreaded", "static-ucrt":
86+
commandLine.appendFlags("-Xlinker", "-defaultlib:libcmt")
87+
case "MTd", "MultiThreadedDebug", "static-debug-ucrt":
88+
commandLine.appendFlags("-Xlinker", "-defaultlib:libcmtd")
89+
case "MD", "MultiThreadedDLL", "shared-ucrt":
90+
commandLine.appendFlags("-Xlinker", "-defaultlib:msvcrt")
91+
case "MDd", "MultiThreadedDebugDLL", "shared-debug-ucrt":
92+
commandLine.appendFlags("-Xlinker", "-defaultlib:msvcrtd")
93+
default:
94+
throw ToolchainValidationError.illegalCrtName(crt.asSingle)
9095
}
9196
} else {
97+
// NOTE: default to `/MD` like Visual Studio 2015 and newer.
98+
// This is far more useful of a mode since the `/MT` mode requires
99+
// that everything is statically linked.
92100
commandLine.appendFlags("-Xlinker", "-defaultlib:msvcrt")
93101
}
94102

Sources/SwiftDriver/Toolchains/WindowsToolchain.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,6 @@ extension WindowsToolchain {
124124
if parsedOptions.hasArgument(.profileUse) {
125125
throw ToolchainValidationError.argumentNotSupported("-profile-use=")
126126
}
127-
128-
if let crt = parsedOptions.getLastArgument(.libc) {
129-
if !["MT", "MTd", "MD", "MDd"].contains(crt.asSingle) {
130-
throw ToolchainValidationError.illegalCrtName(crt.asSingle)
131-
}
132-
}
133127
}
134128

135129
public enum ToolchainValidationError: Error, DiagnosticData {

0 commit comments

Comments
 (0)