From f3f7612a409e4ebbec634ab7f20e094f206d396a Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 13 Apr 2020 20:44:43 -0400 Subject: [PATCH] C++ Compilers: Systematize handling of standard libraries --- .../networking/browsers/firefox/common.nix | 2 +- .../mailreaders/thunderbird/default.nix | 2 +- pkgs/build-support/cc-wrapper/add-flags.sh | 8 +++ pkgs/build-support/cc-wrapper/cc-wrapper.sh | 2 +- pkgs/build-support/cc-wrapper/default.nix | 61 +++++++++++++---- .../compilers/gcc/libstdc++-hook.sh | 4 -- .../development/compilers/llvm/10/default.nix | 17 +---- .../compilers/llvm/10/libc++/default.nix | 9 +-- .../compilers/llvm/10/libc++/setup-hook.sh | 6 -- pkgs/development/compilers/llvm/5/default.nix | 14 +--- .../compilers/llvm/5/libc++/default.nix | 9 +-- .../compilers/llvm/5/libc++/setup-hook.sh | 6 -- pkgs/development/compilers/llvm/6/default.nix | 14 +--- .../compilers/llvm/6/libc++/default.nix | 9 +-- .../compilers/llvm/6/libc++/setup-hook.sh | 6 -- pkgs/development/compilers/llvm/7/default.nix | 68 +++++++++++++------ .../compilers/llvm/7/libc++/default.nix | 9 +-- .../compilers/llvm/7/libc++/setup-hook.sh | 6 -- pkgs/development/compilers/llvm/8/default.nix | 19 +----- .../compilers/llvm/8/libc++/default.nix | 9 +-- .../compilers/llvm/8/libc++/setup-hook.sh | 6 -- pkgs/development/compilers/llvm/9/default.nix | 19 +----- .../compilers/llvm/9/libc++/default.nix | 9 +-- .../compilers/llvm/9/libc++/setup-hook.sh | 6 -- pkgs/development/compilers/swift/default.nix | 2 +- pkgs/misc/vim-plugins/overrides.nix | 2 - pkgs/stdenv/darwin/default.nix | 9 +-- pkgs/top-level/aliases.nix | 1 + pkgs/top-level/all-packages.nix | 15 ++-- 29 files changed, 150 insertions(+), 199 deletions(-) delete mode 100644 pkgs/development/compilers/gcc/libstdc++-hook.sh delete mode 100644 pkgs/development/compilers/llvm/10/libc++/setup-hook.sh delete mode 100644 pkgs/development/compilers/llvm/5/libc++/setup-hook.sh delete mode 100644 pkgs/development/compilers/llvm/6/libc++/setup-hook.sh delete mode 100644 pkgs/development/compilers/llvm/7/libc++/setup-hook.sh delete mode 100644 pkgs/development/compilers/llvm/8/libc++/setup-hook.sh delete mode 100644 pkgs/development/compilers/llvm/9/libc++/setup-hook.sh diff --git a/pkgs/applications/networking/browsers/firefox/common.nix b/pkgs/applications/networking/browsers/firefox/common.nix index 8060895a2e0f..a8628306bf19 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 73536ae5fc1b..09e72dd8e32b 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 3398f11e8c21..04be3f408ee1 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 cf00202221e6..3f9f099f3bc1 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 da16a23f9dff..e23d1c6dd4e6 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 f5b4123b64d9..000000000000 --- 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 4181ab29bd7f..870d5110d145 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 ed76ce77a8bb..872865ec474b 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 3a274aecc23d..000000000000 --- 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 e7083a6ed13a..5a992f4a3504 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 88ad3c29c3e2..f8185fc3ff4b 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 3a274aecc23d..000000000000 --- 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 b544a4f6ba69..2316fbfc3fb2 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 57f1431f4711..a922bcfaf0ea 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 3a274aecc23d..000000000000 --- 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 0b71c3a28d23..b83c0d2ceedd 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.libcxx - # targetLlvmLibraries.libcxxabi + targetLlvmLibraries.libcxxabi targetLlvmLibraries.compiler-rt ]; extraBuildCommands = '' - echo "-target ${stdenv.targetPlatform.config} -rtlib=compiler-rt" >> $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) '' + 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.compiler-rt + ]; + extraBuildCommands = '' + 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 96cb671fa431..83c05cf0e634 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 3a274aecc23d..000000000000 --- 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 d9383d042bbc..34b1f5e641b8 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 24bca6aafcd1..9c0c7951c794 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 3a274aecc23d..000000000000 --- 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 3b6db967b6a2..5d93ca8709fa 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 f3081d1f2699..cec6de61ca99 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 3a274aecc23d..000000000000 --- 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 0cd1f704421e..1ebef9a9ba5c 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 d9a68b90041e..11ffbfed9ad8 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 ) {}; 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 b69de041fd23..9de6ef63bfea 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 64392f49a52e..e9e835848460 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 14a494a164f5..462d67269a64 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 {