summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom McLaughlin <tom@codedown.io>2020-11-19 12:29:02 -0700
committerGitHub <noreply@github.com>2020-11-19 14:29:02 -0500
commitc81c3c3daff4a96980da2fce2d80a9e57f9db953 (patch)
tree89659093133fa8ae665693064080fd40e97d4952
parent93b430bc6ba3c084d66f96546dd7b95a2835eceb (diff)
cling: init at 0.7.0 (#64319)
Co-authored-by: Dmitry Kalinkin <dmitry.kalinkin@gmail.com>
-rw-r--r--pkgs/development/interpreters/cling/default.nix102
-rw-r--r--pkgs/top-level/all-packages.nix2
2 files changed, 104 insertions, 0 deletions
diff --git a/pkgs/development/interpreters/cling/default.nix b/pkgs/development/interpreters/cling/default.nix
new file mode 100644
index 000000000000..68819fa7ab06
--- /dev/null
+++ b/pkgs/development/interpreters/cling/default.nix
@@ -0,0 +1,102 @@
+{ stdenv
+, python
+, libffi
+, git
+, cmake
+, zlib
+, fetchgit
+, makeWrapper
+, runCommand
+, runCommandNoCC
+, llvmPackages_5
+, glibc
+}:
+
+let
+ unwrapped = stdenv.mkDerivation rec {
+ pname = "cling-unwrapped";
+ version = "0.7";
+
+ src = fetchgit {
+ url = "http://root.cern/git/clang.git";
+ # This commit has the tag cling-0.7 so we use it, even though cpt.py
+ # tries to use refs/tags/cling-patches-rrelease_50
+ rev = "354b25b5d915ff3b1946479ad07f3f2768ea1621";
+ branchName = "cling-patches";
+ sha256 = "0q8q2nnvjx3v59ng0q3qqqhzmzf4pmfqqiy3rz1f3drx5w3lgyjg";
+ };
+
+ clingSrc = fetchgit {
+ url = "http://root.cern/git/cling.git";
+ rev = "70163975eee5a76b45a1ca4016bfafebc9b57e07";
+ sha256 = "1mv2fhk857kp5rq714bq49iv7gy9fgdwibydj5wy1kq2m3sf3ysi";
+ };
+
+ preConfigure = ''
+ echo "add_llvm_external_project(cling)" >> tools/CMakeLists.txt
+ cp -r $clingSrc ./tools/cling
+ chmod -R a+w ./tools/cling
+ '';
+
+ nativeBuildInputs = [ python git cmake ];
+ buildInputs = [ libffi llvmPackages_5.llvm zlib ];
+
+ cmakeFlags = [
+ "-DLLVM_TARGETS_TO_BUILD=host;NVPTX"
+ "-DLLVM_ENABLE_RTTI=ON"
+
+ # Setting -DCLING_INCLUDE_TESTS=ON causes the cling/tools targets to be built;
+ # see cling/tools/CMakeLists.txt
+ "-DCLING_INCLUDE_TESTS=ON"
+ ];
+
+ meta = with stdenv.lib; {
+ description = "The Interactive C++ Interpreter";
+ homepage = "https://root.cern/cling/";
+ license = with licenses; [ lgpl21 ncsa ];
+ maintainers = with maintainers; [ thomasjm ];
+ platforms = platforms.unix;
+ };
+ };
+
+ # The flags passed to the wrapped cling should
+ # a) prevent it from searching for system include files and libs, and
+ # b) provide it with the include files and libs it needs (C and C++ standard library)
+
+ # These are also exposed as cling.flags/cling.compilerIncludeFlags because it's handy to be
+ # able to pass them to tools that wrap Cling, particularly Jupyter kernels such as xeus-cling
+ # and the built-in jupyter-cling-kernel. Both of these use Cling as a library by linking against
+ # libclingJupyter.so, so the makeWrapper approach to wrapping the binary doesn't work.
+ # Thus, if you're packaging a Jupyter kernel, you either need to pass these flags as extra
+ # args to xcpp (for xeus-cling) or put them in the environment variable CLING_OPTS
+ # (for jupyter-cling-kernel)
+ flags = [
+ "-nostdinc"
+ "-nostdinc++"
+ "-isystem" "${glibc.dev}/include"
+ "-I" "${unwrapped}/include"
+ "-I" "${unwrapped}/lib/clang/5.0.2/include"
+ ];
+
+ # Autodetect the include paths for the compiler used to build Cling, in the same way Cling does at
+ # https://github.com/root-project/cling/blob/v0.7/lib/Interpreter/CIFactory.cpp#L107:L111
+ # Note: it would be nice to just put the compiler in Cling's PATH and let it do this by itself, but
+ # unfortunately passing -nostdinc/-nostdinc++ disables Cling's autodetection logic.
+ compilerIncludeFlags = runCommandNoCC "compiler-include-flags.txt" {} ''
+ export LC_ALL=C
+ ${stdenv.cc}/bin/c++ -xc++ -E -v /dev/null 2>&1 | sed -n -e '/^.include/,''${' -e '/^ \/.*++/p' -e '}' > tmp
+ sed -e 's/^/-isystem /' -i tmp
+ tr '\n' ' ' < tmp > $out
+ '';
+
+in
+
+runCommand "cling-${unwrapped.version}" {
+ buildInputs = [ makeWrapper ];
+ inherit unwrapped flags compilerIncludeFlags;
+ inherit (unwrapped) meta;
+} ''
+ makeWrapper $unwrapped/bin/cling $out/bin/cling \
+ --add-flags "$(cat "$compilerIncludeFlags")" \
+ --add-flags "$flags"
+''
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 8c96a8b961a2..0d9893de7fe1 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -10190,6 +10190,8 @@ in
ceptre = callPackage ../development/interpreters/ceptre { };
+ cling = callPackage ../development/interpreters/cling { };
+
clips = callPackage ../development/interpreters/clips { };
clisp = callPackage ../development/interpreters/clisp { };