From b89ce8b48b1b44f7d6d6f921da8050a300477c36 Mon Sep 17 00:00:00 2001 From: SharzyL Date: Sat, 11 Mar 2023 10:48:51 +0800 Subject: [PATCH] llvmPackages_*.clang: bind linker on compiling clang When using clang for cross compilation, clang cannot find the linker. Because, for consistency with gcc, given a linker name, clang finds the linker in the following order: 1. in prefix dirs, which contains toolchain specific paths and paths specified by `-B` 2. in ProgramPaths 3. in PATH environment (refer to `Driver::GetProgramPath` in `clang/lib/Driver/Driver.cpp`) (also refer to https://gcc.gnu.org/onlinedocs/gccint/Collect2.html) The step 2 and 3 considers all possible target triple prefixes, but the step 1 does not. In nixpkgs, all binaries in cross toolchains are prefixed by the target triple, thus clang cannot find them. For gcc in nixpkgs, the linker path is hardcoded in configuration phase. This commit copies this behavior to clang. But the added cmakeFlags also introduce circular dependency. The circle comes from the fact that clangNoLibc and clangNoCompilerRT introduce dependency of libc unexpectedly via cmakeFlags of their underlying clang. We need to override bintools for them. Refer to https://github.com/NixOS/nixpkgs/pull/220595#issuecomment-1787393460 for details. --- .../compilers/llvm/10/clang/default.nix | 3 +++ pkgs/development/compilers/llvm/10/default.nix | 8 ++++++-- .../compilers/llvm/11/clang/default.nix | 3 +++ pkgs/development/compilers/llvm/11/default.nix | 8 ++++++-- .../compilers/llvm/12/clang/default.nix | 3 +++ pkgs/development/compilers/llvm/12/default.nix | 8 ++++++-- .../compilers/llvm/13/clang/default.nix | 3 +++ pkgs/development/compilers/llvm/13/default.nix | 8 ++++++-- .../compilers/llvm/14/clang/default.nix | 3 +++ pkgs/development/compilers/llvm/14/default.nix | 8 ++++++-- .../compilers/llvm/15/clang/default.nix | 3 +++ pkgs/development/compilers/llvm/15/default.nix | 8 ++++++-- .../compilers/llvm/16/clang/default.nix | 3 +++ pkgs/development/compilers/llvm/16/default.nix | 8 ++++++-- .../development/compilers/llvm/5/clang/default.nix | 3 +++ .../development/compilers/llvm/6/clang/default.nix | 3 +++ .../development/compilers/llvm/7/clang/default.nix | 3 +++ pkgs/development/compilers/llvm/7/default.nix | 8 ++++++-- .../development/compilers/llvm/8/clang/default.nix | 3 +++ pkgs/development/compilers/llvm/8/default.nix | 8 ++++++-- .../development/compilers/llvm/9/clang/default.nix | 3 +++ pkgs/development/compilers/llvm/9/default.nix | 8 ++++++-- .../compilers/llvm/git/clang/default.nix | 3 +++ pkgs/development/compilers/llvm/git/default.nix | 8 ++++++-- pkgs/os-specific/darwin/cctools/llvm.nix | 4 ++-- pkgs/top-level/darwin-packages.nix | 14 ++++++++++++-- 26 files changed, 119 insertions(+), 26 deletions(-) diff --git a/pkgs/development/compilers/llvm/10/clang/default.nix b/pkgs/development/compilers/llvm/10/clang/default.nix index ad4e913041583..0e1efd86d251c 100644 --- a/pkgs/development/compilers/llvm/10/clang/default.nix +++ b/pkgs/development/compilers/llvm/10/clang/default.nix @@ -2,6 +2,7 @@ , buildLlvmTools , fixDarwinDylibNames , enableManpages ? false +, targetPackages }: let @@ -37,6 +38,8 @@ let ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.targetPlatform) [ + "-DCLANG_DEFAULT_LINKER=${targetPackages.stdenv.cc.bintools}/bin/${stdenv.targetPlatform.config}-ld" ]; patches = [ diff --git a/pkgs/development/compilers/llvm/10/default.nix b/pkgs/development/compilers/llvm/10/default.nix index 37c32e425c63c..81cb25bd817ea 100644 --- a/pkgs/development/compilers/llvm/10/default.nix +++ b/pkgs/development/compilers/llvm/10/default.nix @@ -195,7 +195,9 @@ let }; clangNoLibc = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ @@ -208,7 +210,9 @@ let }; clangNoCompilerRt = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ ]; diff --git a/pkgs/development/compilers/llvm/11/clang/default.nix b/pkgs/development/compilers/llvm/11/clang/default.nix index f0d41a3ab7347..d182cac1b2c05 100644 --- a/pkgs/development/compilers/llvm/11/clang/default.nix +++ b/pkgs/development/compilers/llvm/11/clang/default.nix @@ -3,6 +3,7 @@ , fixDarwinDylibNames , enableManpages ? false , enablePolly ? false +, targetPackages }: let @@ -42,6 +43,8 @@ let ] ++ lib.optionals enablePolly [ "-DWITH_POLLY=ON" "-DLINK_POLLY_INTO_TOOLS=ON" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.targetPlatform) [ + "-DCLANG_DEFAULT_LINKER=${targetPackages.stdenv.cc.bintools}/bin/${stdenv.targetPlatform.config}-ld" ]; diff --git a/pkgs/development/compilers/llvm/11/default.nix b/pkgs/development/compilers/llvm/11/default.nix index 6ce7d86c835e0..c782795b6c07c 100644 --- a/pkgs/development/compilers/llvm/11/default.nix +++ b/pkgs/development/compilers/llvm/11/default.nix @@ -210,7 +210,9 @@ let }; clangNoLibc = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ @@ -223,7 +225,9 @@ let }; clangNoCompilerRt = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ ]; diff --git a/pkgs/development/compilers/llvm/12/clang/default.nix b/pkgs/development/compilers/llvm/12/clang/default.nix index 7ecd4efc08378..d8f6e50b348ce 100644 --- a/pkgs/development/compilers/llvm/12/clang/default.nix +++ b/pkgs/development/compilers/llvm/12/clang/default.nix @@ -2,6 +2,7 @@ , buildLlvmTools , fixDarwinDylibNames , enableManpages ? false +, targetPackages }: let @@ -40,6 +41,8 @@ let ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.targetPlatform) [ + "-DCLANG_DEFAULT_LINKER=${targetPackages.stdenv.cc.bintools}/bin/${stdenv.targetPlatform.config}-ld" ]; patches = [ diff --git a/pkgs/development/compilers/llvm/12/default.nix b/pkgs/development/compilers/llvm/12/default.nix index b976dd2ee67a1..81bed7d9db964 100644 --- a/pkgs/development/compilers/llvm/12/default.nix +++ b/pkgs/development/compilers/llvm/12/default.nix @@ -210,7 +210,9 @@ let }; clangNoLibc = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ @@ -223,7 +225,9 @@ let }; clangNoCompilerRt = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ ]; diff --git a/pkgs/development/compilers/llvm/13/clang/default.nix b/pkgs/development/compilers/llvm/13/clang/default.nix index a070e64c7ddd9..8c103702bb39e 100644 --- a/pkgs/development/compilers/llvm/13/clang/default.nix +++ b/pkgs/development/compilers/llvm/13/clang/default.nix @@ -2,6 +2,7 @@ , buildLlvmTools , fixDarwinDylibNames , enableManpages ? false +, targetPackages }: let @@ -30,6 +31,8 @@ let ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.targetPlatform) [ + "-DCLANG_DEFAULT_LINKER=${targetPackages.stdenv.cc.bintools}/bin/${stdenv.targetPlatform.config}-ld" ]; patches = [ diff --git a/pkgs/development/compilers/llvm/13/default.nix b/pkgs/development/compilers/llvm/13/default.nix index 3cf7cd711ebef..d1cb799a5f47d 100644 --- a/pkgs/development/compilers/llvm/13/default.nix +++ b/pkgs/development/compilers/llvm/13/default.nix @@ -223,7 +223,9 @@ let }; clangNoLibc = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ @@ -236,7 +238,9 @@ let }; clangNoCompilerRt = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ ]; diff --git a/pkgs/development/compilers/llvm/14/clang/default.nix b/pkgs/development/compilers/llvm/14/clang/default.nix index 976ff7580ac31..7f0eb3f8f6fa3 100644 --- a/pkgs/development/compilers/llvm/14/clang/default.nix +++ b/pkgs/development/compilers/llvm/14/clang/default.nix @@ -4,6 +4,7 @@ , buildLlvmTools , fixDarwinDylibNames , enableManpages ? false +, targetPackages }: let @@ -38,6 +39,8 @@ let ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.targetPlatform) [ + "-DCLANG_DEFAULT_LINKER=${targetPackages.stdenv.cc.bintools}/bin/${stdenv.targetPlatform.config}-ld" ]; patches = [ diff --git a/pkgs/development/compilers/llvm/14/default.nix b/pkgs/development/compilers/llvm/14/default.nix index b9a74e0f070a9..7183d83435af3 100644 --- a/pkgs/development/compilers/llvm/14/default.nix +++ b/pkgs/development/compilers/llvm/14/default.nix @@ -226,7 +226,9 @@ let }; clangNoLibc = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ @@ -240,7 +242,9 @@ let }; clangNoCompilerRt = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ ]; diff --git a/pkgs/development/compilers/llvm/15/clang/default.nix b/pkgs/development/compilers/llvm/15/clang/default.nix index 894db1a4975f6..bd79bb3e29ceb 100644 --- a/pkgs/development/compilers/llvm/15/clang/default.nix +++ b/pkgs/development/compilers/llvm/15/clang/default.nix @@ -4,6 +4,7 @@ , buildLlvmTools , fixDarwinDylibNames , enableManpages ? false +, targetPackages }: let @@ -44,6 +45,8 @@ let # `clang-pseudo-gen`: https://github.com/llvm/llvm-project/commit/cd2292ef824591cc34cc299910a3098545c840c7 "-DCLANG_TIDY_CONFUSABLE_CHARS_GEN=${buildLlvmTools.libclang.dev}/bin/clang-tidy-confusable-chars-gen" "-DCLANG_PSEUDO_GEN=${buildLlvmTools.libclang.dev}/bin/clang-pseudo-gen" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.targetPlatform) [ + "-DCLANG_DEFAULT_LINKER=${targetPackages.stdenv.cc.bintools}/bin/${stdenv.targetPlatform.config}-ld" ]; patches = [ diff --git a/pkgs/development/compilers/llvm/15/default.nix b/pkgs/development/compilers/llvm/15/default.nix index 863d31874ec8c..2b0fa2f8e2e52 100644 --- a/pkgs/development/compilers/llvm/15/default.nix +++ b/pkgs/development/compilers/llvm/15/default.nix @@ -274,7 +274,9 @@ in let }; clangNoLibc = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ @@ -288,7 +290,9 @@ in let }; clangNoCompilerRt = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ ]; diff --git a/pkgs/development/compilers/llvm/16/clang/default.nix b/pkgs/development/compilers/llvm/16/clang/default.nix index 2a2656df5fe1c..973fd568513dd 100644 --- a/pkgs/development/compilers/llvm/16/clang/default.nix +++ b/pkgs/development/compilers/llvm/16/clang/default.nix @@ -4,6 +4,7 @@ , buildLlvmTools , fixDarwinDylibNames , enableManpages ? false +, targetPackages }: let @@ -44,6 +45,8 @@ let # `clang-pseudo-gen`: https://github.com/llvm/llvm-project/commit/cd2292ef824591cc34cc299910a3098545c840c7 "-DCLANG_TIDY_CONFUSABLE_CHARS_GEN=${buildLlvmTools.libclang.dev}/bin/clang-tidy-confusable-chars-gen" "-DCLANG_PSEUDO_GEN=${buildLlvmTools.libclang.dev}/bin/clang-pseudo-gen" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.targetPlatform) [ + "-DCLANG_DEFAULT_LINKER=${targetPackages.stdenv.cc.bintools}/bin/${stdenv.targetPlatform.config}-ld" ]; patches = [ diff --git a/pkgs/development/compilers/llvm/16/default.nix b/pkgs/development/compilers/llvm/16/default.nix index 24dd31ea9fef8..0362c82b23f95 100644 --- a/pkgs/development/compilers/llvm/16/default.nix +++ b/pkgs/development/compilers/llvm/16/default.nix @@ -279,7 +279,9 @@ in let }; clangNoLibc = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ @@ -293,7 +295,9 @@ in let }; clangNoCompilerRt = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ ]; diff --git a/pkgs/development/compilers/llvm/5/clang/default.nix b/pkgs/development/compilers/llvm/5/clang/default.nix index 70ffb3e0dd19e..41efb8fffcce5 100644 --- a/pkgs/development/compilers/llvm/5/clang/default.nix +++ b/pkgs/development/compilers/llvm/5/clang/default.nix @@ -2,6 +2,7 @@ , buildLlvmTools , fixDarwinDylibNames , enableManpages ? false +, targetPackages }: let @@ -38,6 +39,8 @@ let ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.targetPlatform) [ + "-DCLANG_DEFAULT_LINKER=${targetPackages.stdenv.cc.bintools}/bin/${stdenv.targetPlatform.config}-ld" ]; patches = [ diff --git a/pkgs/development/compilers/llvm/6/clang/default.nix b/pkgs/development/compilers/llvm/6/clang/default.nix index bc69f1c99cf47..3dd063b21e481 100644 --- a/pkgs/development/compilers/llvm/6/clang/default.nix +++ b/pkgs/development/compilers/llvm/6/clang/default.nix @@ -2,6 +2,7 @@ , buildLlvmTools , fixDarwinDylibNames , enableManpages ? false +, targetPackages }: let @@ -38,6 +39,8 @@ let ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.targetPlatform) [ + "-DCLANG_DEFAULT_LINKER=${targetPackages.stdenv.cc.bintools}/bin/${stdenv.targetPlatform.config}-ld" ]; patches = [ diff --git a/pkgs/development/compilers/llvm/7/clang/default.nix b/pkgs/development/compilers/llvm/7/clang/default.nix index 136a69e72161a..6b7f057d4f55e 100644 --- a/pkgs/development/compilers/llvm/7/clang/default.nix +++ b/pkgs/development/compilers/llvm/7/clang/default.nix @@ -3,6 +3,7 @@ , fixDarwinDylibNames , enableManpages ? false , enablePolly ? false # TODO: get this info from llvm (passthru?) +, targetPackages }: let @@ -42,6 +43,8 @@ let ] ++ lib.optionals enablePolly [ "-DWITH_POLLY=ON" "-DLINK_POLLY_INTO_TOOLS=ON" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.targetPlatform) [ + "-DCLANG_DEFAULT_LINKER=${targetPackages.stdenv.cc.bintools}/bin/${stdenv.targetPlatform.config}-ld" ]; patches = [ diff --git a/pkgs/development/compilers/llvm/7/default.nix b/pkgs/development/compilers/llvm/7/default.nix index 0607b5ebf42c2..adcb11d9beea8 100644 --- a/pkgs/development/compilers/llvm/7/default.nix +++ b/pkgs/development/compilers/llvm/7/default.nix @@ -197,7 +197,9 @@ let }; clangNoLibc = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ @@ -210,7 +212,9 @@ let }; clangNoCompilerRt = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ ]; diff --git a/pkgs/development/compilers/llvm/8/clang/default.nix b/pkgs/development/compilers/llvm/8/clang/default.nix index 994f9bd967c41..02a3c5fcb1ad5 100644 --- a/pkgs/development/compilers/llvm/8/clang/default.nix +++ b/pkgs/development/compilers/llvm/8/clang/default.nix @@ -3,6 +3,7 @@ , fixDarwinDylibNames , enableManpages ? false , enablePolly ? false # TODO: get this info from llvm (passthru?) +, targetPackages }: let @@ -42,6 +43,8 @@ let ] ++ lib.optionals enablePolly [ "-DWITH_POLLY=ON" "-DLINK_POLLY_INTO_TOOLS=ON" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.targetPlatform) [ + "-DCLANG_DEFAULT_LINKER=${targetPackages.stdenv.cc.bintools}/bin/${stdenv.targetPlatform.config}-ld" ]; patches = [ diff --git a/pkgs/development/compilers/llvm/8/default.nix b/pkgs/development/compilers/llvm/8/default.nix index 5beb8afb2ee94..00757c9248912 100644 --- a/pkgs/development/compilers/llvm/8/default.nix +++ b/pkgs/development/compilers/llvm/8/default.nix @@ -198,7 +198,9 @@ let }; clangNoLibc = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ @@ -211,7 +213,9 @@ let }; clangNoCompilerRt = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ ]; diff --git a/pkgs/development/compilers/llvm/9/clang/default.nix b/pkgs/development/compilers/llvm/9/clang/default.nix index 75814fc11c481..e37ad21cf8458 100644 --- a/pkgs/development/compilers/llvm/9/clang/default.nix +++ b/pkgs/development/compilers/llvm/9/clang/default.nix @@ -3,6 +3,7 @@ , fixDarwinDylibNames , enableManpages ? false , enablePolly ? false # TODO: get this info from llvm (passthru?) +, targetPackages }: let @@ -42,6 +43,8 @@ let ] ++ lib.optionals enablePolly [ "-DWITH_POLLY=ON" "-DLINK_POLLY_INTO_TOOLS=ON" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.targetPlatform) [ + "-DCLANG_DEFAULT_LINKER=${targetPackages.stdenv.cc.bintools}/bin/${stdenv.targetPlatform.config}-ld" ]; patches = [ diff --git a/pkgs/development/compilers/llvm/9/default.nix b/pkgs/development/compilers/llvm/9/default.nix index 9f79dc5cce7fc..30ca6e4362b0f 100644 --- a/pkgs/development/compilers/llvm/9/default.nix +++ b/pkgs/development/compilers/llvm/9/default.nix @@ -198,7 +198,9 @@ let }; clangNoLibc = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ @@ -211,7 +213,9 @@ let }; clangNoCompilerRt = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ ]; diff --git a/pkgs/development/compilers/llvm/git/clang/default.nix b/pkgs/development/compilers/llvm/git/clang/default.nix index 733f5462d320c..60758ad8fd585 100644 --- a/pkgs/development/compilers/llvm/git/clang/default.nix +++ b/pkgs/development/compilers/llvm/git/clang/default.nix @@ -4,6 +4,7 @@ , buildLlvmTools , fixDarwinDylibNames , enableManpages ? false +, targetPackages }: let @@ -44,6 +45,8 @@ let # `clang-pseudo-gen`: https://github.com/llvm/llvm-project/commit/cd2292ef824591cc34cc299910a3098545c840c7 "-DCLANG_TIDY_CONFUSABLE_CHARS_GEN=${buildLlvmTools.libclang.dev}/bin/clang-tidy-confusable-chars-gen" "-DCLANG_PSEUDO_GEN=${buildLlvmTools.libclang.dev}/bin/clang-pseudo-gen" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.targetPlatform) [ + "-DCLANG_DEFAULT_LINKER=${targetPackages.stdenv.cc.bintools}/bin/${stdenv.targetPlatform.config}-ld" ]; patches = [ diff --git a/pkgs/development/compilers/llvm/git/default.nix b/pkgs/development/compilers/llvm/git/default.nix index 930b716881e81..5dcd046e630ec 100644 --- a/pkgs/development/compilers/llvm/git/default.nix +++ b/pkgs/development/compilers/llvm/git/default.nix @@ -265,7 +265,9 @@ in let }; clangNoLibc = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ @@ -279,7 +281,9 @@ in let }; clangNoCompilerRt = wrapCCWith rec { - cc = tools.clang-unwrapped; + cc = tools.clang-unwrapped.override { + targetPackages.stdenv.cc.bintools = bintoolsNoLibc'; + }; libcxx = null; bintools = bintoolsNoLibc'; extraPackages = [ ]; diff --git a/pkgs/os-specific/darwin/cctools/llvm.nix b/pkgs/os-specific/darwin/cctools/llvm.nix index f2986bf872f76..03b8f3b21ab31 100644 --- a/pkgs/os-specific/darwin/cctools/llvm.nix +++ b/pkgs/os-specific/darwin/cctools/llvm.nix @@ -1,7 +1,7 @@ # Create a cctools-compatible bintools that uses equivalent tools from LLVM in place of the ones # from cctools when possible. -{ lib, stdenv, makeWrapper, cctools-port, llvmPackages, enableManpages ? stdenv.targetPlatform == stdenv.hostPlatform }: +{ lib, stdenv, makeWrapper, cctools-port, llvmPackages, clang-unwrapped, enableManpages ? stdenv.targetPlatform == stdenv.hostPlatform }: let inherit (stdenv) targetPlatform hostPlatform; @@ -86,7 +86,7 @@ stdenv.mkDerivation { '' + lib.optionalString useClangAssembler '' # Use the clang-integrated assembler instead of using `as` from cctools. - makeWrapper "${lib.getBin llvmPackages.clang-unwrapped}/bin/clang" "$out/bin/${targetPrefix}as" \ + makeWrapper "${lib.getBin clang-unwrapped}/bin/clang" "$out/bin/${targetPrefix}as" \ --add-flags "-x assembler -integrated-as -c" '' + '' diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix index ed049340332c6..c4d0fab5bc75e 100644 --- a/pkgs/top-level/darwin-packages.nix +++ b/pkgs/top-level/darwin-packages.nix @@ -21,6 +21,13 @@ makeScopeWithSplicing' { f = (self: let inherit (self) mkDerivation callPackage; + clang-unwrapped-build = let + clang-unwrapped = pkgs.llvmPackages.clang-unwrapped; + in + if clang-unwrapped ? override + then clang-unwrapped.override { targetPackages.stdenv.cc.bintools = buildPackages.binutils; } + else clang-unwrapped; # when clang-unwrapped is bootstrapped and not overridable + # Must use pkgs.callPackage to avoid infinite recursion. # Open source packages that are built from source @@ -74,7 +81,8 @@ impure-cmds // appleSourcePackages // chooseLibs // { binutils-unwrapped = callPackage ../os-specific/darwin/binutils { inherit (pkgs) binutils-unwrapped; - inherit (pkgs.llvmPackages) llvm clang-unwrapped; + inherit (pkgs.llvmPackages) llvm; + clang-unwrapped = clang-unwrapped-build; }; binutils = pkgs.wrapBintoolsWith { @@ -87,7 +95,8 @@ impure-cmds // appleSourcePackages // chooseLibs // { binutilsDualAs-unwrapped = callPackage ../os-specific/darwin/binutils { inherit (pkgs) binutils-unwrapped; - inherit (pkgs.llvmPackages) llvm clang-unwrapped; + inherit (pkgs.llvmPackages) llvm; + clang-unwrapped = clang-unwrapped-build; dualAs = true; }; @@ -112,6 +121,7 @@ impure-cmds // appleSourcePackages // chooseLibs // { cctools-llvm = callPackage ../os-specific/darwin/cctools/llvm.nix { stdenv = if stdenv.isDarwin then stdenv else pkgs.libcxxStdenv; + clang-unwrapped = clang-unwrapped-build; }; cctools-port = callPackage ../os-specific/darwin/cctools/port.nix {