From 17c5a15c89f2523b2543f946daa4d018e04d731a Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Fri, 7 Jan 2022 02:25:17 +0100 Subject: [PATCH 1/3] wrapCCWith: rely on the new bintools attribute for default value wrapCCWith shipped its own, but imperfect duplication of the logic we use to choose the bintools for the *next* stage by inspecting targetPlatform. This change should ensure that C compilers relying on the default behavior of wrapCCWith should end up with the same bintools als theirStage.bintools. In particular, this makes pkgsLLVM.llvmPackages.stdenv correctly use the LLVM bintools instead of GNU binutils. --- pkgs/top-level/all-packages.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index d3aa3479d13d..8ce2176df0d5 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -13271,7 +13271,11 @@ with pkgs; # Others should instead delegate to the next stage's choice with # `targetPackages.stdenv.cc.bintools`. This one is different just to # provide the default choice, avoiding infinite recursion. - bintools ? if stdenv.targetPlatform.isDarwin then darwin.binutils else binutils + # See the bintools attribute for the logic and reasoning. We need to provide + # a default here, since eval will hit this function when bootstrapping + # stdenv where the bintools attribute doesn't exist, but will never actually + # be evaluated -- callPackage ends up being too eager. + bintools ? pkgs.bintools , 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 From 766f5ffb761bc916ea0f270f472d04ab30664d52 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Fri, 7 Jan 2022 02:30:01 +0100 Subject: [PATCH 2/3] llvmPackages_*: respect cc for target when choosing C++ flavour MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit llvmPackages_*.clang should check the default compiler for the package set it is targeting (targetPackages.stdenv.cc) instead of the compiler that has been used to build it (stdenv.cc) in order to get some sense of whether to use libc++ or libstdc++. Since we are now inspecting targetPackages in the llvmPackages.clang attribute, we need to avoid using it in the cross stdenv — which just forces us to explicitly request libcxxClang for darwin instead of relying on the clang attribute to pick it for us. We also need to do something similar for targetPackages.stdenv.cc: Here the llvmPackages.clang logic would work as we want (inspect targetPackages.stdenv.cc and if it doesn't exist, make the choice based on stdenv.cc), but it gets locked in a cycle with the previous package. We can easily break this, however: We know that the previous set had clang and the next one doesn't exist, so we'd choose libcxxClang any day of the week. --- pkgs/development/compilers/llvm/10/default.nix | 6 +++++- pkgs/development/compilers/llvm/11/default.nix | 6 +++++- pkgs/development/compilers/llvm/12/default.nix | 6 +++++- pkgs/development/compilers/llvm/13/default.nix | 6 +++++- pkgs/development/compilers/llvm/5/default.nix | 6 +++++- pkgs/development/compilers/llvm/6/default.nix | 6 +++++- pkgs/development/compilers/llvm/7/default.nix | 6 +++++- pkgs/development/compilers/llvm/8/default.nix | 6 +++++- pkgs/development/compilers/llvm/9/default.nix | 6 +++++- pkgs/development/compilers/llvm/git/default.nix | 6 +++++- pkgs/stdenv/booter.nix | 8 +++++++- pkgs/stdenv/cross/default.nix | 2 +- 12 files changed, 58 insertions(+), 12 deletions(-) diff --git a/pkgs/development/compilers/llvm/10/default.nix b/pkgs/development/compilers/llvm/10/default.nix index 8bd7e937e7d7..83840b4fd27e 100644 --- a/pkgs/development/compilers/llvm/10/default.nix +++ b/pkgs/development/compilers/llvm/10/default.nix @@ -89,7 +89,11 @@ let # python3 = pkgs.python3; # don't use python-boot # }); - clang = if stdenv.cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; + # pick clang appropriate for package set we are targeting + clang = + if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU + then tools.libstdcxxClang + else tools.libcxxClang; libstdcxxClang = wrapCCWith rec { cc = tools.clang-unwrapped; diff --git a/pkgs/development/compilers/llvm/11/default.nix b/pkgs/development/compilers/llvm/11/default.nix index ebd0dc672aa3..b5c070915242 100644 --- a/pkgs/development/compilers/llvm/11/default.nix +++ b/pkgs/development/compilers/llvm/11/default.nix @@ -104,7 +104,11 @@ let # python3 = pkgs.python3; # don't use python-boot # }); - clang = if stdenv.cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; + # pick clang appropriate for package set we are targeting + clang = + if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU + then tools.libstdcxxClang + else tools.libcxxClang; libstdcxxClang = wrapCCWith rec { cc = tools.clang-unwrapped; diff --git a/pkgs/development/compilers/llvm/12/default.nix b/pkgs/development/compilers/llvm/12/default.nix index e68522faea06..8de6bb420d41 100644 --- a/pkgs/development/compilers/llvm/12/default.nix +++ b/pkgs/development/compilers/llvm/12/default.nix @@ -92,7 +92,11 @@ let # python3 = pkgs.python3; # don't use python-boot # }); - clang = if stdenv.cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; + # pick clang appropriate for package set we are targeting + clang = + if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU + then tools.libstdcxxClang + else tools.libcxxClang; libstdcxxClang = wrapCCWith rec { cc = tools.clang-unwrapped; diff --git a/pkgs/development/compilers/llvm/13/default.nix b/pkgs/development/compilers/llvm/13/default.nix index a89c6dabe391..bdc07a68742d 100644 --- a/pkgs/development/compilers/llvm/13/default.nix +++ b/pkgs/development/compilers/llvm/13/default.nix @@ -93,7 +93,11 @@ let # python3 = pkgs.python3; # don't use python-boot # }); - clang = if stdenv.cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; + # pick clang appropriate for package set we are targeting + clang = + if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU + then tools.libstdcxxClang + else tools.libcxxClang; libstdcxxClang = wrapCCWith rec { cc = tools.clang-unwrapped; diff --git a/pkgs/development/compilers/llvm/5/default.nix b/pkgs/development/compilers/llvm/5/default.nix index 4593580b72fd..4a6d55d55727 100644 --- a/pkgs/development/compilers/llvm/5/default.nix +++ b/pkgs/development/compilers/llvm/5/default.nix @@ -65,7 +65,11 @@ let python3 = pkgs.python3; # don't use python-boot }); - clang = if stdenv.cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; + # pick clang appropriate for package set we are targeting + clang = + if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU + then tools.libstdcxxClang + else tools.libcxxClang; libstdcxxClang = wrapCCWith rec { cc = tools.clang-unwrapped; diff --git a/pkgs/development/compilers/llvm/6/default.nix b/pkgs/development/compilers/llvm/6/default.nix index 9b1caf410bc2..1b9a793e8858 100644 --- a/pkgs/development/compilers/llvm/6/default.nix +++ b/pkgs/development/compilers/llvm/6/default.nix @@ -66,7 +66,11 @@ let python3 = pkgs.python3; # don't use python-boot }); - clang = if stdenv.cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; + # pick clang appropriate for package set we are targeting + clang = + if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU + then tools.libstdcxxClang + else tools.libcxxClang; libstdcxxClang = wrapCCWith rec { cc = tools.clang-unwrapped; diff --git a/pkgs/development/compilers/llvm/7/default.nix b/pkgs/development/compilers/llvm/7/default.nix index d014c043a80d..841fc120d744 100644 --- a/pkgs/development/compilers/llvm/7/default.nix +++ b/pkgs/development/compilers/llvm/7/default.nix @@ -96,7 +96,11 @@ let python3 = pkgs.python3; # don't use python-boot }); - clang = if stdenv.cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; + # pick clang appropriate for package set we are targeting + clang = + if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU + then tools.libstdcxxClang + else tools.libcxxClang; libstdcxxClang = wrapCCWith rec { cc = tools.clang-unwrapped; diff --git a/pkgs/development/compilers/llvm/8/default.nix b/pkgs/development/compilers/llvm/8/default.nix index 7252b75a3397..234473c1adae 100644 --- a/pkgs/development/compilers/llvm/8/default.nix +++ b/pkgs/development/compilers/llvm/8/default.nix @@ -97,7 +97,11 @@ let python3 = pkgs.python3; # don't use python-boot }); - clang = if stdenv.cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; + # pick clang appropriate for package set we are targeting + clang = + if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU + then tools.libstdcxxClang + else tools.libcxxClang; libstdcxxClang = wrapCCWith rec { cc = tools.clang-unwrapped; diff --git a/pkgs/development/compilers/llvm/9/default.nix b/pkgs/development/compilers/llvm/9/default.nix index 9126a614b106..a10bac13824e 100644 --- a/pkgs/development/compilers/llvm/9/default.nix +++ b/pkgs/development/compilers/llvm/9/default.nix @@ -97,7 +97,11 @@ let python3 = pkgs.python3; # don't use python-boot }); - clang = if stdenv.cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; + # pick clang appropriate for package set we are targeting + clang = + if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU + then tools.libstdcxxClang + else tools.libcxxClang; libstdcxxClang = wrapCCWith rec { cc = tools.clang-unwrapped; diff --git a/pkgs/development/compilers/llvm/git/default.nix b/pkgs/development/compilers/llvm/git/default.nix index 666e9be3cd89..56904addb52b 100644 --- a/pkgs/development/compilers/llvm/git/default.nix +++ b/pkgs/development/compilers/llvm/git/default.nix @@ -93,7 +93,11 @@ let # python3 = pkgs.python3; # don't use python-boot # }); - clang = if stdenv.cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; + # pick clang appropriate for package set we are targeting + clang = + if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU + then tools.libstdcxxClang + else tools.libcxxClang; libstdcxxClang = wrapCCWith rec { cc = tools.clang-unwrapped; diff --git a/pkgs/stdenv/booter.nix b/pkgs/stdenv/booter.nix index 51d617354e86..f1d07e6461a9 100644 --- a/pkgs/stdenv/booter.nix +++ b/pkgs/stdenv/booter.nix @@ -124,7 +124,13 @@ stageFuns: let if buildPackages.stdenv.hasCC then if buildPackages.stdenv.cc.isClang or false - then buildPackages.clang + # buildPackages.clang checks targetPackages.stdenv.cc (i. e. this + # attribute) to get a sense of the its set's default compiler and + # chooses between libc++ and libstdc++ based on that. If we hit this + # code here, we'll cause an infinite recursion. Since a set with + # clang as its default compiler always means libc++, we can infer this + # decision statically. + then buildPackages.llvmPackages.libcxxClang else buildPackages.gcc else # This will blow up if anything uses it, but that's OK. The `if diff --git a/pkgs/stdenv/cross/default.nix b/pkgs/stdenv/cross/default.nix index 613b8d5304c0..e01ac74599ae 100644 --- a/pkgs/stdenv/cross/default.nix +++ b/pkgs/stdenv/cross/default.nix @@ -70,7 +70,7 @@ in lib.init bootStages ++ [ # when there is a C compiler and everything should be fine. then throw "no C compiler provided for this platform" else if crossSystem.isDarwin - then buildPackages.llvmPackages.clang + then buildPackages.llvmPackages.libcxxClang else if crossSystem.useLLVM or false then buildPackages.llvmPackages.clangUseLLVM else buildPackages.gcc; From e238f456b8d643d5afe5370e942e82204907d0ef Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Fri, 7 Jan 2022 12:58:21 +0100 Subject: [PATCH 3/3] llvmPackages_*.clang: pick clangUseLLVM if targetPlatform.useLLVM libcxxClang still depends on cc wrapper's gccForLibs for libgcc which is not available when useLLVM is set. In such cases we need to switch to clangUseLLVM and (try) to use compiler-rt instead. Resolves #153759: pkgsLLVM.llvmPackages.stdenv now correctly clangUseLLVM as cc, allowing compilation to work as expected. --- pkgs/development/compilers/llvm/10/default.nix | 4 ++-- pkgs/development/compilers/llvm/11/default.nix | 4 ++-- pkgs/development/compilers/llvm/12/default.nix | 4 ++-- pkgs/development/compilers/llvm/13/default.nix | 4 ++-- pkgs/development/compilers/llvm/5/default.nix | 4 ++-- pkgs/development/compilers/llvm/6/default.nix | 4 ++-- pkgs/development/compilers/llvm/7/default.nix | 4 ++-- pkgs/development/compilers/llvm/8/default.nix | 4 ++-- pkgs/development/compilers/llvm/9/default.nix | 4 ++-- pkgs/development/compilers/llvm/git/default.nix | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/pkgs/development/compilers/llvm/10/default.nix b/pkgs/development/compilers/llvm/10/default.nix index 83840b4fd27e..5cb6c278659d 100644 --- a/pkgs/development/compilers/llvm/10/default.nix +++ b/pkgs/development/compilers/llvm/10/default.nix @@ -91,8 +91,8 @@ let # pick clang appropriate for package set we are targeting clang = - if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU - then tools.libstdcxxClang + /**/ if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; libstdcxxClang = wrapCCWith rec { diff --git a/pkgs/development/compilers/llvm/11/default.nix b/pkgs/development/compilers/llvm/11/default.nix index b5c070915242..82a78af85cac 100644 --- a/pkgs/development/compilers/llvm/11/default.nix +++ b/pkgs/development/compilers/llvm/11/default.nix @@ -106,8 +106,8 @@ let # pick clang appropriate for package set we are targeting clang = - if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU - then tools.libstdcxxClang + /**/ if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; libstdcxxClang = wrapCCWith rec { diff --git a/pkgs/development/compilers/llvm/12/default.nix b/pkgs/development/compilers/llvm/12/default.nix index 8de6bb420d41..4a2a7ee87894 100644 --- a/pkgs/development/compilers/llvm/12/default.nix +++ b/pkgs/development/compilers/llvm/12/default.nix @@ -94,8 +94,8 @@ let # pick clang appropriate for package set we are targeting clang = - if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU - then tools.libstdcxxClang + /**/ if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; libstdcxxClang = wrapCCWith rec { diff --git a/pkgs/development/compilers/llvm/13/default.nix b/pkgs/development/compilers/llvm/13/default.nix index bdc07a68742d..be5e9404cdd4 100644 --- a/pkgs/development/compilers/llvm/13/default.nix +++ b/pkgs/development/compilers/llvm/13/default.nix @@ -95,8 +95,8 @@ let # pick clang appropriate for package set we are targeting clang = - if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU - then tools.libstdcxxClang + /**/ if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; libstdcxxClang = wrapCCWith rec { diff --git a/pkgs/development/compilers/llvm/5/default.nix b/pkgs/development/compilers/llvm/5/default.nix index 4a6d55d55727..ef9886fb5ea7 100644 --- a/pkgs/development/compilers/llvm/5/default.nix +++ b/pkgs/development/compilers/llvm/5/default.nix @@ -67,8 +67,8 @@ let # pick clang appropriate for package set we are targeting clang = - if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU - then tools.libstdcxxClang + /**/ if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; libstdcxxClang = wrapCCWith rec { diff --git a/pkgs/development/compilers/llvm/6/default.nix b/pkgs/development/compilers/llvm/6/default.nix index 1b9a793e8858..4acfe6cd85d7 100644 --- a/pkgs/development/compilers/llvm/6/default.nix +++ b/pkgs/development/compilers/llvm/6/default.nix @@ -68,8 +68,8 @@ let # pick clang appropriate for package set we are targeting clang = - if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU - then tools.libstdcxxClang + /**/ if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; libstdcxxClang = wrapCCWith rec { diff --git a/pkgs/development/compilers/llvm/7/default.nix b/pkgs/development/compilers/llvm/7/default.nix index 841fc120d744..f0908f30775d 100644 --- a/pkgs/development/compilers/llvm/7/default.nix +++ b/pkgs/development/compilers/llvm/7/default.nix @@ -98,8 +98,8 @@ let # pick clang appropriate for package set we are targeting clang = - if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU - then tools.libstdcxxClang + /**/ if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; libstdcxxClang = wrapCCWith rec { diff --git a/pkgs/development/compilers/llvm/8/default.nix b/pkgs/development/compilers/llvm/8/default.nix index 234473c1adae..43050a72b922 100644 --- a/pkgs/development/compilers/llvm/8/default.nix +++ b/pkgs/development/compilers/llvm/8/default.nix @@ -99,8 +99,8 @@ let # pick clang appropriate for package set we are targeting clang = - if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU - then tools.libstdcxxClang + /**/ if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; libstdcxxClang = wrapCCWith rec { diff --git a/pkgs/development/compilers/llvm/9/default.nix b/pkgs/development/compilers/llvm/9/default.nix index a10bac13824e..7efe8486a387 100644 --- a/pkgs/development/compilers/llvm/9/default.nix +++ b/pkgs/development/compilers/llvm/9/default.nix @@ -99,8 +99,8 @@ let # pick clang appropriate for package set we are targeting clang = - if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU - then tools.libstdcxxClang + /**/ if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; libstdcxxClang = wrapCCWith rec { diff --git a/pkgs/development/compilers/llvm/git/default.nix b/pkgs/development/compilers/llvm/git/default.nix index 56904addb52b..890270c851db 100644 --- a/pkgs/development/compilers/llvm/git/default.nix +++ b/pkgs/development/compilers/llvm/git/default.nix @@ -95,8 +95,8 @@ let # pick clang appropriate for package set we are targeting clang = - if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU - then tools.libstdcxxClang + /**/ if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang else tools.libcxxClang; libstdcxxClang = wrapCCWith rec {