From b8edf0213e794a8bd58206bf66aee3fe81be4e60 Mon Sep 17 00:00:00 2001
From: kubycsolutions <keshlam@kubyc.solutions>
Date: Wed, 9 Nov 2022 17:26:25 -0500
Subject: [PATCH] Avoid runtime dependency on static libstdc++

Usually, we do want to use the static C++ library when building rustc_llvm, but do not want to have that dependency at compiler runtime. Change the defaults to Make It So.
---
 config.toml.example     | 7 ++++---
 src/bootstrap/config.rs | 2 +-
 src/ci/run.sh           | 4 ++++
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/config.toml.example b/config.toml.example
index 2373fb2ec4f..c94a27b12a3 100644
--- a/config.toml.example
+++ b/config.toml.example
@@ -87,9 +87,10 @@ changelog-seen = 2
 # this flag will indicate that this version check should not be done.
 #version-check = true
 
-# Link libstdc++ statically into the rustc_llvm instead of relying on a
-# dynamic version to be available.
-#static-libstdcpp = true
+# When true, link libstdc++ statically into the rustc_llvm.
+# This is useful if you don't want to use the dynamic version of that
+# library provided by LLVM.
+#static-libstdcpp = false
 
 # Whether to use Ninja to build LLVM. This runs much faster than make.
 #ninja = true
diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs
index ba50ce9ec24..2afce4fac42 100644
--- a/src/bootstrap/config.rs
+++ b/src/bootstrap/config.rs
@@ -781,7 +781,7 @@ impl Config {
         config.llvm_optimize = true;
         config.ninja_in_file = true;
         config.llvm_version_check = true;
-        config.llvm_static_stdcpp = true;
+        config.llvm_static_stdcpp = false;
         config.backtrace = true;
         config.rust_optimize = true;
         config.rust_optimize_tests = true;
diff --git a/src/ci/run.sh b/src/ci/run.sh
index 9a247fb60a8..7de06ec35c3 100755
--- a/src/ci/run.sh
+++ b/src/ci/run.sh
@@ -123,6 +123,10 @@ else
   # (And PGO is its own can of worms).
   if [ "$NO_DOWNLOAD_CI_LLVM" = "" ]; then
     RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set llvm.download-ci-llvm=if-available"
+  else
+    # When building for CI we want to use the static C++ Standard library
+    # included with LLVM, since a dynamic libstdcpp may not be available.
+    RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set llvm.static-libstdcpp"
   fi
 fi