Skip to content

Commit d2185f6

Browse files
committed
Auto merge of #65911 - mati865:static-libstdcxx-mingw, r=alexcrichton
Statically link libstdc++ on windows-gnu Fixes #61561 by not shipping `libstdc++-6.dll` which can conflict with the GCC.
2 parents 881ebeb + b20d8d3 commit d2185f6

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

src/bootstrap/compile.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -657,11 +657,11 @@ pub fn build_codegen_backend(builder: &Builder<'_>,
657657
if let Some(ref s) = builder.config.llvm_ldflags {
658658
cargo.env("LLVM_LINKER_FLAGS", s);
659659
}
660-
// Building with a static libstdc++ is only supported on linux right now,
660+
// Building with a static libstdc++ is only supported on linux and mingw right now,
661661
// not for MSVC or macOS
662662
if builder.config.llvm_static_stdcpp &&
663663
!target.contains("freebsd") &&
664-
!target.contains("windows") &&
664+
!target.contains("msvc") &&
665665
!target.contains("apple") {
666666
let file = compiler_file(builder,
667667
builder.cxx(target).unwrap(),

src/bootstrap/dist.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ fn make_win_dist(
236236
}
237237

238238
let target_tools = ["gcc.exe", "ld.exe", "dlltool.exe", "libwinpthread-1.dll"];
239-
let mut rustc_dlls = vec!["libstdc++-6.dll", "libwinpthread-1.dll"];
239+
let mut rustc_dlls = vec!["libwinpthread-1.dll"];
240240
if target_triple.starts_with("i686-") {
241241
rustc_dlls.push("libgcc_s_dw2-1.dll");
242242
} else {

src/bootstrap/native.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl Step for Llvm {
159159

160160
// For distribution we want the LLVM tools to be *statically* linked to libstdc++
161161
if builder.config.llvm_tools_enabled || builder.config.lldb_enabled {
162-
if !target.contains("windows") {
162+
if !target.contains("msvc") {
163163
if target.contains("apple") {
164164
cfg.define("CMAKE_EXE_LINKER_FLAGS", "-static-libstdc++");
165165
} else {
@@ -395,7 +395,7 @@ fn configure_cmake(builder: &Builder<'_>,
395395
cfg.define("CMAKE_C_FLAGS", cflags);
396396
let mut cxxflags = builder.cflags(target, GitRepo::Llvm).join(" ");
397397
if builder.config.llvm_static_stdcpp &&
398-
!target.contains("windows") &&
398+
!target.contains("msvc") &&
399399
!target.contains("netbsd")
400400
{
401401
cxxflags.push_str(" -static-libstdc++");

src/librustc_llvm/build.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,11 @@ fn main() {
279279
let path = PathBuf::from(s);
280280
println!("cargo:rustc-link-search=native={}",
281281
path.parent().unwrap().display());
282-
println!("cargo:rustc-link-lib=static={}", stdcppname);
282+
if target.contains("windows") {
283+
println!("cargo:rustc-link-lib=static-nobundle={}", stdcppname);
284+
} else {
285+
println!("cargo:rustc-link-lib=static={}", stdcppname);
286+
}
283287
} else if cxxflags.contains("stdlib=libc++") {
284288
println!("cargo:rustc-link-lib=c++");
285289
} else {

0 commit comments

Comments
 (0)