nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at netboot-syslinux-multiplatform 128 lines 4.0 kB view raw
1{ lib, stdenv, llvm_meta 2, monorepoSrc, runCommand 3, substituteAll, cmake, 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 python3 ] 24 ++ lib.optional enableManpages python3.pkgs.sphinx 25 ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; 26 27 buildInputs = [ libxml2 libllvm ]; 28 29 cmakeFlags = [ 30 "-DCLANGD_BUILD_XPC=OFF" 31 "-DLLVM_ENABLE_RTTI=ON" 32 ] ++ lib.optionals enableManpages [ 33 "-DCLANG_INCLUDE_DOCS=ON" 34 "-DLLVM_ENABLE_SPHINX=ON" 35 "-DSPHINX_OUTPUT_MAN=ON" 36 "-DSPHINX_OUTPUT_HTML=OFF" 37 "-DSPHINX_WARNINGS_AS_ERRORS=OFF" 38 ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ 39 "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" 40 "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" 41 ]; 42 43 patches = [ 44 ./purity.patch 45 # https://reviews.llvm.org/D51899 46 ./gnu-install-dirs.patch 47 ../../common/clang/add-nostdlibinc-flag.patch 48 (substituteAll { 49 src = ../../clang-11-12-LLVMgold-path.patch; 50 libllvmLibdir = "${libllvm.lib}/lib"; 51 }) 52 ]; 53 54 postPatch = '' 55 (cd tools && ln -s ../../clang-tools-extra extra) 56 '' + lib.optionalString stdenv.hostPlatform.isMusl '' 57 sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp 58 ''; 59 60 outputs = [ "out" "lib" "dev" "python" ]; 61 62 postInstall = '' 63 ln -sv $out/bin/clang $out/bin/cpp 64 65 # Move libclang to 'lib' output 66 moveToOutput "lib/libclang.*" "$lib" 67 moveToOutput "lib/libclang-cpp.*" "$lib" 68 substituteInPlace $out/lib/cmake/clang/ClangTargets-release.cmake \ 69 --replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." \ 70 --replace "\''${_IMPORT_PREFIX}/lib/libclang-cpp." "$lib/lib/libclang-cpp." 71 72 mkdir -p $python/bin $python/share/clang/ 73 mv $out/bin/{git-clang-format,scan-view} $python/bin 74 if [ -e $out/bin/set-xcode-analyzer ]; then 75 mv $out/bin/set-xcode-analyzer $python/bin 76 fi 77 mv $out/share/clang/*.py $python/share/clang 78 rm $out/bin/c-index-test 79 patchShebangs $python/bin 80 81 mkdir -p $dev/bin 82 cp bin/clang-tblgen $dev/bin 83 ''; 84 85 passthru = { 86 inherit libllvm; 87 isClang = true; 88 hardeningUnsupportedFlags = [ "fortify3" ]; 89 }; 90 91 meta = llvm_meta // { 92 homepage = "https://clang.llvm.org/"; 93 description = "A C language family frontend for LLVM"; 94 longDescription = '' 95 The Clang project provides a language front-end and tooling 96 infrastructure for languages in the C language family (C, C++, Objective 97 C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. 98 It aims to deliver amazingly fast compiles, extremely useful error and 99 warning messages and to provide a platform for building great source 100 level tools. The Clang Static Analyzer and clang-tidy are tools that 101 automatically find bugs in your code, and are great examples of the sort 102 of tools that can be built using the Clang frontend as a library to 103 parse C/C++ code. 104 ''; 105 mainProgram = "clang"; 106 }; 107 } // lib.optionalAttrs enableManpages { 108 pname = "clang-manpages"; 109 110 buildPhase = '' 111 make docs-clang-man 112 ''; 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