16 unwrapped = stdenv.mkDerivation rec {
17 pname = "cling-unwrapped";
21 url = "http://root.cern/git/clang.git";
22 # This commit has the tag cling-0.7 so we use it, even though cpt.py
23 # tries to use refs/tags/cling-patches-rrelease_50
24 rev = "354b25b5d915ff3b1946479ad07f3f2768ea1621";
25 branchName = "cling-patches";
26 sha256 = "0q8q2nnvjx3v59ng0q3qqqhzmzf4pmfqqiy3rz1f3drx5w3lgyjg";
30 url = "http://root.cern/git/cling.git";
31 rev = "70163975eee5a76b45a1ca4016bfafebc9b57e07";
32 sha256 = "1mv2fhk857kp5rq714bq49iv7gy9fgdwibydj5wy1kq2m3sf3ysi";
36 echo "add_llvm_external_project(cling)" >> tools/CMakeLists.txt
37 cp -r $clingSrc ./tools/cling
38 chmod -R a+w ./tools/cling
41 nativeBuildInputs = [ python3 git cmake llvmPackages_5.llvm.dev ];
42 buildInputs = [ libffi llvmPackages_5.llvm zlib ncurses ];
47 "-DLLVM_TARGETS_TO_BUILD=host;NVPTX"
48 "-DLLVM_ENABLE_RTTI=ON"
50 # Setting -DCLING_INCLUDE_TESTS=ON causes the cling/tools targets to be built;
51 # see cling/tools/CMakeLists.txt
52 "-DCLING_INCLUDE_TESTS=ON"
56 description = "The Interactive C++ Interpreter";
57 homepage = "https://root.cern/cling/";
58 license = with licenses; [ lgpl21 ncsa ];
59 maintainers = with maintainers; [ thomasjm ];
60 platforms = platforms.unix;
64 # The flags passed to the wrapped cling should
65 # a) prevent it from searching for system include files and libs, and
66 # b) provide it with the include files and libs it needs (C and C++ standard library)
68 # These are also exposed as cling.flags/cling.compilerIncludeFlags because it's handy to be
69 # able to pass them to tools that wrap Cling, particularly Jupyter kernels such as xeus-cling
70 # and the built-in jupyter-cling-kernel. Both of these use Cling as a library by linking against
71 # libclingJupyter.so, so the makeWrapper approach to wrapping the binary doesn't work.
72 # Thus, if you're packaging a Jupyter kernel, you either need to pass these flags as extra
73 # args to xcpp (for xeus-cling) or put them in the environment variable CLING_OPTS
74 # (for jupyter-cling-kernel)
78 "-isystem" "${lib.getDev stdenv.cc.libc}/include"
79 "-I" "${lib.getDev unwrapped}/include"
80 "-I" "${lib.getLib unwrapped}/lib/clang/5.0.2/include"
83 # Autodetect the include paths for the compiler used to build Cling, in the same way Cling does at
84 # https://github.com/root-project/cling/blob/v0.7/lib/Interpreter/CIFactory.cpp#L107:L111
85 # Note: it would be nice to just put the compiler in Cling's PATH and let it do this by itself, but
86 # unfortunately passing -nostdinc/-nostdinc++ disables Cling's autodetection logic.
87 compilerIncludeFlags = runCommand "compiler-include-flags.txt" {} ''
89 ${stdenv.cc}/bin/c++ -xc++ -E -v /dev/null 2>&1 | sed -n -e '/^.include/,''${' -e '/^ \/.*++/p' -e '}' > tmp
90 sed -e 's/^/-isystem /' -i tmp
91 tr '\n' ' ' < tmp > $out
96 runCommand "cling-${unwrapped.version}" {
97 nativeBuildInputs = [ makeWrapper ];
98 inherit unwrapped flags compilerIncludeFlags;
99 inherit (unwrapped) meta;
101 makeWrapper $unwrapped/bin/cling $out/bin/cling \
102 --add-flags "$(cat "$compilerIncludeFlags")" \