nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at netboot-syslinux-multiplatform 128 lines 4.1 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.hostPlatform != stdenv.buildPlatform) [ 40 "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" 41 "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" 42 ]; 43 44 patches = [ 45 ./purity.patch 46 # https://reviews.llvm.org/D51899 47 ./gnu-install-dirs.patch 48 ../../common/clang/add-nostdlibinc-flag.patch 49 # FIMXE: do we need this patch? 50 # (substituteAll { 51 # src = ../../clang-11-12-LLVMgold-path.patch; 52 # libllvmLibdir = "${libllvm.lib}/lib"; 53 # }) 54 ]; 55 56 postPatch = '' 57 (cd tools && ln -s ../../clang-tools-extra extra) 58 '' + lib.optionalString stdenv.hostPlatform.isMusl '' 59 sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp 60 ''; 61 62 outputs = [ "out" "lib" "dev" "python" ]; 63 64 postInstall = '' 65 ln -sv $out/bin/clang $out/bin/cpp 66 67 # Move libclang to 'lib' output 68 moveToOutput "lib/libclang.*" "$lib" 69 moveToOutput "lib/libclang-cpp.*" "$lib" 70 substituteInPlace $dev/lib/cmake/clang/ClangTargets-release.cmake \ 71 --replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." \ 72 --replace "\''${_IMPORT_PREFIX}/lib/libclang-cpp." "$lib/lib/libclang-cpp." 73 74 mkdir -p $python/bin $python/share/clang/ 75 mv $out/bin/{git-clang-format,scan-view} $python/bin 76 if [ -e $out/bin/set-xcode-analyzer ]; then 77 mv $out/bin/set-xcode-analyzer $python/bin 78 fi 79 mv $out/share/clang/*.py $python/share/clang 80 rm $out/bin/c-index-test 81 patchShebangs $python/bin 82 83 mkdir -p $dev/bin 84 cp bin/clang-tblgen $dev/bin 85 ''; 86 87 passthru = { 88 inherit libllvm; 89 isClang = true; 90 hardeningUnsupportedFlags = [ "fortify3" ]; 91 }; 92 93 meta = llvm_meta // { 94 homepage = "https://clang.llvm.org/"; 95 description = "A C language family frontend for LLVM"; 96 longDescription = '' 97 The Clang project provides a language front-end and tooling 98 infrastructure for languages in the C language family (C, C++, Objective 99 C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. 100 It aims to deliver amazingly fast compiles, extremely useful error and 101 warning messages and to provide a platform for building great source 102 level tools. The Clang Static Analyzer and clang-tidy are tools that 103 automatically find bugs in your code, and are great examples of the sort 104 of tools that can be built using the Clang frontend as a library to 105 parse C/C++ code. 106 ''; 107 mainProgram = "clang"; 108 }; 109 } // lib.optionalAttrs enableManpages { 110 pname = "clang-manpages"; 111 112 ninjaFlags = [ "docs-clang-man" ]; 113 114 installPhase = '' 115 mkdir -p $out/share/man/man1 116 # Manually install clang manpage 117 cp docs/man/*.1 $out/share/man/man1/ 118 ''; 119 120 outputs = [ "out" ]; 121 122 doCheck = false; 123 124 meta = llvm_meta // { 125 description = "man page for Clang ${version}"; 126 }; 127 }); 128in self