Skip to content

Commit b2c4e74

Browse files
committed
rustc: Link statically to the MSVCRT
This commit changes all MSVC rustc binaries to be compiled with `-C target-feature=+crt-static` to link statically against the MSVCRT instead of dynamically (as it does today). This also necessitates compiling LLVM in a different fashion, ensuring it's compiled with `/MT` instead of `/MD`. cc #37406
1 parent 48bc082 commit b2c4e74

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/bootstrap/bin/rustc.rs

+5
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ fn main() {
205205
}
206206
}
207207
}
208+
209+
if target.contains("pc-windows-msvc") {
210+
cmd.arg("-Z").arg("unstable-options");
211+
cmd.arg("-C").arg("target-feature=+crt-static");
212+
}
208213
}
209214

210215
if verbose > 1 {

src/bootstrap/native.rs

+6
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ pub fn llvm(build: &Build, target: &str) {
9999
.define("LLVM_TARGET_ARCH", target.split('-').next().unwrap())
100100
.define("LLVM_DEFAULT_TARGET_TRIPLE", target);
101101

102+
if target.contains("msvc") {
103+
cfg.define("LLVM_USE_CRT_DEBUG", "MT");
104+
cfg.define("LLVM_USE_CRT_RELEASE", "MT");
105+
cfg.define("LLVM_USE_CRT_RELWITHDEBINFO", "MT");
106+
}
107+
102108
if target.starts_with("i686") {
103109
cfg.define("LLVM_BUILD_32_BITS", "ON");
104110
}

0 commit comments

Comments
 (0)