about summary refs log tree commit diff
path: root/pkgs/build-support/cc-wrapper
diff options
context:
space:
mode:
authorRahul Butani <rrbutani@users.noreply.github.com>2023-04-12 14:51:11 -0500
committerSomeone Serge <sergei.kozlukov@aalto.fi>2024-01-12 17:38:00 +0000
commit290ea23649ef663eab7de48992de87c647316044 (patch)
treea26f5c9ffed8fce4296f0421df5802f12012f902 /pkgs/build-support/cc-wrapper
parent223283c66b431a937dc41c760f08067336c9c113 (diff)
cc-wrapper: expose the c++ std library being used
(cherry picked from commit dc6a8f9f7912363577e11520bafa040c0db14359)
Diffstat (limited to 'pkgs/build-support/cc-wrapper')
-rw-r--r--pkgs/build-support/cc-wrapper/default.nix26
1 files changed, 26 insertions, 0 deletions
diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix
index 56075a032971c..e07d465646543 100644
--- a/pkgs/build-support/cc-wrapper/default.nix
+++ b/pkgs/build-support/cc-wrapper/default.nix
@@ -261,6 +261,25 @@ stdenv.mkDerivation {
     inherit bintools;
     inherit cc libc libcxx nativeTools nativeLibc nativePrefix isGNU isClang;
 
+    # Expose the C++ standard library we're using. See the comments on "General
+    # libc++ support". This is also relevant when using older gcc than the
+    # stdenv's, as may be required e.g. by CUDAToolkit's nvcc.
+    cxxStdlib =
+      let
+        givenLibcxx = libcxx.isLLVM or false;
+        givenGccForLibs = useGccForLibs && gccForLibs.langCC or false;
+      in
+      if (!givenLibcxx) && givenGccForLibs then
+        { kind = "libstdc++"; lib = gccForLibs; }
+      else if givenLibcxx then
+        { kind = "libc++"; lib = libcxx; }
+      else
+      # We're probably using the `libstdc++` that came with our `gcc`.
+      # TODO: this is maybe not always correct?
+      # TODO: what happens when `nativeTools = true`?
+        { kind = "libstdc++"; lib = cc_solib; }
+    ;
+
     emacsBufferSetup = pkgs: ''
       ; We should handle propagation here too
       (mapc
@@ -440,6 +459,13 @@ stdenv.mkDerivation {
       echo "-L${gccForLibs}/lib/gcc/${targetPlatform.config}/${gccForLibs.version}" >> $out/nix-support/cc-ldflags
       echo "-L${gccForLibs_solib}/lib" >> $out/nix-support/cc-ldflags
     ''
+    # The above "fix" may be incorrect; gcc.cc.lib doesn't contain a
+    # `target-triple` dir but the correct fix may be to just remove the above?
+    #
+    # For clang it's not necessary (see `--gcc-toolchain` below) and for other
+    # situations adding in the above will bring in lots of other gcc libraries
+    # (i.e. sanitizer libraries, `libatomic`, `libquadmath`) besides just
+    # `libstdc++`; this may actually break clang.
 
     # TODO We would like to connect this to `useGccForLibs`, but we cannot yet
     # because `libcxxStdenv` on linux still needs this. Maybe someday we'll