From 290ea23649ef663eab7de48992de87c647316044 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Wed, 12 Apr 2023 14:51:11 -0500 Subject: [PATCH] cc-wrapper: expose the c++ std library being used (cherry picked from commit dc6a8f9f7912363577e11520bafa040c0db14359) --- pkgs/build-support/cc-wrapper/default.nix | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 56075a032971..e07d46564654 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