nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at 19.03 176 lines 5.9 kB view raw
1{ stdenv 2, fetch 3, fetchpatch 4, cmake 5, python 6, libffi 7, libbfd 8, libxml2 9, ncurses 10, version 11, release_version 12, zlib 13, compiler-rt_src 14, debugVersion ? false 15, enableManpages ? false 16, enableSharedLibraries ? !enableManpages 17}: 18 19let 20 src = fetch "llvm" "0l9bf7kdwhlj0kq1hawpyxhna1062z3h7qcz2y8nfl9dz2qksy6s"; 21 22 # Used when creating a version-suffixed symlink of libLLVM.dylib 23 shortVersion = with stdenv.lib; 24 concatStringsSep "." (take 2 (splitString "." release_version)); 25in stdenv.mkDerivation (rec { 26 name = "llvm-${version}"; 27 28 unpackPhase = '' 29 unpackFile ${src} 30 mv llvm-${version}* llvm 31 sourceRoot=$PWD/llvm 32 unpackFile ${compiler-rt_src} 33 mv compiler-rt-* $sourceRoot/projects/compiler-rt 34 ''; 35 36 outputs = [ "out" ] 37 ++ stdenv.lib.optional enableSharedLibraries "lib"; 38 39 nativeBuildInputs = [ cmake python ] 40 ++ stdenv.lib.optional enableManpages python.pkgs.sphinx; 41 42 buildInputs = [ libxml2 libffi ]; 43 44 propagatedBuildInputs = [ ncurses zlib ]; 45 46 # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks 47 # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra 48 # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd 49 # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by 50 # a flag and turn the flag off during the stdenv build. 51 postPatch = stdenv.lib.optionalString stdenv.isDarwin '' 52 substituteInPlace ./projects/compiler-rt/cmake/config-ix.cmake \ 53 --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' 54 55 substituteInPlace cmake/modules/AddLLVM.cmake \ 56 --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \ 57 --replace 'set(_install_rpath "@loader_path/../lib" ''${extra_libdir})' "" 58 '' 59 # Patch llvm-config to return correct library path based on --link-{shared,static}. 60 + stdenv.lib.optionalString (enableSharedLibraries) '' 61 substitute '${./llvm-outputs.patch}' ./llvm-outputs.patch --subst-var lib 62 patch -p1 < ./llvm-outputs.patch 63 '' 64 + '' 65 ( 66 cd projects/compiler-rt 67 patch -p1 < ${ 68 fetchpatch { 69 name = "sigaltstack.patch"; # for glibc-2.26 70 url = https://github.com/llvm-mirror/compiler-rt/commit/8a5e425a68d.diff; 71 sha256 = "0h4y5vl74qaa7dl54b1fcyqalvlpd8zban2d1jxfkxpzyi7m8ifi"; 72 } 73 } 74 substituteInPlace lib/esan/esan_sideline_linux.cpp \ 75 --replace 'struct sigaltstack' 'stack_t' 76 ) 77 '' + # Fix extra space printed in commandline help sometimes, "- help" 78 '' 79 patch -p1 -i ${./cmdline-help.patch} 80 '' + stdenv.lib.optionalString stdenv.isAarch64 '' 81 patch -p0 < ${../aarch64.patch} 82 '' + stdenv.lib.optionalString stdenv.hostPlatform.isMusl '' 83 patch -p1 -i ${../TLI-musl.patch} 84 patch -p1 -i ${../dynamiclibrary-musl.patch} 85 patch -p1 -i ${./sanitizers-nongnu.patch} -d projects/compiler-rt 86 ''; 87 88 # hacky fix: created binaries need to be run before installation 89 preBuild = '' 90 mkdir -p $out/ 91 ln -sv $PWD/lib $out 92 ''; 93 94 cmakeFlags = with stdenv; [ 95 "-DCMAKE_BUILD_TYPE=${if debugVersion then "Debug" else "Release"}" 96 "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc 97 "-DLLVM_BUILD_TESTS=ON" 98 "-DLLVM_ENABLE_FFI=ON" 99 "-DLLVM_ENABLE_RTTI=ON" 100 "-DCOMPILER_RT_INCLUDE_TESTS=OFF" # FIXME: requires clang source code 101 102 "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" 103 "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.targetPlatform.config}" 104 "-DTARGET_TRIPLE=${stdenv.targetPlatform.config}" 105 ] 106 ++ stdenv.lib.optional enableSharedLibraries 107 "-DLLVM_LINK_LLVM_DYLIB=ON" 108 ++ stdenv.lib.optionals enableManpages [ 109 "-DLLVM_BUILD_DOCS=ON" 110 "-DLLVM_ENABLE_SPHINX=ON" 111 "-DSPHINX_OUTPUT_MAN=ON" 112 "-DSPHINX_OUTPUT_HTML=OFF" 113 "-DSPHINX_WARNINGS_AS_ERRORS=OFF" 114 ] 115 ++ stdenv.lib.optional (!isDarwin) 116 "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" 117 ++ stdenv.lib.optionals (isDarwin) [ 118 "-DLLVM_ENABLE_LIBCXX=ON" 119 "-DCAN_TARGET_i386=false" 120 ]; 121 122 postBuild = '' 123 rm -fR $out 124 ''; 125 126 preCheck = '' 127 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/lib 128 ''; 129 130 postInstall = stdenv.lib.optionalString enableSharedLibraries '' 131 moveToOutput "lib/libLLVM-*" "$lib" 132 moveToOutput "lib/libLLVM${stdenv.hostPlatform.extensions.sharedLibrary}" "$lib" 133 substituteInPlace "$out/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \ 134 --replace "\''${_IMPORT_PREFIX}/lib/libLLVM-" "$lib/lib/libLLVM-" 135 '' 136 + stdenv.lib.optionalString (stdenv.isDarwin && enableSharedLibraries) '' 137 substituteInPlace "$out/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \ 138 --replace "\''${_IMPORT_PREFIX}/lib/libLLVM.dylib" "$lib/lib/libLLVM.dylib" 139 ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib 140 ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib 141 ''; 142 143 doCheck = stdenv.isLinux && (!stdenv.isi686); 144 145 checkTarget = "check-all"; 146 147 enableParallelBuilding = true; 148 149 passthru.src = src; 150 151 meta = { 152 description = "Collection of modular and reusable compiler and toolchain technologies"; 153 homepage = http://llvm.org/; 154 license = stdenv.lib.licenses.ncsa; 155 maintainers = with stdenv.lib.maintainers; [ lovek323 raskin dtzWill ]; 156 platforms = stdenv.lib.platforms.all; 157 }; 158} // stdenv.lib.optionalAttrs enableManpages { 159 name = "llvm-manpages-${version}"; 160 161 buildPhase = '' 162 make docs-llvm-man 163 ''; 164 165 propagatedBuildInputs = [ ]; 166 167 installPhase = '' 168 make -C docs install 169 ''; 170 171 outputs = [ "out" ]; 172 173 doCheck = false; 174 175 meta.description = "man pages for LLVM ${version}"; 176})