2023-08-19 20:19:01 +00:00
|
|
|
{ cmake
|
2022-11-21 00:23:00 +00:00
|
|
|
, fetchFromGitHub
|
2023-08-19 20:19:01 +00:00
|
|
|
, git
|
|
|
|
, lib
|
|
|
|
, libffi
|
2024-04-09 04:37:04 +00:00
|
|
|
, llvmPackages_13
|
2023-08-19 20:19:01 +00:00
|
|
|
, makeWrapper
|
2021-05-08 22:58:11 +00:00
|
|
|
, ncurses
|
2023-08-19 20:19:01 +00:00
|
|
|
, python3
|
|
|
|
, runCommand
|
|
|
|
, zlib
|
|
|
|
|
|
|
|
# *NOT* from LLVM 9!
|
|
|
|
# The compiler used to compile Cling may affect the runtime include and lib
|
|
|
|
# directories it expects to be run with. Cling builds against (a fork of) Clang,
|
|
|
|
# so we prefer to use Clang as the compiler as well for consistency.
|
|
|
|
# It would be cleanest to use LLVM 9's clang, but it errors. So, we use a later
|
|
|
|
# version of Clang to compile, but we check out the Cling fork of Clang 9 to
|
|
|
|
# build Cling against.
|
|
|
|
, clangStdenv
|
|
|
|
|
|
|
|
# For runtime C++ standard library
|
|
|
|
, gcc-unwrapped
|
|
|
|
|
|
|
|
# Build with debug symbols
|
|
|
|
, debug ? false
|
|
|
|
|
|
|
|
# Build with libc++ (LLVM) rather than stdlibc++ (GCC).
|
|
|
|
# This is experimental and not all features work.
|
2024-04-09 04:41:52 +00:00
|
|
|
, useLLVMLibcxx ? clangStdenv.isDarwin
|
2020-11-19 19:29:02 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2023-08-19 20:19:01 +00:00
|
|
|
stdenv = clangStdenv;
|
|
|
|
|
2024-04-09 04:37:04 +00:00
|
|
|
# The patched clang lives in the LLVM megarepo
|
|
|
|
clangSrc = fetchFromGitHub {
|
|
|
|
owner = "root-project";
|
|
|
|
repo = "llvm-project";
|
|
|
|
# cling-llvm13 branch
|
|
|
|
rev = "3610201fbe0352a63efb5cb45f4ea4987702c735";
|
|
|
|
sha256 = "sha256-Cb7BvV7yobG+mkaYe7zD2KcnPvm8/vmVATNWssklXyk=";
|
|
|
|
sparseCheckout = ["clang"];
|
|
|
|
};
|
2023-04-15 09:45:35 +00:00
|
|
|
|
2020-11-19 19:29:02 +00:00
|
|
|
unwrapped = stdenv.mkDerivation rec {
|
|
|
|
pname = "cling-unwrapped";
|
2024-04-09 04:37:04 +00:00
|
|
|
version = "1.0";
|
2020-11-19 19:29:02 +00:00
|
|
|
|
2024-04-09 04:37:04 +00:00
|
|
|
src = "${clangSrc}/clang";
|
2020-11-19 19:29:02 +00:00
|
|
|
|
2022-11-21 00:23:00 +00:00
|
|
|
clingSrc = fetchFromGitHub {
|
|
|
|
owner = "root-project";
|
|
|
|
repo = "cling";
|
2024-04-09 04:41:04 +00:00
|
|
|
rev = "v${version}";
|
2024-04-09 04:37:04 +00:00
|
|
|
sha256 = "sha256-Ye8EINzt+dyNvUIRydACXzb/xEPLm0YSkz08Xxw3xp4=";
|
2020-11-19 19:29:02 +00:00
|
|
|
};
|
2022-11-22 23:11:46 +00:00
|
|
|
|
|
|
|
prePatch = ''
|
2020-11-19 19:29:02 +00:00
|
|
|
echo "add_llvm_external_project(cling)" >> tools/CMakeLists.txt
|
2022-11-22 23:11:46 +00:00
|
|
|
|
2024-04-09 04:37:04 +00:00
|
|
|
cp -r $clingSrc tools/cling
|
|
|
|
chmod -R a+w tools/cling
|
2022-11-22 23:11:46 +00:00
|
|
|
'';
|
2020-11-19 19:29:02 +00:00
|
|
|
|
2022-11-22 05:37:41 +00:00
|
|
|
patches = [
|
|
|
|
./no-clang-cpp.patch
|
|
|
|
];
|
|
|
|
|
2023-04-15 09:45:35 +00:00
|
|
|
nativeBuildInputs = [ python3 git cmake ];
|
2023-08-19 20:19:01 +00:00
|
|
|
buildInputs = [ libffi ncurses zlib ];
|
2022-11-22 23:11:46 +00:00
|
|
|
|
2021-03-25 11:00:51 +00:00
|
|
|
strictDeps = true;
|
|
|
|
|
2020-11-19 19:29:02 +00:00
|
|
|
cmakeFlags = [
|
2024-04-09 04:37:04 +00:00
|
|
|
"-DLLVM_BINARY_DIR=${llvmPackages_13.llvm.out}"
|
|
|
|
"-DLLVM_CONFIG=${llvmPackages_13.llvm.dev}/bin/llvm-config"
|
|
|
|
"-DLLVM_LIBRARY_DIR=${llvmPackages_13.llvm.lib}/lib"
|
|
|
|
"-DLLVM_MAIN_INCLUDE_DIR=${llvmPackages_13.llvm.dev}/include"
|
|
|
|
"-DLLVM_TABLEGEN_EXE=${llvmPackages_13.llvm.out}/bin/llvm-tblgen"
|
|
|
|
"-DLLVM_TOOLS_BINARY_DIR=${llvmPackages_13.llvm.out}/bin"
|
2023-08-19 20:19:01 +00:00
|
|
|
"-DLLVM_BUILD_TOOLS=Off"
|
2023-04-15 09:45:35 +00:00
|
|
|
"-DLLVM_TOOL_CLING_BUILD=ON"
|
|
|
|
|
2020-11-19 19:29:02 +00:00
|
|
|
"-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"
|
2022-11-22 05:37:41 +00:00
|
|
|
"-DCLANG-TOOLS=OFF"
|
2023-08-19 20:19:01 +00:00
|
|
|
] ++ lib.optionals debug [
|
|
|
|
"-DCMAKE_BUILD_TYPE=Debug"
|
|
|
|
] ++ lib.optionals useLLVMLibcxx [
|
|
|
|
"-DLLVM_ENABLE_LIBCXX=ON"
|
|
|
|
"-DLLVM_ENABLE_LIBCXXABI=ON"
|
2020-11-19 19:29:02 +00:00
|
|
|
];
|
|
|
|
|
2023-08-19 20:19:01 +00:00
|
|
|
CPPFLAGS = if useLLVMLibcxx then [ "-stdlib=libc++" ] else [];
|
|
|
|
|
2023-05-09 10:00:43 +00:00
|
|
|
postInstall = lib.optionalString (!stdenv.isDarwin) ''
|
2023-04-19 00:01:10 +00:00
|
|
|
mkdir -p $out/share/Jupyter
|
|
|
|
cp -r /build/clang/tools/cling/tools/Jupyter/kernel $out/share/Jupyter
|
|
|
|
'';
|
|
|
|
|
2023-08-19 20:19:01 +00:00
|
|
|
dontStrip = debug;
|
|
|
|
|
2021-01-23 13:15:07 +00:00
|
|
|
meta = with lib; {
|
2020-11-19 19:29:02 +00:00
|
|
|
description = "Interactive C++ Interpreter";
|
2024-03-19 02:14:51 +00:00
|
|
|
mainProgram = "cling";
|
2020-11-19 19:29:02 +00:00
|
|
|
homepage = "https://root.cern/cling/";
|
|
|
|
license = with licenses; [ lgpl21 ncsa ];
|
|
|
|
maintainers = with maintainers; [ thomasjm ];
|
|
|
|
platforms = platforms.unix;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-08-19 20:19:01 +00:00
|
|
|
# Runtime flags for the C++ standard library
|
|
|
|
cxxFlags = if useLLVMLibcxx then [
|
2024-04-09 04:37:04 +00:00
|
|
|
"-I" "${lib.getDev llvmPackages_13.libcxx}/include/c++/v1"
|
|
|
|
"-L" "${llvmPackages_13.libcxx}/lib"
|
2024-04-09 04:41:52 +00:00
|
|
|
"-l" "${llvmPackages_13.libcxx}/lib/libc++${stdenv.hostPlatform.extensions.sharedLibrary}"
|
2023-08-19 20:19:01 +00:00
|
|
|
] else [
|
|
|
|
"-I" "${gcc-unwrapped}/include/c++/${gcc-unwrapped.version}"
|
2024-04-09 04:41:44 +00:00
|
|
|
"-I" "${gcc-unwrapped}/include/c++/${gcc-unwrapped.version}/${stdenv.hostPlatform.config}"
|
2023-08-19 20:19:01 +00:00
|
|
|
];
|
|
|
|
|
2020-11-19 19:29:02 +00:00
|
|
|
# The flags passed to the wrapped cling should
|
|
|
|
# a) prevent it from searching for system include files and libs, and
|
2023-08-19 20:19:01 +00:00
|
|
|
# b) provide it with the include files and libs it needs (C and C++ standard library plus
|
|
|
|
# its own stuff)
|
2020-11-19 19:29:02 +00:00
|
|
|
|
2023-08-19 20:19:01 +00:00
|
|
|
# These are also exposed as cling.flags 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, which use Cling as a library.
|
2020-11-19 19:29:02 +00:00
|
|
|
# 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
|
2023-08-19 20:19:01 +00:00
|
|
|
# (for jupyter-cling-kernel).
|
2020-11-19 19:29:02 +00:00
|
|
|
flags = [
|
|
|
|
"-nostdinc"
|
|
|
|
"-nostdinc++"
|
2023-08-19 20:19:01 +00:00
|
|
|
|
2024-04-09 04:37:04 +00:00
|
|
|
"-resource-dir" "${llvmPackages_13.llvm.lib}/lib"
|
|
|
|
|
|
|
|
"-isystem" "${lib.getLib unwrapped}/lib/clang/${llvmPackages_13.clang.version}/include"
|
2023-08-19 20:19:01 +00:00
|
|
|
]
|
|
|
|
++ cxxFlags
|
|
|
|
++ [
|
|
|
|
# System libc
|
2021-01-23 13:15:07 +00:00
|
|
|
"-isystem" "${lib.getDev stdenv.cc.libc}/include"
|
2020-11-19 19:29:02 +00:00
|
|
|
|
2023-08-19 20:19:01 +00:00
|
|
|
# cling includes
|
|
|
|
"-isystem" "${lib.getDev unwrapped}/include"
|
|
|
|
];
|
2020-11-19 19:29:02 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
|
2024-04-09 21:29:58 +00:00
|
|
|
stdenv.mkDerivation {
|
|
|
|
pname = "cling";
|
|
|
|
version = unwrapped.version;
|
|
|
|
|
2022-07-15 17:21:54 +00:00
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
2023-08-19 20:19:01 +00:00
|
|
|
inherit unwrapped flags;
|
2020-11-19 19:29:02 +00:00
|
|
|
inherit (unwrapped) meta;
|
2024-04-09 21:29:58 +00:00
|
|
|
|
|
|
|
dontUnpack = true;
|
|
|
|
dontConfigure = true;
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
|
|
|
|
makeWrapper $unwrapped/bin/cling $out/bin/cling \
|
|
|
|
--add-flags "$flags"
|
|
|
|
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
doCheck = true;
|
|
|
|
checkPhase = ''
|
|
|
|
runHook preCheck
|
|
|
|
|
|
|
|
output=$($out/bin/cling <<EOF
|
|
|
|
#include <iostream>
|
|
|
|
std::cout << "hello world" << std::endl
|
|
|
|
EOF
|
|
|
|
)
|
|
|
|
|
|
|
|
echo "$output" | grep -q "Type C++ code and press enter to run it"
|
|
|
|
echo "$output" | grep -q "hello world"
|
|
|
|
|
|
|
|
runHook postCheck
|
|
|
|
'';
|
|
|
|
|
|
|
|
dontInstall = true;
|
|
|
|
}
|