lol
at 23.11-beta 171 lines 5.1 kB view raw
1{ cmake 2, fetchFromGitHub 3, fetchgit 4, git 5, lib 6, libffi 7, llvmPackages_9 8, makeWrapper 9, ncurses 10, python3 11, runCommand 12, zlib 13 14# *NOT* from LLVM 9! 15# The compiler used to compile Cling may affect the runtime include and lib 16# directories it expects to be run with. Cling builds against (a fork of) Clang, 17# so we prefer to use Clang as the compiler as well for consistency. 18# It would be cleanest to use LLVM 9's clang, but it errors. So, we use a later 19# version of Clang to compile, but we check out the Cling fork of Clang 9 to 20# build Cling against. 21, clangStdenv 22 23# For runtime C++ standard library 24, gcc-unwrapped 25 26# Build with debug symbols 27, debug ? false 28 29# Build with libc++ (LLVM) rather than stdlibc++ (GCC). 30# This is experimental and not all features work. 31, useLLVMLibcxx ? false 32}: 33 34let 35 stdenv = clangStdenv; 36 37 # The LLVM 9 headers have a couple bugs we need to patch 38 fixedLlvmDev = runCommand "llvm-dev-${llvmPackages_9.llvm.version}" { buildInputs = [git]; } '' 39 mkdir $out 40 cp -r ${llvmPackages_9.llvm.dev}/include $out 41 cd $out 42 chmod -R u+w include 43 git apply ${./fix-llvm-include.patch} 44 ''; 45 46 unwrapped = stdenv.mkDerivation rec { 47 pname = "cling-unwrapped"; 48 version = "0.9"; 49 50 src = fetchgit { 51 url = "http://root.cern/git/clang.git"; 52 rev = "cling-v0.9"; 53 sha256 = "sha256-ft1NUIclSiZ9lN3Z3DJCWA0U9q/K1M0TKkZr+PjsFYk="; 54 }; 55 56 clingSrc = fetchFromGitHub { 57 owner = "root-project"; 58 repo = "cling"; 59 rev = "v0.9"; 60 sha256 = "0wx3fi19wfjcph5kclf8108i436y79ddwakrcf0lgxnnxhdjyd29"; 61 }; 62 63 prePatch = '' 64 echo "add_llvm_external_project(cling)" >> tools/CMakeLists.txt 65 66 cp -r $clingSrc ./tools/cling 67 chmod -R a+w ./tools/cling 68 ''; 69 70 patches = [ 71 ./no-clang-cpp.patch 72 73 # https://github.com/root-project/root/commit/286d96b12aad8688b9d8e4b3b5df843dcfb716a8 74 ./fix-llvm-dylib-usage.patch 75 76 ./force-install-cling-targets.patch 77 ]; 78 79 nativeBuildInputs = [ python3 git cmake ]; 80 buildInputs = [ libffi ncurses zlib ]; 81 82 strictDeps = true; 83 84 cmakeFlags = [ 85 "-DLLVM_BINARY_DIR=${llvmPackages_9.llvm.out}" 86 "-DLLVM_CONFIG=${llvmPackages_9.llvm.dev}/bin/llvm-config" 87 "-DLLVM_LIBRARY_DIR=${llvmPackages_9.llvm.lib}/lib" 88 "-DLLVM_MAIN_INCLUDE_DIR=${fixedLlvmDev}/include" 89 "-DLLVM_TABLEGEN_EXE=${llvmPackages_9.llvm.out}/bin/llvm-tblgen" 90 "-DLLVM_TOOLS_BINARY_DIR=${llvmPackages_9.llvm.out}/bin" 91 "-DLLVM_BUILD_TOOLS=Off" 92 "-DLLVM_TOOL_CLING_BUILD=ON" 93 94 "-DLLVM_TARGETS_TO_BUILD=host;NVPTX" 95 "-DLLVM_ENABLE_RTTI=ON" 96 97 # Setting -DCLING_INCLUDE_TESTS=ON causes the cling/tools targets to be built; 98 # see cling/tools/CMakeLists.txt 99 "-DCLING_INCLUDE_TESTS=ON" 100 "-DCLANG-TOOLS=OFF" 101 ] ++ lib.optionals debug [ 102 "-DCMAKE_BUILD_TYPE=Debug" 103 ] ++ lib.optionals useLLVMLibcxx [ 104 "-DLLVM_ENABLE_LIBCXX=ON" 105 "-DLLVM_ENABLE_LIBCXXABI=ON" 106 ]; 107 108 CPPFLAGS = if useLLVMLibcxx then [ "-stdlib=libc++" ] else []; 109 110 postInstall = lib.optionalString (!stdenv.isDarwin) '' 111 mkdir -p $out/share/Jupyter 112 cp -r /build/clang/tools/cling/tools/Jupyter/kernel $out/share/Jupyter 113 ''; 114 115 dontStrip = debug; 116 117 meta = with lib; { 118 description = "The Interactive C++ Interpreter"; 119 homepage = "https://root.cern/cling/"; 120 license = with licenses; [ lgpl21 ncsa ]; 121 maintainers = with maintainers; [ thomasjm ]; 122 platforms = platforms.unix; 123 }; 124 }; 125 126 # Runtime flags for the C++ standard library 127 cxxFlags = if useLLVMLibcxx then [ 128 "-I" "${lib.getDev llvmPackages_9.libcxx}/include/c++/v1" 129 "-L" "${llvmPackages_9.libcxx}/lib" 130 "-l" "${llvmPackages_9.libcxx}/lib/libc++.so" 131 ] else [ 132 "-I" "${gcc-unwrapped}/include/c++/${gcc-unwrapped.version}" 133 "-I" "${gcc-unwrapped}/include/c++/${gcc-unwrapped.version}/x86_64-unknown-linux-gnu" 134 ]; 135 136 # The flags passed to the wrapped cling should 137 # a) prevent it from searching for system include files and libs, and 138 # b) provide it with the include files and libs it needs (C and C++ standard library plus 139 # its own stuff) 140 141 # These are also exposed as cling.flags because it's handy to be able to pass them to tools 142 # that wrap Cling, particularly Jupyter kernels such as xeus-cling and the built-in 143 # jupyter-cling-kernel, which use Cling as a library. 144 # Thus, if you're packaging a Jupyter kernel, you either need to pass these flags as extra 145 # args to xcpp (for xeus-cling) or put them in the environment variable CLING_OPTS 146 # (for jupyter-cling-kernel). 147 flags = [ 148 "-nostdinc" 149 "-nostdinc++" 150 151 "-isystem" "${lib.getLib unwrapped}/lib/clang/9.0.1/include" 152 ] 153 ++ cxxFlags 154 ++ [ 155 # System libc 156 "-isystem" "${lib.getDev stdenv.cc.libc}/include" 157 158 # cling includes 159 "-isystem" "${lib.getDev unwrapped}/include" 160 ]; 161 162in 163 164runCommand "cling-${unwrapped.version}" { 165 nativeBuildInputs = [ makeWrapper ]; 166 inherit unwrapped flags; 167 inherit (unwrapped) meta; 168} '' 169 makeWrapper $unwrapped/bin/cling $out/bin/cling \ 170 --add-flags "$flags" 171''