1{
2 lib,
3 stdenv,
4 clang-unwrapped,
5 clang,
6 libcxxClang,
7 llvm_meta,
8 # enableLibcxx will use the c++ headers from clang instead of gcc.
9 # This shouldn't have any effect on platforms that use clang as the default compiler already.
10 enableLibcxx ? false,
11}:
12
13stdenv.mkDerivation {
14 unwrapped = clang-unwrapped;
15
16 pname = "clang-tools";
17 version = lib.getVersion clang-unwrapped;
18 dontUnpack = true;
19 clang = if enableLibcxx then libcxxClang else clang;
20
21 installPhase = ''
22 runHook preInstall
23
24 mkdir -p $out/bin
25
26 for tool in $unwrapped/bin/clang-*; do
27 tool=$(basename "$tool")
28
29 # Compilers have their own derivation, no need to include them here:
30 if [[ $tool == "clang-cl" || $tool == "clang-cpp" ]]; then
31 continue
32 fi
33
34 # Clang's derivation produces a lot of binaries, but the tools we are
35 # interested in follow the `clang-something` naming convention - except
36 # for clang-$version (e.g. clang-13), which is the compiler again:
37 if [[ ! $tool =~ ^clang\-[a-zA-Z_\-]+$ ]]; then
38 continue
39 fi
40
41 ln -s $out/bin/clangd $out/bin/$tool
42 done
43
44 if [[ -z "$(ls -A $out/bin)" ]]; then
45 echo "Found no binaries - maybe their location or naming convention changed?"
46 exit 1
47 fi
48
49 substituteAll ${./wrapper} $out/bin/clangd
50 chmod +x $out/bin/clangd
51
52 runHook postInstall
53 '';
54
55 meta = llvm_meta // {
56 description = "Standalone command line tools for C++ development";
57 maintainers = with lib.maintainers; [ patryk27 ];
58 };
59}