2017-02-18 19:53:46 +00:00
|
|
|
{ stdenv
|
|
|
|
, fetch
|
|
|
|
, fetchpatch
|
|
|
|
, perl
|
|
|
|
, groff
|
|
|
|
, cmake
|
|
|
|
, python
|
|
|
|
, libffi
|
|
|
|
, binutils
|
|
|
|
, libxml2
|
|
|
|
, valgrind
|
|
|
|
, ncurses
|
|
|
|
, version
|
2017-02-19 20:33:47 +00:00
|
|
|
, release_version
|
2017-02-18 19:53:46 +00:00
|
|
|
, zlib
|
|
|
|
, compiler-rt_src
|
|
|
|
, libcxxabi
|
|
|
|
, debugVersion ? false
|
2017-06-24 12:11:43 +01:00
|
|
|
, enableManpages ? false
|
2017-02-18 19:53:46 +00:00
|
|
|
, enableSharedLibraries ? true
|
|
|
|
, darwin
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2017-03-13 19:54:39 +00:00
|
|
|
src = fetch "llvm" "1giklnw71wzsgbqg9wb5x7dxnbj39m6zpfvskvzvhwvfz4fm244d";
|
2017-02-18 19:53:46 +00:00
|
|
|
shlib = if stdenv.isDarwin then "dylib" else "so";
|
|
|
|
|
|
|
|
# Used when creating a version-suffixed symlink of libLLVM.dylib
|
|
|
|
shortVersion = with stdenv.lib;
|
2017-02-19 20:33:47 +00:00
|
|
|
concatStringsSep "." (take 2 (splitString "." release_version));
|
2017-02-18 19:53:46 +00:00
|
|
|
in stdenv.mkDerivation rec {
|
|
|
|
name = "llvm-${version}";
|
|
|
|
|
|
|
|
unpackPhase = ''
|
|
|
|
unpackFile ${src}
|
|
|
|
mv llvm-${version}* llvm
|
|
|
|
sourceRoot=$PWD/llvm
|
|
|
|
unpackFile ${compiler-rt_src}
|
|
|
|
mv compiler-rt-* $sourceRoot/projects/compiler-rt
|
|
|
|
'';
|
|
|
|
|
2017-05-31 19:16:13 +01:00
|
|
|
outputs = [ "out" ]
|
2017-06-01 22:23:56 +01:00
|
|
|
++ stdenv.lib.optional enableSharedLibraries "lib"
|
|
|
|
++ stdenv.lib.optional enableManpages "man";
|
2017-05-31 19:16:13 +01:00
|
|
|
|
|
|
|
nativeBuildInputs = [ perl groff cmake python ]
|
|
|
|
++ stdenv.lib.optional enableManpages python.pkgs.sphinx;
|
2017-02-18 19:53:46 +00:00
|
|
|
|
2017-05-19 18:34:39 +01:00
|
|
|
buildInputs = [ libxml2 libffi ]
|
2017-03-18 17:07:52 +00:00
|
|
|
++ stdenv.lib.optionals stdenv.isDarwin [ libcxxabi ];
|
2017-02-18 19:53:46 +00:00
|
|
|
|
|
|
|
propagatedBuildInputs = [ ncurses zlib ];
|
|
|
|
|
2017-03-18 17:07:52 +00:00
|
|
|
# TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks
|
|
|
|
# to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra
|
|
|
|
# can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd
|
|
|
|
# get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by
|
|
|
|
# a flag and turn the flag off during the stdenv build.
|
2017-02-18 19:53:46 +00:00
|
|
|
postPatch = stdenv.lib.optionalString stdenv.isDarwin ''
|
2017-03-18 17:07:52 +00:00
|
|
|
substituteInPlace ./projects/compiler-rt/cmake/config-ix.cmake \
|
|
|
|
--replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)'
|
2017-02-18 19:53:46 +00:00
|
|
|
''
|
|
|
|
# Patch llvm-config to return correct library path based on --link-{shared,static}.
|
|
|
|
+ stdenv.lib.optionalString (enableSharedLibraries) ''
|
|
|
|
substitute '${./llvm-outputs.patch}' ./llvm-outputs.patch --subst-var lib
|
|
|
|
patch -p1 < ./llvm-outputs.patch
|
2017-03-06 14:33:16 +00:00
|
|
|
''
|
|
|
|
# Remove broken tests: (https://bugs.llvm.org//show_bug.cgi?id=31610)
|
|
|
|
+ ''
|
|
|
|
rm test/CodeGen/AMDGPU/invalid-opencl-version-metadata1.ll
|
|
|
|
rm test/CodeGen/AMDGPU/invalid-opencl-version-metadata2.ll
|
|
|
|
rm test/CodeGen/AMDGPU/invalid-opencl-version-metadata3.ll
|
|
|
|
rm test/CodeGen/AMDGPU/runtime-metadata.ll
|
2017-02-18 19:53:46 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
# hacky fix: created binaries need to be run before installation
|
|
|
|
preBuild = ''
|
|
|
|
mkdir -p $out/
|
|
|
|
ln -sv $PWD/lib $out
|
|
|
|
'';
|
|
|
|
|
|
|
|
cmakeFlags = with stdenv; [
|
|
|
|
"-DCMAKE_BUILD_TYPE=${if debugVersion then "Debug" else "Release"}"
|
|
|
|
"-DLLVM_INSTALL_UTILS=ON" # Needed by rustc
|
|
|
|
"-DLLVM_BUILD_TESTS=ON"
|
|
|
|
"-DLLVM_ENABLE_FFI=ON"
|
|
|
|
"-DLLVM_ENABLE_RTTI=ON"
|
|
|
|
"-DCOMPILER_RT_INCLUDE_TESTS=OFF" # FIXME: requires clang source code
|
2017-06-01 22:23:56 +01:00
|
|
|
]
|
|
|
|
++ stdenv.lib.optional enableSharedLibraries
|
|
|
|
"-DLLVM_LINK_LLVM_DYLIB=ON"
|
|
|
|
++ stdenv.lib.optionals enableManpages [
|
2017-05-19 13:26:05 +01:00
|
|
|
"-DLLVM_BUILD_DOCS=ON"
|
|
|
|
"-DLLVM_ENABLE_SPHINX=ON"
|
|
|
|
"-DSPHINX_OUTPUT_MAN=ON"
|
|
|
|
"-DSPHINX_OUTPUT_HTML=OFF"
|
|
|
|
"-DSPHINX_WARNINGS_AS_ERRORS=OFF"
|
2017-06-01 22:23:56 +01:00
|
|
|
]
|
|
|
|
++ stdenv.lib.optional (!isDarwin)
|
2017-02-18 19:53:46 +00:00
|
|
|
"-DLLVM_BINUTILS_INCDIR=${binutils.dev}/include"
|
2017-06-01 22:23:56 +01:00
|
|
|
++ stdenv.lib.optionals (isDarwin) [
|
2017-02-18 19:53:46 +00:00
|
|
|
"-DLLVM_ENABLE_LIBCXX=ON"
|
|
|
|
"-DCAN_TARGET_i386=false"
|
|
|
|
];
|
|
|
|
|
|
|
|
postBuild = ''
|
|
|
|
rm -fR $out
|
|
|
|
|
|
|
|
paxmark m bin/{lli,llvm-rtdyld}
|
2017-03-06 14:33:16 +00:00
|
|
|
paxmark m unittests/ExecutionEngine/MCJIT/MCJITTests
|
|
|
|
paxmark m unittests/ExecutionEngine/Orc/OrcJITTests
|
|
|
|
paxmark m unittests/Support/SupportTests
|
|
|
|
paxmark m bin/lli-child-target
|
|
|
|
'';
|
|
|
|
|
|
|
|
preCheck = ''
|
|
|
|
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/lib
|
2017-02-18 19:53:46 +00:00
|
|
|
'';
|
|
|
|
|
2017-05-31 19:16:13 +01:00
|
|
|
postInstall = stdenv.lib.optionalString enableManpages ''
|
2017-05-19 13:26:05 +01:00
|
|
|
moveToOutput "share/man" "$man"
|
|
|
|
''
|
2017-05-31 19:16:13 +01:00
|
|
|
+ stdenv.lib.optionalString enableSharedLibraries ''
|
2017-02-18 19:53:46 +00:00
|
|
|
moveToOutput "lib/libLLVM-*" "$lib"
|
|
|
|
moveToOutput "lib/libLLVM.${shlib}" "$lib"
|
|
|
|
substituteInPlace "$out/lib/cmake/llvm/LLVMExports-release.cmake" \
|
|
|
|
--replace "\''${_IMPORT_PREFIX}/lib/libLLVM-" "$lib/lib/libLLVM-"
|
|
|
|
''
|
|
|
|
+ stdenv.lib.optionalString (stdenv.isDarwin && enableSharedLibraries) ''
|
|
|
|
substituteInPlace "$out/lib/cmake/llvm/LLVMExports-release.cmake" \
|
|
|
|
--replace "\''${_IMPORT_PREFIX}/lib/libLLVM.dylib" "$lib/lib/libLLVM.dylib"
|
|
|
|
install_name_tool -id $lib/lib/libLLVM.dylib $lib/lib/libLLVM.dylib
|
|
|
|
install_name_tool -change @rpath/libLLVM.dylib $lib/lib/libLLVM.dylib $out/bin/llvm-config
|
|
|
|
ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib
|
2017-02-19 20:33:47 +00:00
|
|
|
ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib
|
2017-02-18 19:53:46 +00:00
|
|
|
'';
|
|
|
|
|
2017-03-06 14:33:16 +00:00
|
|
|
doCheck = stdenv.isLinux;
|
|
|
|
|
|
|
|
checkTarget = "check-all";
|
|
|
|
|
2017-02-18 19:53:46 +00:00
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
|
|
|
passthru.src = src;
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
description = "Collection of modular and reusable compiler and toolchain technologies";
|
|
|
|
homepage = http://llvm.org/;
|
|
|
|
license = stdenv.lib.licenses.ncsa;
|
2017-03-02 22:25:07 +00:00
|
|
|
maintainers = with stdenv.lib.maintainers; [ lovek323 raskin viric dtzWill ];
|
2017-02-18 19:53:46 +00:00
|
|
|
platforms = stdenv.lib.platforms.all;
|
|
|
|
};
|
|
|
|
}
|