diff options
author | Yueh-Shun Li <shamrocklee@posteo.net> | 2024-05-16 05:37:22 +0800 |
---|---|---|
committer | John Titor <50095635+JohnRTitor@users.noreply.github.com> | 2024-06-23 01:34:26 +0530 |
commit | eb572c420d34e978e3069de31e9e4c9339ce0df4 (patch) | |
tree | 737ab1da2fdc6a350383d07d2dc7f4c6c3ff29d7 /pkgs/development/compilers | |
parent | ff60b6d3a53ce89bfb9c77fbd8ac977801f9b594 (diff) |
clang-tools: move into llvmPackages
Diffstat (limited to 'pkgs/development/compilers')
10 files changed, 110 insertions, 0 deletions
diff --git a/pkgs/development/compilers/llvm/12/default.nix b/pkgs/development/compilers/llvm/12/default.nix index 0e498aa303565..c7c119a45b8ae 100644 --- a/pkgs/development/compilers/llvm/12/default.nix +++ b/pkgs/development/compilers/llvm/12/default.nix @@ -149,6 +149,9 @@ let # python3 = pkgs.python3; # don't use python-boot # }); + # Wrapper for standalone command line utilities + clang-tools = callPackage ../common/clang-tools { }; + # pick clang appropriate for package set we are targeting clang = /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc diff --git a/pkgs/development/compilers/llvm/13/default.nix b/pkgs/development/compilers/llvm/13/default.nix index 22bdc6140ab30..ffbbe1deb0d4e 100644 --- a/pkgs/development/compilers/llvm/13/default.nix +++ b/pkgs/development/compilers/llvm/13/default.nix @@ -174,6 +174,9 @@ in let # python3 = pkgs.python3; # don't use python-boot # }); + # Wrapper for standalone command line utilities + clang-tools = callPackage ../common/clang-tools { }; + # pick clang appropriate for package set we are targeting clang = /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc diff --git a/pkgs/development/compilers/llvm/14/default.nix b/pkgs/development/compilers/llvm/14/default.nix index 22fd8223c8f27..06972af065c98 100644 --- a/pkgs/development/compilers/llvm/14/default.nix +++ b/pkgs/development/compilers/llvm/14/default.nix @@ -145,6 +145,9 @@ in let # python3 = pkgs.python3; # don't use python-boot # }); + # Wrapper for standalone command line utilities + clang-tools = callPackage ../common/clang-tools { }; + # pick clang appropriate for package set we are targeting clang = /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc diff --git a/pkgs/development/compilers/llvm/15/default.nix b/pkgs/development/compilers/llvm/15/default.nix index b3d2d9c3de48c..e50e35b2c4eb0 100644 --- a/pkgs/development/compilers/llvm/15/default.nix +++ b/pkgs/development/compilers/llvm/15/default.nix @@ -188,6 +188,9 @@ in let python3 = pkgs.python3; # don't use python-boot }); + # Wrapper for standalone command line utilities + clang-tools = callPackage ../common/clang-tools { }; + # pick clang appropriate for package set we are targeting clang = /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc diff --git a/pkgs/development/compilers/llvm/16/default.nix b/pkgs/development/compilers/llvm/16/default.nix index 521e1ed92e3ea..80b2424b14cc0 100644 --- a/pkgs/development/compilers/llvm/16/default.nix +++ b/pkgs/development/compilers/llvm/16/default.nix @@ -182,6 +182,9 @@ in let python3 = pkgs.python3; # don't use python-boot }); + # Wrapper for standalone command line utilities + clang-tools = callPackage ../common/clang-tools { }; + # pick clang appropriate for package set we are targeting clang = /**/ if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM diff --git a/pkgs/development/compilers/llvm/17/default.nix b/pkgs/development/compilers/llvm/17/default.nix index af0d648c4fd01..84979d24b1971 100644 --- a/pkgs/development/compilers/llvm/17/default.nix +++ b/pkgs/development/compilers/llvm/17/default.nix @@ -176,6 +176,9 @@ in let python3 = pkgs.python3; # don't use python-boot }); + # Wrapper for standalone command line utilities + clang-tools = callPackage ../common/clang-tools { }; + # pick clang appropriate for package set we are targeting clang = /**/ if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM diff --git a/pkgs/development/compilers/llvm/18/default.nix b/pkgs/development/compilers/llvm/18/default.nix index 4ef9728708385..878f1e3a8e7e4 100644 --- a/pkgs/development/compilers/llvm/18/default.nix +++ b/pkgs/development/compilers/llvm/18/default.nix @@ -176,6 +176,9 @@ in let python3 = pkgs.python3; # don't use python-boot }); + # Wrapper for standalone command line utilities + clang-tools = callPackage ../common/clang-tools { }; + # pick clang appropriate for package set we are targeting clang = /**/ if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM diff --git a/pkgs/development/compilers/llvm/common/clang-tools/default.nix b/pkgs/development/compilers/llvm/common/clang-tools/default.nix new file mode 100644 index 0000000000000..7ecf0c5c431de --- /dev/null +++ b/pkgs/development/compilers/llvm/common/clang-tools/default.nix @@ -0,0 +1,59 @@ +{ + lib, + stdenv, + clang-unwrapped, + clang, + libcxxClang, + llvm_meta, + # enableLibcxx will use the c++ headers from clang instead of gcc. + # This shouldn't have any effect on platforms that use clang as the default compiler already. + enableLibcxx ? false, +}: + +stdenv.mkDerivation { + unwrapped = clang-unwrapped; + + pname = "clang-tools"; + version = lib.getVersion clang-unwrapped; + dontUnpack = true; + clang = if enableLibcxx then libcxxClang else clang; + + installPhase = '' + runHook preInstall + + mkdir -p $out/bin + + for tool in $unwrapped/bin/clang-*; do + tool=$(basename "$tool") + + # Compilers have their own derivation, no need to include them here: + if [[ $tool == "clang-cl" || $tool == "clang-cpp" ]]; then + continue + fi + + # Clang's derivation produces a lot of binaries, but the tools we are + # interested in follow the `clang-something` naming convention - except + # for clang-$version (e.g. clang-13), which is the compiler again: + if [[ ! $tool =~ ^clang\-[a-zA-Z_\-]+$ ]]; then + continue + fi + + ln -s $out/bin/clangd $out/bin/$tool + done + + if [[ -z "$(ls -A $out/bin)" ]]; then + echo "Found no binaries - maybe their location or naming convention changed?" + exit 1 + fi + + substituteAll ${./wrapper} $out/bin/clangd + chmod +x $out/bin/clangd + + runHook postInstall + ''; + + meta = llvm_meta // { + description = "Standalone command line tools for C++ development"; + maintainers = with lib.maintainers; [ patryk27 ]; + }; +} diff --git a/pkgs/development/compilers/llvm/common/clang-tools/wrapper b/pkgs/development/compilers/llvm/common/clang-tools/wrapper new file mode 100755 index 0000000000000..1008023fdc0d1 --- /dev/null +++ b/pkgs/development/compilers/llvm/common/clang-tools/wrapper @@ -0,0 +1,27 @@ +#!/bin/sh + +buildcpath() { + local path after + while (( $# )); do + case $1 in + -isystem) + shift + path=$path${path:+':'}$1 + ;; + -idirafter) + shift + after=$after${after:+':'}$1 + ;; + esac + shift + done + echo $path${after:+':'}$after +} + +export CPATH=${CPATH}${CPATH:+':'}$(buildcpath ${NIX_CFLAGS_COMPILE} \ + $(<@clang@/nix-support/libc-cflags)):@clang@/resource-root/include +export CPLUS_INCLUDE_PATH=${CPLUS_INCLUDE_PATH}${CPLUS_INCLUDE_PATH:+':'}$(buildcpath ${NIX_CFLAGS_COMPILE} \ + $(<@clang@/nix-support/libcxx-cxxflags) \ + $(<@clang@/nix-support/libc-cflags)):@clang@/resource-root/include + +exec -a "$0" @unwrapped@/bin/$(basename $0) "$@" diff --git a/pkgs/development/compilers/llvm/git/default.nix b/pkgs/development/compilers/llvm/git/default.nix index 0e3a0eb7c6967..786bd82fa648c 100644 --- a/pkgs/development/compilers/llvm/git/default.nix +++ b/pkgs/development/compilers/llvm/git/default.nix @@ -181,6 +181,9 @@ in let python3 = pkgs.python3; # don't use python-boot }); + # Wrapper for standalone command line utilities + clang-tools = callPackage ../common/clang-tools { }; + # pick clang appropriate for package set we are targeting clang = /**/ if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM |