summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohn Ericson <git@JohnEricson.me>2020-04-13 20:44:43 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2020-06-22 04:24:44 +0000
commitf3f7612a409e4ebbec634ab7f20e094f206d396a (patch)
tree58131834c6a8decb3a33bf3cb59dd3860cdca39c
parente00d4d60214e04ba75d19870000e55b8ac4ed4dc (diff)
downloadnixpkgs-f3f7612a409e4ebbec634ab7f20e094f206d396a.tar
nixpkgs-f3f7612a409e4ebbec634ab7f20e094f206d396a.tar.gz
nixpkgs-f3f7612a409e4ebbec634ab7f20e094f206d396a.tar.bz2
nixpkgs-f3f7612a409e4ebbec634ab7f20e094f206d396a.tar.lz
nixpkgs-f3f7612a409e4ebbec634ab7f20e094f206d396a.tar.xz
nixpkgs-f3f7612a409e4ebbec634ab7f20e094f206d396a.tar.zst
nixpkgs-f3f7612a409e4ebbec634ab7f20e094f206d396a.zip
C++ Compilers: Systematize handling of standard libraries
-rw-r--r--pkgs/applications/networking/browsers/firefox/common.nix2
-rw-r--r--pkgs/applications/networking/mailreaders/thunderbird/default.nix2
-rw-r--r--pkgs/build-support/cc-wrapper/add-flags.sh8
-rw-r--r--pkgs/build-support/cc-wrapper/cc-wrapper.sh2
-rw-r--r--pkgs/build-support/cc-wrapper/default.nix61
-rw-r--r--pkgs/development/compilers/gcc/libstdc++-hook.sh4
-rw-r--r--pkgs/development/compilers/llvm/10/default.nix17
-rw-r--r--pkgs/development/compilers/llvm/10/libc++/default.nix9
-rw-r--r--pkgs/development/compilers/llvm/10/libc++/setup-hook.sh6
-rw-r--r--pkgs/development/compilers/llvm/5/default.nix14
-rw-r--r--pkgs/development/compilers/llvm/5/libc++/default.nix9
-rw-r--r--pkgs/development/compilers/llvm/5/libc++/setup-hook.sh6
-rw-r--r--pkgs/development/compilers/llvm/6/default.nix14
-rw-r--r--pkgs/development/compilers/llvm/6/libc++/default.nix9
-rw-r--r--pkgs/development/compilers/llvm/6/libc++/setup-hook.sh6
-rw-r--r--pkgs/development/compilers/llvm/7/default.nix68
-rw-r--r--pkgs/development/compilers/llvm/7/libc++/default.nix9
-rw-r--r--pkgs/development/compilers/llvm/7/libc++/setup-hook.sh6
-rw-r--r--pkgs/development/compilers/llvm/8/default.nix19
-rw-r--r--pkgs/development/compilers/llvm/8/libc++/default.nix9
-rw-r--r--pkgs/development/compilers/llvm/8/libc++/setup-hook.sh6
-rw-r--r--pkgs/development/compilers/llvm/9/default.nix19
-rw-r--r--pkgs/development/compilers/llvm/9/libc++/default.nix9
-rw-r--r--pkgs/development/compilers/llvm/9/libc++/setup-hook.sh6
-rw-r--r--pkgs/development/compilers/swift/default.nix2
-rw-r--r--pkgs/misc/vim-plugins/overrides.nix2
-rw-r--r--pkgs/stdenv/darwin/default.nix9
-rw-r--r--pkgs/top-level/aliases.nix1
-rw-r--r--pkgs/top-level/all-packages.nix15
29 files changed, 150 insertions, 199 deletions
diff --git a/pkgs/applications/networking/browsers/firefox/common.nix b/pkgs/applications/networking/browsers/firefox/common.nix
index 8060895a2e0..a8628306bf1 100644
--- a/pkgs/applications/networking/browsers/firefox/common.nix
+++ b/pkgs/applications/networking/browsers/firefox/common.nix
@@ -177,7 +177,7 @@ stdenv.mkDerivation ({
 
     BINDGEN_CFLAGS="$(< ${stdenv.cc}/nix-support/libc-cflags) \
       $(< ${stdenv.cc}/nix-support/cc-cflags) \
-      ${stdenv.cc.default_cxx_stdlib_compile} \
+      $(< ${stdenv.cc}/nix-support/libcxx-cxxflags) \
       ${lib.optionalString stdenv.cc.isClang "-idirafter ${stdenv.cc.cc}/lib/clang/${lib.getVersion stdenv.cc.cc}/include"} \
       ${lib.optionalString stdenv.cc.isGNU "-isystem ${stdenv.cc.cc}/include/c++/${lib.getVersion stdenv.cc.cc} -isystem ${stdenv.cc.cc}/include/c++/${lib.getVersion stdenv.cc.cc}/${stdenv.hostPlatform.config}"} \
       $NIX_CFLAGS_COMPILE"
diff --git a/pkgs/applications/networking/mailreaders/thunderbird/default.nix b/pkgs/applications/networking/mailreaders/thunderbird/default.nix
index 73536ae5fc1..09e72dd8e32 100644
--- a/pkgs/applications/networking/mailreaders/thunderbird/default.nix
+++ b/pkgs/applications/networking/mailreaders/thunderbird/default.nix
@@ -179,7 +179,7 @@ stdenv.mkDerivation rec {
 
     BINDGEN_CFLAGS="$(< ${stdenv.cc}/nix-support/libc-cflags) \
       $(< ${stdenv.cc}/nix-support/cc-cflags) \
-      ${stdenv.cc.default_cxx_stdlib_compile} \
+      $(< ${stdenv.cc}/nix-support/libcxx-cxxflags) \
       ${
         lib.optionalString stdenv.cc.isClang
         "-idirafter ${stdenv.cc.cc}/lib/clang/${
diff --git a/pkgs/build-support/cc-wrapper/add-flags.sh b/pkgs/build-support/cc-wrapper/add-flags.sh
index 3398f11e8c2..04be3f408ee 100644
--- a/pkgs/build-support/cc-wrapper/add-flags.sh
+++ b/pkgs/build-support/cc-wrapper/add-flags.sh
@@ -37,6 +37,14 @@ if [ -e @out@/nix-support/libc-cflags ]; then
     NIX_CFLAGS_COMPILE_@suffixSalt@="$(< @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE_@suffixSalt@"
 fi
 
+if [ -e @out@/nix-support/libcxx-cxxflags ]; then
+    NIX_CXXSTDLIB_COMPILE_@suffixSalt@+=" $(< @out@/nix-support/libcxx-cxxflags)"
+fi
+
+if [ -e @out@/nix-support/libcxx-ldflags ]; then
+    NIX_CXXSTDLIB_LINK_@suffixSalt@+=" $(< @out@/nix-support/libcxx-ldflags)"
+fi
+
 if [ -e @out@/nix-support/cc-cflags ]; then
     NIX_CFLAGS_COMPILE_@suffixSalt@="$(< @out@/nix-support/cc-cflags) $NIX_CFLAGS_COMPILE_@suffixSalt@"
 fi
diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh
index cf00202221e..3f9f099f3bc 100644
--- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh
+++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh
@@ -129,7 +129,7 @@ fi
 
 if [[ "$isCpp" = 1 ]]; then
     if [[ "$cppInclude" = 1 ]]; then
-        NIX_CFLAGS_COMPILE_@suffixSalt@+=" ${NIX_CXXSTDLIB_COMPILE_@suffixSalt@:-@default_cxx_stdlib_compile@}"
+        NIX_CFLAGS_COMPILE_@suffixSalt@+=" $NIX_CXXSTDLIB_COMPILE_@suffixSalt@"
     fi
     NIX_CFLAGS_LINK_@suffixSalt@+=" $NIX_CXXSTDLIB_LINK_@suffixSalt@"
 fi
diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix
index da16a23f9df..e23d1c6dd4e 100644
--- a/pkgs/build-support/cc-wrapper/default.nix
+++ b/pkgs/build-support/cc-wrapper/default.nix
@@ -48,12 +48,6 @@ let
   # The wrapper scripts use 'cat' and 'grep', so we may need coreutils.
   coreutils_bin = if nativeTools then "" else getBin coreutils;
 
-  default_cxx_stdlib_compile = if (targetPlatform.isLinux && !(cc.isGNU or false) && !nativeTools && cc ? gcc) && !(targetPlatform.useLLVM or false) then
-    "-isystem $(echo -n ${cc.gcc}/include/c++/*) -isystem $(echo -n ${cc.gcc}/include/c++/*)/${targetPlatform.config}"
-  else if targetPlatform.isDarwin && (libcxx != null) && (cc.isClang or false) && !(targetPlatform.useLLVM or false) then
-    "-isystem ${libcxx}/include/c++/v1"
-  else "";
-
   # The "suffix salt" is a arbitrary string added in the end of env vars
   # defined by cc-wrapper's hooks so that multiple cc-wrappers can be used
   # without interfering. For the moment, it is defined as the target triple,
@@ -68,7 +62,7 @@ let
 
   # older compilers (for example bootstrap's GCC 5) fail with -march=too-modern-cpu
   isGccArchSupported = arch:
-    if cc.isGNU or false then
+    if isGNU then
       { skylake        = versionAtLeast ccVersion "6.0";
         skylake-avx512 = versionAtLeast ccVersion "6.0";
         cannonlake     = versionAtLeast ccVersion "8.0";
@@ -76,7 +70,7 @@ let
         icelake-server = versionAtLeast ccVersion "8.0";
         knm            = versionAtLeast ccVersion "8.0";
       }.${arch} or true
-    else if cc.isClang or false then
+    else if isClang then
       { cannonlake     = versionAtLeast ccVersion "5.0";
         icelake-client = versionAtLeast ccVersion "7.0";
         icelake-server = versionAtLeast ccVersion "7.0";
@@ -116,7 +110,7 @@ stdenv.mkDerivation {
     # Binutils, and Apple's "cctools"; "bintools" as an attempt to find an
     # unused middle-ground name that evokes both.
     inherit bintools;
-    inherit libc nativeTools nativeLibc nativePrefix isGNU isClang default_cxx_stdlib_compile;
+    inherit libc nativeTools nativeLibc nativePrefix isGNU isClang;
 
     emacsBufferSetup = pkgs: ''
       ; We should handle propagation here too
@@ -173,8 +167,6 @@ stdenv.mkDerivation {
       export named_cc=${targetPrefix}cc
       export named_cxx=${targetPrefix}c++
 
-      export default_cxx_stdlib_compile="${default_cxx_stdlib_compile}"
-
       if [ -e $ccPath/${targetPrefix}gcc ]; then
         wrap ${targetPrefix}gcc $wrapper $ccPath/${targetPrefix}gcc
         ln -s ${targetPrefix}gcc $out/bin/${targetPrefix}cc
@@ -226,7 +218,7 @@ stdenv.mkDerivation {
 
   strictDeps = true;
   propagatedBuildInputs = [ bintools ] ++ extraTools ++ optionals cc.langD or false [ zlib ];
-  depsTargetTargetPropagated = extraPackages;
+  depsTargetTargetPropagated = optional (libcxx != null) libcxx ++ extraPackages;
 
   wrapperName = "CC_WRAPPER";
 
@@ -250,6 +242,24 @@ stdenv.mkDerivation {
       fi
     ''
 
+    + optionalString isClang ''
+      ##
+      ## General Clang support
+      ##
+
+      echo "-target ${targetPlatform.config}" >> $out/nix-support/cc-cflags
+    ''
+
+    + optionalString (isClang && libcxx == null && cc ? gcc) ''
+      ##
+      ## GCC libs for non-GCC support
+      ##
+
+      echo "-B${cc.gcc}/lib/gcc/${targetPlatform.config}/${cc.gcc.version}" >> $out/nix-support/cc-cflags
+      echo "-L${cc.gcc}/lib/gcc/${targetPlatform.config}/${cc.gcc.version}" >> $out/nix-support/cc-ldflags
+      echo "-L${cc.gcc.lib}/${targetPlatform.config}/lib" >> $out/nix-support/cc-ldflags
+    ''
+
     + optionalString (libc != null) (''
       ##
       ## General libc support
@@ -279,6 +289,27 @@ stdenv.mkDerivation {
       echo "${libc_dev}" > $out/nix-support/orig-libc-dev
     '')
 
+    + ''
+      ##
+      ## General libc++ support
+      ##
+
+    ''
+    + optionalString (libcxx == null && cc ? gcc) ''
+      for dir in ${cc.gcc}/include/c++/*; do
+        echo "-isystem $dir" >> $out/nix-support/libcxx-cxxflags
+      done
+      for dir in ${cc.gcc}/include/c++/*/${targetPlatform.config}; do
+        echo "-isystem $dir" >> $out/nix-support/libcxx-cxxflags
+      done
+    ''
+    + optionalString (libcxx.isLLVM or false) (''
+      echo "-isystem ${libcxx}/include/c++/v1" >> $out/nix-support/libcxx-cxxflags
+      echo "-stdlib=libc++" >> $out/nix-support/libcxx-ldflags
+    '' + stdenv.lib.optionalString stdenv.targetPlatform.isLinux ''
+      echo "-lc++abi" >> $out/nix-support/libcxx-ldflags
+    '')
+
     + optionalString (!nativeTools) ''
       ##
       ## Initial CFLAGS
@@ -389,9 +420,9 @@ stdenv.mkDerivation {
     # There are a few tools (to name one libstdcxx5) which do not work
     # well with multi line flags, so make the flags single line again
     + ''
-      if [ -e "$out/nix-support/libc-cflags" ]; then
-        substituteInPlace "$out/nix-support/libc-cflags" --replace $'\n' ' '
-      fi
+      for flags in "$out/nix-support"/*flags; do
+        substituteInPlace "$flags" --replace $'\n' ' '
+      done
 
       substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh
       substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh
diff --git a/pkgs/development/compilers/gcc/libstdc++-hook.sh b/pkgs/development/compilers/gcc/libstdc++-hook.sh
deleted file mode 100644
index f5b4123b64d..00000000000
--- a/pkgs/development/compilers/gcc/libstdc++-hook.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-# See pkgs/build-support/setup-hooks/role.bash
-getHostRole
-
-export NIX_CXXSTDLIB_COMPILE${role_post}+=" -isystem $(echo -n @gcc@/include/c++/*) -isystem $(echo -n @gcc@/include/c++/*)/@targetConfig@"
diff --git a/pkgs/development/compilers/llvm/10/default.nix b/pkgs/development/compilers/llvm/10/default.nix
index 4181ab29bd7..870d5110d14 100644
--- a/pkgs/development/compilers/llvm/10/default.nix
+++ b/pkgs/development/compilers/llvm/10/default.nix
@@ -1,4 +1,4 @@
-{ lowPrio, newScope, pkgs, stdenv, cmake, gcc, libstdcxxHook
+{ lowPrio, newScope, pkgs, stdenv, cmake
 , libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith
 , buildLlvmTools # tools, but from the previous stage, for cross
 , targetLlvmLibraries # libraries, but from the next stage, for cross
@@ -57,23 +57,17 @@ let
 
     libstdcxxClang = wrapCCWith rec {
       cc = tools.clang-unwrapped;
+      libcxx = null; # libstdcxx is smuggled in with clang.gcc
       extraPackages = [
-        libstdcxxHook
         targetLlvmLibraries.compiler-rt
       ];
-      extraBuildCommands = ''
-          echo "-target ${targetConfig}" >> $out/nix-support/cc-cflags
-          echo "-B${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-cflags
-          echo "-L${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-ldflags
-          echo "-L${gcc.cc.lib}/${targetConfig}/lib" >> $out/nix-support/cc-ldflags
-      '' + mkExtraBuildCommands cc;
+      extraBuildCommands = mkExtraBuildCommands cc;
     };
 
     libcxxClang = wrapCCWith rec {
       cc = tools.clang-unwrapped;
       libcxx = targetLlvmLibraries.libcxx;
       extraPackages = [
-        targetLlvmLibraries.libcxx
         targetLlvmLibraries.libcxxabi
         targetLlvmLibraries.compiler-rt
       ];
@@ -100,14 +94,12 @@ let
         inherit (tools) bintools;
       };
       extraPackages = [
-        targetLlvmLibraries.libcxx
         targetLlvmLibraries.libcxxabi
         targetLlvmLibraries.compiler-rt
       ] ++ stdenv.lib.optionals (!stdenv.targetPlatform.isWasm) [
         targetLlvmLibraries.libunwind
       ];
       extraBuildCommands = ''
-        echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
         echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags
         echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
       '' + stdenv.lib.optionalString (!stdenv.targetPlatform.isWasm) ''
@@ -127,7 +119,6 @@ let
         targetLlvmLibraries.compiler-rt
       ];
       extraBuildCommands = ''
-        echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
         echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
         echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
         echo "-nostdlib++" >> $out/nix-support/cc-cflags
@@ -145,7 +136,6 @@ let
         targetLlvmLibraries.compiler-rt
       ];
       extraBuildCommands = ''
-        echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
         echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
         echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
       '' + mkExtraBuildCommands cc;
@@ -161,7 +151,6 @@ let
       extraPackages = [ ];
       extraBuildCommands = ''
         echo "-nostartfiles" >> $out/nix-support/cc-cflags
-        echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
       '';
     };
 
diff --git a/pkgs/development/compilers/llvm/10/libc++/default.nix b/pkgs/development/compilers/llvm/10/libc++/default.nix
index ed76ce77a8b..872865ec474 100644
--- a/pkgs/development/compilers/llvm/10/libc++/default.nix
+++ b/pkgs/development/compilers/llvm/10/libc++/default.nix
@@ -39,12 +39,9 @@ stdenv.mkDerivation {
 
   enableParallelBuilding = true;
 
-  linkCxxAbi = stdenv.isLinux;
-
-  setupHooks = [
-    ../../../../../build-support/setup-hooks/role.bash
-    ./setup-hook.sh
-  ];
+  passthru = {
+    isLLVM = true;
+  };
 
   meta = {
     homepage = "https://libcxx.llvm.org/";
diff --git a/pkgs/development/compilers/llvm/10/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/10/libc++/setup-hook.sh
deleted file mode 100644
index 3a274aecc23..00000000000
--- a/pkgs/development/compilers/llvm/10/libc++/setup-hook.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-# See pkgs/build-support/setup-hooks/role.bash
-getHostRole
-
-linkCxxAbi="@linkCxxAbi@"
-export NIX_CXXSTDLIB_COMPILE${role_post}+=" -isystem @out@/include/c++/v1"
-export NIX_CXXSTDLIB_LINK${role_post}=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
diff --git a/pkgs/development/compilers/llvm/5/default.nix b/pkgs/development/compilers/llvm/5/default.nix
index e7083a6ed13..5a992f4a350 100644
--- a/pkgs/development/compilers/llvm/5/default.nix
+++ b/pkgs/development/compilers/llvm/5/default.nix
@@ -1,4 +1,4 @@
-{ lowPrio, newScope, pkgs, stdenv, cmake, gcc, libstdcxxHook
+{ lowPrio, newScope, pkgs, stdenv, cmake
 , libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith
 , buildLlvmTools # tools, but from the previous stage, for cross
 , targetLlvmLibraries # libraries, but from the next stage, for cross
@@ -51,25 +51,17 @@ let
 
     libstdcxxClang = wrapCCWith rec {
       cc = tools.clang-unwrapped;
-      extraTools = [
-        libstdcxxHook
-      ];
+      libcxx = null; # libstdcxx is smuggled in with clang.gcc
       extraPackages = [
         targetLlvmLibraries.compiler-rt
       ];
-      extraBuildCommands = ''
-          echo "-target ${targetConfig}" >> $out/nix-support/cc-cflags
-          echo "-B${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-cflags
-          echo "-L${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-ldflags
-          echo "-L${gcc.cc.lib}/${targetConfig}/lib" >> $out/nix-support/cc-ldflags
-      '' + mkExtraBuildCommands cc;
+      extraBuildCommands = mkExtraBuildCommands cc;
     };
 
     libcxxClang = wrapCCWith rec {
       cc = tools.clang-unwrapped;
       libcxx = targetLlvmLibraries.libcxx;
       extraPackages = [
-        targetLlvmLibraries.libcxx
         targetLlvmLibraries.libcxxabi
         targetLlvmLibraries.compiler-rt
       ];
diff --git a/pkgs/development/compilers/llvm/5/libc++/default.nix b/pkgs/development/compilers/llvm/5/libc++/default.nix
index 88ad3c29c3e..f8185fc3ff4 100644
--- a/pkgs/development/compilers/llvm/5/libc++/default.nix
+++ b/pkgs/development/compilers/llvm/5/libc++/default.nix
@@ -37,12 +37,9 @@ stdenv.mkDerivation {
 
   enableParallelBuilding = true;
 
-  linkCxxAbi = stdenv.isLinux;
-
-  setupHooks = [
-    ../../../../../build-support/setup-hooks/role.bash
-    ./setup-hook.sh
-  ];
+  passthru = {
+    isLLVM = true;
+  };
 
   meta = {
     homepage = "https://libcxx.llvm.org/";
diff --git a/pkgs/development/compilers/llvm/5/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/5/libc++/setup-hook.sh
deleted file mode 100644
index 3a274aecc23..00000000000
--- a/pkgs/development/compilers/llvm/5/libc++/setup-hook.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-# See pkgs/build-support/setup-hooks/role.bash
-getHostRole
-
-linkCxxAbi="@linkCxxAbi@"
-export NIX_CXXSTDLIB_COMPILE${role_post}+=" -isystem @out@/include/c++/v1"
-export NIX_CXXSTDLIB_LINK${role_post}=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
diff --git a/pkgs/development/compilers/llvm/6/default.nix b/pkgs/development/compilers/llvm/6/default.nix
index b544a4f6ba6..2316fbfc3fb 100644
--- a/pkgs/development/compilers/llvm/6/default.nix
+++ b/pkgs/development/compilers/llvm/6/default.nix
@@ -1,4 +1,4 @@
-{ lowPrio, newScope, pkgs, stdenv, cmake, gcc, libstdcxxHook
+{ lowPrio, newScope, pkgs, stdenv, cmake
 , libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith
 , buildLlvmTools # tools, but from the previous stage, for cross
 , targetLlvmLibraries # libraries, but from the next stage, for cross
@@ -51,25 +51,17 @@ let
 
     libstdcxxClang = wrapCCWith rec {
       cc = tools.clang-unwrapped;
-      extraTools = [
-        libstdcxxHook
-      ];
+      libcxx = null; # libstdcxx is smuggled in with clang.gcc
       extraPackages = [
         targetLlvmLibraries.compiler-rt
       ];
-      extraBuildCommands = ''
-          echo "-target ${targetConfig}" >> $out/nix-support/cc-cflags
-          echo "-B${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-cflags
-          echo "-L${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-ldflags
-          echo "-L${gcc.cc.lib}/${targetConfig}/lib" >> $out/nix-support/cc-ldflags
-      '' + mkExtraBuildCommands cc;
+      extraBuildCommands = mkExtraBuildCommands cc;
     };
 
     libcxxClang = wrapCCWith rec {
       cc = tools.clang-unwrapped;
       libcxx = targetLlvmLibraries.libcxx;
       extraPackages = [
-        targetLlvmLibraries.libcxx
         targetLlvmLibraries.libcxxabi
         targetLlvmLibraries.compiler-rt
       ];
diff --git a/pkgs/development/compilers/llvm/6/libc++/default.nix b/pkgs/development/compilers/llvm/6/libc++/default.nix
index 57f1431f471..a922bcfaf0e 100644
--- a/pkgs/development/compilers/llvm/6/libc++/default.nix
+++ b/pkgs/development/compilers/llvm/6/libc++/default.nix
@@ -37,12 +37,9 @@ stdenv.mkDerivation {
 
   enableParallelBuilding = true;
 
-  linkCxxAbi = stdenv.isLinux;
-
-  setupHooks = [
-    ../../../../../build-support/setup-hooks/role.bash
-    ./setup-hook.sh
-  ];
+  passthru = {
+    isLLVM = true;
+  };
 
   meta = {
     homepage = "https://libcxx.llvm.org/";
diff --git a/pkgs/development/compilers/llvm/6/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/6/libc++/setup-hook.sh
deleted file mode 100644
index 3a274aecc23..00000000000
--- a/pkgs/development/compilers/llvm/6/libc++/setup-hook.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-# See pkgs/build-support/setup-hooks/role.bash
-getHostRole
-
-linkCxxAbi="@linkCxxAbi@"
-export NIX_CXXSTDLIB_COMPILE${role_post}+=" -isystem @out@/include/c++/v1"
-export NIX_CXXSTDLIB_LINK${role_post}=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
diff --git a/pkgs/development/compilers/llvm/7/default.nix b/pkgs/development/compilers/llvm/7/default.nix
index 0b71c3a28d2..b83c0d2ceed 100644
--- a/pkgs/development/compilers/llvm/7/default.nix
+++ b/pkgs/development/compilers/llvm/7/default.nix
@@ -1,4 +1,4 @@
-{ lowPrio, newScope, pkgs, stdenv, cmake, gcc, libstdcxxHook
+{ lowPrio, newScope, pkgs, stdenv, cmake
 , libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith
 , buildLlvmTools # tools, but from the previous stage, for cross
 , targetLlvmLibraries # libraries, but from the next stage, for cross
@@ -58,25 +58,17 @@ let
 
     libstdcxxClang = wrapCCWith rec {
       cc = tools.clang-unwrapped;
-      extraTools = [
-        libstdcxxHook
-      ];
+      libcxx = null; # libstdcxx is smuggled in with clang.gcc
       extraPackages = [
         targetLlvmLibraries.compiler-rt
       ];
-      extraBuildCommands = ''
-          echo "-target ${targetConfig}" >> $out/nix-support/cc-cflags
-          echo "-B${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-cflags
-          echo "-L${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-ldflags
-          echo "-L${gcc.cc.lib}/${targetConfig}/lib" >> $out/nix-support/cc-ldflags
-      '' + mkExtraBuildCommands cc;
+      extraBuildCommands = mkExtraBuildCommands cc;
     };
 
     libcxxClang = wrapCCWith rec {
       cc = tools.clang-unwrapped;
       libcxx = targetLlvmLibraries.libcxx;
       extraPackages = [
-        targetLlvmLibraries.libcxx
         targetLlvmLibraries.libcxxabi
         targetLlvmLibraries.compiler-rt
       ];
@@ -87,48 +79,77 @@ let
 
     lldb = callPackage ./lldb.nix {};
 
+    # Below, is the LLVM bootstrapping logic. It handles building a
+    # fully LLVM toolchain from scratch. No GCC toolchain should be
+    # pulled in. As a consequence, it is very quick to build different
+    # targets provided by LLVM and we can also build for what GCC
+    # doesn’t support like LLVM. Probably we should move to some other
+    # file.
+
     bintools = callPackage ./bintools.nix {};
 
     lldClang = wrapCCWith rec {
       cc = tools.clang-unwrapped;
+      libcxx = targetLlvmLibraries.libcxx;
+      bintools = wrapBintoolsWith {
+        inherit (tools) bintools;
+      };
+      extraPackages = [
+        targetLlvmLibraries.libcxxabi
+        targetLlvmLibraries.compiler-rt
+      ];
+      extraBuildCommands = ''
+        echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags
+        echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
+      '' + stdenv.lib.optionalString (!stdenv.targetPlatform.isWasm) ''
+        echo "--unwindlib=libunwind" >> $out/nix-support/cc-cflags
+      '' + stdenv.lib.optionalString stdenv.targetPlatform.isWasm ''
+        echo "-fno-exceptions" >> $out/nix-support/cc-cflags
+      '' + mkExtraBuildCommands cc;
+    };
+
+    lldClangNoLibcxx = wrapCCWith rec {
+      cc = tools.clang-unwrapped;
+      libcxx = null;
       bintools = wrapBintoolsWith {
         inherit (tools) bintools;
       };
       extraPackages = [
-        # targetLlvmLibraries.libcxx
-        # targetLlvmLibraries.libcxxabi
         targetLlvmLibraries.compiler-rt
       ];
       extraBuildCommands = ''
-        echo "-target ${stdenv.targetPlatform.config} -rtlib=compiler-rt" >> $out/nix-support/cc-cflags
+        echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
+        echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
+        echo "-nostdlib++" >> $out/nix-support/cc-cflags
       '' + mkExtraBuildCommands cc;
     };
 
     lldClangNoLibc = wrapCCWith rec {
       cc = tools.clang-unwrapped;
+      libcxx = null;
       bintools = wrapBintoolsWith {
         inherit (tools) bintools;
         libc = null;
       };
       extraPackages = [
-        # targetLlvmLibraries.libcxx
-        # targetLlvmLibraries.libcxxabi
         targetLlvmLibraries.compiler-rt
       ];
       extraBuildCommands = ''
-        echo "-target ${stdenv.targetPlatform.config} -rtlib=compiler-rt" >> $out/nix-support/cc-cflags
+        echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
+        echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
       '' + mkExtraBuildCommands cc;
     };
 
     lldClangNoCompilerRt = wrapCCWith {
       cc = tools.clang-unwrapped;
+      libcxx = null;
       bintools = wrapBintoolsWith {
         inherit (tools) bintools;
         libc = null;
       };
       extraPackages = [ ];
       extraBuildCommands = ''
-        echo "-nostartfiles -target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
+        echo "-nostartfiles" >> $out/nix-support/cc-cflags
       '';
     };
 
@@ -148,9 +169,16 @@ let
 
     libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang;
 
-    libcxx = callPackage ./libc++ {};
+    libcxx = callPackage ./libc++ ({} //
+      (stdenv.lib.optionalAttrs (stdenv.hostPlatform.useLLVM or false) {
+        stdenv = overrideCC stdenv buildLlvmTools.lldClangNoLibcxx;
+      }));
 
-    libcxxabi = callPackage ./libc++abi.nix {};
+    libcxxabi = callPackage ./libc++abi.nix ({} //
+      (stdenv.lib.optionalAttrs (stdenv.hostPlatform.useLLVM or false) {
+        stdenv = overrideCC stdenv buildLlvmTools.lldClangNoLibcxx;
+        libunwind = libraries.libunwind;
+      }));
 
     openmp = callPackage ./openmp.nix {};
   });
diff --git a/pkgs/development/compilers/llvm/7/libc++/default.nix b/pkgs/development/compilers/llvm/7/libc++/default.nix
index 96cb671fa43..83c05cf0e63 100644
--- a/pkgs/development/compilers/llvm/7/libc++/default.nix
+++ b/pkgs/development/compilers/llvm/7/libc++/default.nix
@@ -37,12 +37,9 @@ stdenv.mkDerivation {
 
   enableParallelBuilding = true;
 
-  linkCxxAbi = stdenv.isLinux;
-
-  setupHooks = [
-    ../../../../../build-support/setup-hooks/role.bash
-    ./setup-hook.sh
-  ];
+  passthru = {
+    isLLVM = true;
+  };
 
   meta = {
     homepage = "https://libcxx.llvm.org/";
diff --git a/pkgs/development/compilers/llvm/7/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/7/libc++/setup-hook.sh
deleted file mode 100644
index 3a274aecc23..00000000000
--- a/pkgs/development/compilers/llvm/7/libc++/setup-hook.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-# See pkgs/build-support/setup-hooks/role.bash
-getHostRole
-
-linkCxxAbi="@linkCxxAbi@"
-export NIX_CXXSTDLIB_COMPILE${role_post}+=" -isystem @out@/include/c++/v1"
-export NIX_CXXSTDLIB_LINK${role_post}=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
diff --git a/pkgs/development/compilers/llvm/8/default.nix b/pkgs/development/compilers/llvm/8/default.nix
index d9383d042bb..34b1f5e641b 100644
--- a/pkgs/development/compilers/llvm/8/default.nix
+++ b/pkgs/development/compilers/llvm/8/default.nix
@@ -1,4 +1,4 @@
-{ lowPrio, newScope, pkgs, stdenv, cmake, gcc, libstdcxxHook
+{ lowPrio, newScope, pkgs, stdenv, cmake
 , libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith
 , buildLlvmTools # tools, but from the previous stage, for cross
 , targetLlvmLibraries # libraries, but from the next stage, for cross
@@ -58,25 +58,17 @@ let
 
     libstdcxxClang = wrapCCWith rec {
       cc = tools.clang-unwrapped;
-      extraTools = [
-        libstdcxxHook
-      ];
+      libcxx = null; # libstdcxx is smuggled in with clang.gcc
       extraPackages = [
         targetLlvmLibraries.compiler-rt
       ];
-      extraBuildCommands = ''
-          echo "-target ${targetConfig}" >> $out/nix-support/cc-cflags
-          echo "-B${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-cflags
-          echo "-L${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-ldflags
-          echo "-L${gcc.cc.lib}/${targetConfig}/lib" >> $out/nix-support/cc-ldflags
-      '' + mkExtraBuildCommands cc;
+      extraBuildCommands = mkExtraBuildCommands cc;
     };
 
     libcxxClang = wrapCCWith rec {
       cc = tools.clang-unwrapped;
       libcxx = targetLlvmLibraries.libcxx;
       extraPackages = [
-        targetLlvmLibraries.libcxx
         targetLlvmLibraries.libcxxabi
         targetLlvmLibraries.compiler-rt
       ];
@@ -103,14 +95,12 @@ let
         inherit (tools) bintools;
       };
       extraPackages = [
-        targetLlvmLibraries.libcxx
         targetLlvmLibraries.libcxxabi
         targetLlvmLibraries.compiler-rt
       ] ++ stdenv.lib.optionals (!stdenv.targetPlatform.isWasm) [
         targetLlvmLibraries.libunwind
       ];
       extraBuildCommands = ''
-        echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
         echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags
         echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
       '' + stdenv.lib.optionalString (!stdenv.targetPlatform.isWasm) ''
@@ -130,7 +120,6 @@ let
         targetLlvmLibraries.compiler-rt
       ];
       extraBuildCommands = ''
-        echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
         echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
         echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
         echo "-nostdlib++" >> $out/nix-support/cc-cflags
@@ -148,7 +137,6 @@ let
         targetLlvmLibraries.compiler-rt
       ];
       extraBuildCommands = ''
-        echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
         echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
         echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
       '' + mkExtraBuildCommands cc;
@@ -164,7 +152,6 @@ let
       extraPackages = [ ];
       extraBuildCommands = ''
         echo "-nostartfiles" >> $out/nix-support/cc-cflags
-        echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
       '';
     };
 
diff --git a/pkgs/development/compilers/llvm/8/libc++/default.nix b/pkgs/development/compilers/llvm/8/libc++/default.nix
index 24bca6aafcd..9c0c7951c79 100644
--- a/pkgs/development/compilers/llvm/8/libc++/default.nix
+++ b/pkgs/development/compilers/llvm/8/libc++/default.nix
@@ -43,12 +43,9 @@ stdenv.mkDerivation {
 
   enableParallelBuilding = true;
 
-  linkCxxAbi = stdenv.isLinux;
-
-  setupHooks = [
-    ../../../../../build-support/setup-hooks/role.bash
-    ./setup-hook.sh
-  ];
+  passthru = {
+    isLLVM = true;
+  };
 
   meta = {
     homepage = "https://libcxx.llvm.org/";
diff --git a/pkgs/development/compilers/llvm/8/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/8/libc++/setup-hook.sh
deleted file mode 100644
index 3a274aecc23..00000000000
--- a/pkgs/development/compilers/llvm/8/libc++/setup-hook.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-# See pkgs/build-support/setup-hooks/role.bash
-getHostRole
-
-linkCxxAbi="@linkCxxAbi@"
-export NIX_CXXSTDLIB_COMPILE${role_post}+=" -isystem @out@/include/c++/v1"
-export NIX_CXXSTDLIB_LINK${role_post}=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
diff --git a/pkgs/development/compilers/llvm/9/default.nix b/pkgs/development/compilers/llvm/9/default.nix
index 3b6db967b6a..5d93ca8709f 100644
--- a/pkgs/development/compilers/llvm/9/default.nix
+++ b/pkgs/development/compilers/llvm/9/default.nix
@@ -1,4 +1,4 @@
-{ lowPrio, newScope, pkgs, stdenv, cmake, gcc, libstdcxxHook
+{ lowPrio, newScope, pkgs, stdenv, cmake
 , libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith
 , buildLlvmTools # tools, but from the previous stage, for cross
 , targetLlvmLibraries # libraries, but from the next stage, for cross
@@ -58,25 +58,17 @@ let
 
     libstdcxxClang = wrapCCWith rec {
       cc = tools.clang-unwrapped;
-      extraTools = [
-        libstdcxxHook
-      ];
+      libcxx = null; # libstdcxx is smuggled in with clang.gcc
       extraPackages = [
         targetLlvmLibraries.compiler-rt
       ];
-      extraBuildCommands = ''
-          echo "-target ${targetConfig}" >> $out/nix-support/cc-cflags
-          echo "-B${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-cflags
-          echo "-L${gcc.cc}/lib/gcc/${targetConfig}/${gcc.version}" >> $out/nix-support/cc-ldflags
-          echo "-L${gcc.cc.lib}/${targetConfig}/lib" >> $out/nix-support/cc-ldflags
-      '' + mkExtraBuildCommands cc;
+      extraBuildCommands = mkExtraBuildCommands cc;
     };
 
     libcxxClang = wrapCCWith rec {
       cc = tools.clang-unwrapped;
       libcxx = targetLlvmLibraries.libcxx;
       extraPackages = [
-        targetLlvmLibraries.libcxx
         targetLlvmLibraries.libcxxabi
         targetLlvmLibraries.compiler-rt
       ];
@@ -103,14 +95,12 @@ let
         inherit (tools) bintools;
       };
       extraPackages = [
-        targetLlvmLibraries.libcxx
         targetLlvmLibraries.libcxxabi
         targetLlvmLibraries.compiler-rt
       ] ++ stdenv.lib.optionals (!stdenv.targetPlatform.isWasm) [
         targetLlvmLibraries.libunwind
       ];
       extraBuildCommands = ''
-        echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
         echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags
         echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
       '' + stdenv.lib.optionalString (!stdenv.targetPlatform.isWasm) ''
@@ -130,7 +120,6 @@ let
         targetLlvmLibraries.compiler-rt
       ];
       extraBuildCommands = ''
-        echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
         echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
         echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
         echo "-nostdlib++" >> $out/nix-support/cc-cflags
@@ -148,7 +137,6 @@ let
         targetLlvmLibraries.compiler-rt
       ];
       extraBuildCommands = ''
-        echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
         echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
         echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
       '' + mkExtraBuildCommands cc;
@@ -164,7 +152,6 @@ let
       extraPackages = [ ];
       extraBuildCommands = ''
         echo "-nostartfiles" >> $out/nix-support/cc-cflags
-        echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
       '';
     };
 
diff --git a/pkgs/development/compilers/llvm/9/libc++/default.nix b/pkgs/development/compilers/llvm/9/libc++/default.nix
index f3081d1f269..cec6de61ca9 100644
--- a/pkgs/development/compilers/llvm/9/libc++/default.nix
+++ b/pkgs/development/compilers/llvm/9/libc++/default.nix
@@ -39,12 +39,9 @@ stdenv.mkDerivation {
 
   enableParallelBuilding = true;
 
-  linkCxxAbi = stdenv.isLinux;
-
-  setupHooks = [
-    ../../../../../build-support/setup-hooks/role.bash
-    ./setup-hook.sh
-  ];
+  passthru = {
+    isLLVM = true;
+  };
 
   meta = {
     homepage = "https://libcxx.llvm.org/";
diff --git a/pkgs/development/compilers/llvm/9/libc++/setup-hook.sh b/pkgs/development/compilers/llvm/9/libc++/setup-hook.sh
deleted file mode 100644
index 3a274aecc23..00000000000
--- a/pkgs/development/compilers/llvm/9/libc++/setup-hook.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-# See pkgs/build-support/setup-hooks/role.bash
-getHostRole
-
-linkCxxAbi="@linkCxxAbi@"
-export NIX_CXXSTDLIB_COMPILE${role_post}+=" -isystem @out@/include/c++/v1"
-export NIX_CXXSTDLIB_LINK${role_post}=" -stdlib=libc++${linkCxxAbi:+" -lc++abi"}"
diff --git a/pkgs/development/compilers/swift/default.nix b/pkgs/development/compilers/swift/default.nix
index 0cd1f704421..1ebef9a9ba5 100644
--- a/pkgs/development/compilers/swift/default.nix
+++ b/pkgs/development/compilers/swift/default.nix
@@ -258,7 +258,7 @@ stdenv.mkDerivation {
 
   buildPhase = ''
     # gcc-6.4.0/include/c++/6.4.0/cstdlib:75:15: fatal error: 'stdlib.h' file not found
-    export NIX_CFLAGS_COMPILE="$( echo ${clang.default_cxx_stdlib_compile} ) $NIX_CFLAGS_COMPILE"
+    export NIX_CFLAGS_COMPILE="$(< $NIX_CC/nix-support/libcxx-cxxflags) $NIX_CFLAGS_COMPILE"
     # During the Swift build, a full local LLVM build is performed and the resulting clang is invoked.
     # This compiler is not using the Nix wrappers, so it needs some help to find things.
     export NIX_LDFLAGS_BEFORE="-rpath ${clang.cc.gcc.lib}/lib -L${clang.cc.gcc.lib}/lib $NIX_LDFLAGS_BEFORE"
diff --git a/pkgs/misc/vim-plugins/overrides.nix b/pkgs/misc/vim-plugins/overrides.nix
index d9a68b90041..11ffbfed9ad 100644
--- a/pkgs/misc/vim-plugins/overrides.nix
+++ b/pkgs/misc/vim-plugins/overrides.nix
@@ -98,8 +98,6 @@ self: super: {
     # These usually implicitly set by cc-wrapper around clang (pkgs/build-support/cc-wrapper).
     # The linked ruby code shows generates the required '.clang_complete' for cmake based projects
     # https://gist.github.com/Mic92/135e83803ed29162817fce4098dec144
-    # as an alternative you can execute the following command:
-    # $ eval echo $(nix-instantiate --eval --expr 'with (import <nixpkgs>) {}; clang.default_cxx_stdlib_compile')
     preFixup = ''
       substituteInPlace "$out"/share/vim-plugins/clang_complete/plugin/clang_complete.vim \
         --replace "let g:clang_library_path = '' + "''" + ''" "let g:clang_library_path='${llvmPackages.clang.cc.lib}/lib/libclang.so'"
diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix
index b69de041fd2..9de6ef63bfe 100644
--- a/pkgs/stdenv/darwin/default.nix
+++ b/pkgs/stdenv/darwin/default.nix
@@ -90,11 +90,11 @@ in rec {
         inherit shell;
         inherit (last) stdenvNoCC;
 
-        extraPackages = lib.optional (libcxx != null) libcxx;
+        extraPackages = [];
 
         nativeTools  = false;
         nativeLibc   = false;
-        inherit buildPackages coreutils gnugrep bintools;
+        inherit buildPackages coreutils gnugrep bintools libcxx;
         libc         = last.pkgs.darwin.Libsystem;
         isClang      = true;
         cc           = { name = "${name}-clang"; outPath = bootstrapTools; };
@@ -168,8 +168,9 @@ in rec {
             ln -s ${bootstrapTools}/lib/libc++.dylib $out/lib/libc++.dylib
             ln -s ${bootstrapTools}/include/c++      $out/include/c++
           '';
-          linkCxxAbi = false;
-          setupHook = ../../development/compilers/llvm/7/libc++/setup-hook.sh;
+          passthru = {
+            isLLVM = true;
+          };
         };
 
         libcxxabi = stdenv.mkDerivation {
diff --git a/pkgs/top-level/aliases.nix b/pkgs/top-level/aliases.nix
index 64392f49a52..e9e83584846 100644
--- a/pkgs/top-level/aliases.nix
+++ b/pkgs/top-level/aliases.nix
@@ -264,6 +264,7 @@ mapAliases ({
   libudev = udev; # added 2018-04-25
   libusb = libusb1; # added 2020-04-28
   libsexy = throw "libsexy has been removed from nixpkgs, as it's abandoned and no package needed it."; # 2019-12-10
+  libstdcxxHook = throw "libstdcxx hook has been removed because cc-wrapper is now directly aware of the c++ standard library intended to be used."; # 2020-06-22
   libqmatrixclient = throw "libqmatrixclient was renamed to libquotient"; # added 2020-04-09
   links = links2; # added 2016-01-31
   linux_rpi0 = linux_rpi1;
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 14a494a164f..462d67269a6 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -8188,7 +8188,6 @@ in
   computecpp = wrapCCWith rec {
     cc = computecpp-unwrapped;
     extraPackages = [
-      libstdcxxHook
       llvmPackages.compiler-rt
     ];
     extraBuildCommands = ''
@@ -8330,14 +8329,6 @@ in
     stripped = false;
   }));
 
-  libstdcxxHook = makeSetupHook
-    { substitutions = {
-        gcc = gcc-unwrapped;
-        targetConfig = stdenv.targetPlatform.config;
-      };
-    }
-    ../development/compilers/gcc/libstdc++-hook.sh;
-
   crossLibcStdenv = overrideCC stdenv
     (if stdenv.hostPlatform.useLLVM or false
      then buildPackages.llvmPackages_8.lldClangNoLibc
@@ -9394,6 +9385,10 @@ in
       # provide the default choice, avoiding infinite recursion.
       bintools ? if stdenv.targetPlatform.isDarwin then darwin.binutils else binutils
     , libc ? bintools.libc
+    , # libc++ from the default LLVM version is bound at the top level, but we
+      # want the C++ library to be explicitly chosen by the caller, and null by
+      # default.
+      libcxx ? null
     , extraPackages ? stdenv.lib.optional (cc.isGNU or false && stdenv.targetPlatform.isMinGW) threadsCross
     , ...
     } @ extraArgs:
@@ -9406,7 +9401,7 @@ in
     isGNU = cc.isGNU or false;
     isClang = cc.isClang or false;
 
-    inherit cc bintools libc extraPackages zlib;
+    inherit cc bintools libc libcxx extraPackages zlib;
   } // extraArgs; in self);
 
   wrapCC = cc: wrapCCWith {