nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at netboot-syslinux-multiplatform 138 lines 4.9 kB view raw
1{ lib, stdenv, llvm_meta 2, monorepoSrc, runCommand 3, substituteAll, cmake, ninja, libxml2, libllvm, version, python3 4, buildLlvmTools 5, fixDarwinDylibNames 6, enableManpages ? false 7}: 8 9let 10 self = stdenv.mkDerivation (rec { 11 pname = "clang"; 12 inherit version; 13 14 src = runCommand "${pname}-src-${version}" {} '' 15 mkdir -p "$out" 16 cp -r ${monorepoSrc}/cmake "$out" 17 cp -r ${monorepoSrc}/${pname} "$out" 18 cp -r ${monorepoSrc}/clang-tools-extra "$out" 19 ''; 20 21 sourceRoot = "${src.name}/${pname}"; 22 23 nativeBuildInputs = [ cmake ninja python3 ] 24 ++ lib.optional enableManpages python3.pkgs.sphinx 25 ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; 26 27 buildInputs = [ libxml2 libllvm ]; 28 29 cmakeFlags = [ 30 "-DCLANG_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/clang" 31 "-DCLANGD_BUILD_XPC=OFF" 32 "-DLLVM_ENABLE_RTTI=ON" 33 ] ++ lib.optionals enableManpages [ 34 "-DCLANG_INCLUDE_DOCS=ON" 35 "-DLLVM_ENABLE_SPHINX=ON" 36 "-DSPHINX_OUTPUT_MAN=ON" 37 "-DSPHINX_OUTPUT_HTML=OFF" 38 "-DSPHINX_WARNINGS_AS_ERRORS=OFF" 39 ] ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ 40 "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" 41 "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" 42 # Added in LLVM15: 43 # `clang-tidy-confusable-chars-gen`: https://github.com/llvm/llvm-project/commit/c3574ef739fbfcc59d405985a3a4fa6f4619ecdb 44 # `clang-pseudo-gen`: https://github.com/llvm/llvm-project/commit/cd2292ef824591cc34cc299910a3098545c840c7 45 "-DCLANG_TIDY_CONFUSABLE_CHARS_GEN=${buildLlvmTools.libclang.dev}/bin/clang-tidy-confusable-chars-gen" 46 "-DCLANG_PSEUDO_GEN=${buildLlvmTools.libclang.dev}/bin/clang-pseudo-gen" 47 ]; 48 49 patches = [ 50 ./purity.patch 51 # https://reviews.llvm.org/D51899 52 ./gnu-install-dirs.patch 53 ../../common/clang/add-nostdlibinc-flag.patch 54 (substituteAll { 55 src = ../../clang-11-12-LLVMgold-path.patch; 56 libllvmLibdir = "${libllvm.lib}/lib"; 57 }) 58 ]; 59 60 postPatch = '' 61 (cd tools && ln -s ../../clang-tools-extra extra) 62 '' + lib.optionalString stdenv.hostPlatform.isMusl '' 63 sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp 64 ''; 65 66 outputs = [ "out" "lib" "dev" "python" ]; 67 68 env = lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform) { 69 # The following warning is triggered with (at least) gcc >= 70 # 12, but appears to occur only for cross compiles. 71 NIX_CFLAGS_COMPILE = "-Wno-maybe-uninitialized"; 72 }; 73 74 postInstall = '' 75 ln -sv $out/bin/clang $out/bin/cpp 76 77 # Move libclang to 'lib' output 78 moveToOutput "lib/libclang.*" "$lib" 79 moveToOutput "lib/libclang-cpp.*" "$lib" 80 substituteInPlace $dev/lib/cmake/clang/ClangTargets-release.cmake \ 81 --replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." \ 82 --replace "\''${_IMPORT_PREFIX}/lib/libclang-cpp." "$lib/lib/libclang-cpp." 83 84 mkdir -p $python/bin $python/share/clang/ 85 mv $out/bin/{git-clang-format,scan-view} $python/bin 86 if [ -e $out/bin/set-xcode-analyzer ]; then 87 mv $out/bin/set-xcode-analyzer $python/bin 88 fi 89 mv $out/share/clang/*.py $python/share/clang 90 rm $out/bin/c-index-test 91 patchShebangs $python/bin 92 93 mkdir -p $dev/bin 94 cp bin/{clang-tblgen,clang-tidy-confusable-chars-gen,clang-pseudo-gen} $dev/bin 95 ''; 96 97 passthru = { 98 inherit libllvm; 99 isClang = true; 100 hardeningUnsupportedFlags = [ "fortify3" ]; 101 }; 102 103 meta = llvm_meta // { 104 homepage = "https://clang.llvm.org/"; 105 description = "A C language family frontend for LLVM"; 106 longDescription = '' 107 The Clang project provides a language front-end and tooling 108 infrastructure for languages in the C language family (C, C++, Objective 109 C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. 110 It aims to deliver amazingly fast compiles, extremely useful error and 111 warning messages and to provide a platform for building great source 112 level tools. The Clang Static Analyzer and clang-tidy are tools that 113 automatically find bugs in your code, and are great examples of the sort 114 of tools that can be built using the Clang frontend as a library to 115 parse C/C++ code. 116 ''; 117 mainProgram = "clang"; 118 }; 119 } // lib.optionalAttrs enableManpages { 120 pname = "clang-manpages"; 121 122 ninjaFlags = [ "docs-clang-man" ]; 123 124 installPhase = '' 125 mkdir -p $out/share/man/man1 126 # Manually install clang manpage 127 cp docs/man/*.1 $out/share/man/man1/ 128 ''; 129 130 outputs = [ "out" ]; 131 132 doCheck = false; 133 134 meta = llvm_meta // { 135 description = "man page for Clang ${version}"; 136 }; 137 }); 138in self