2022-11-21 00:23:00 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
2021-03-25 11:00:51 +00:00
|
|
|
, python3
|
2020-11-19 19:29:02 +00:00
|
|
|
, libffi
|
|
|
|
, git
|
|
|
|
, cmake
|
|
|
|
, zlib
|
|
|
|
, fetchgit
|
2022-11-21 00:23:00 +00:00
|
|
|
, fetchFromGitHub
|
2020-11-19 19:29:02 +00:00
|
|
|
, makeWrapper
|
|
|
|
, runCommand
|
2022-11-21 00:23:00 +00:00
|
|
|
, llvmPackages_9
|
2020-11-19 19:29:02 +00:00
|
|
|
, glibc
|
2021-05-08 22:58:11 +00:00
|
|
|
, ncurses
|
2020-11-19 19:29:02 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2023-04-15 09:45:35 +00:00
|
|
|
# The LLVM 9 headers have a couple bugs we need to patch
|
|
|
|
fixedLlvmDev = runCommand "llvm-dev-${llvmPackages_9.llvm.version}" { buildInputs = [git]; } ''
|
2023-04-15 22:57:54 +00:00
|
|
|
mkdir $out
|
|
|
|
cp -r ${llvmPackages_9.llvm.dev}/include $out
|
2023-04-15 09:45:35 +00:00
|
|
|
cd $out
|
|
|
|
chmod -R u+w include
|
|
|
|
git apply ${./fix-llvm-include.patch}
|
|
|
|
'';
|
|
|
|
|
2020-11-19 19:29:02 +00:00
|
|
|
unwrapped = stdenv.mkDerivation rec {
|
|
|
|
pname = "cling-unwrapped";
|
2022-11-21 00:23:00 +00:00
|
|
|
version = "0.9";
|
2020-11-19 19:29:02 +00:00
|
|
|
|
|
|
|
src = fetchgit {
|
|
|
|
url = "http://root.cern/git/clang.git";
|
2022-11-21 00:23:00 +00:00
|
|
|
rev = "cling-v0.9";
|
|
|
|
sha256 = "sha256-ft1NUIclSiZ9lN3Z3DJCWA0U9q/K1M0TKkZr+PjsFYk=";
|
2020-11-19 19:29:02 +00:00
|
|
|
};
|
|
|
|
|
2022-11-21 00:23:00 +00:00
|
|
|
clingSrc = fetchFromGitHub {
|
|
|
|
owner = "root-project";
|
|
|
|
repo = "cling";
|
|
|
|
rev = "v0.9";
|
|
|
|
sha256 = "0wx3fi19wfjcph5kclf8108i436y79ddwakrcf0lgxnnxhdjyd29";
|
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
|
|
|
|
2020-11-19 19:29:02 +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-17 00:52:36 +00:00
|
|
|
|
|
|
|
# https://github.com/root-project/root/commit/286d96b12aad8688b9d8e4b3b5df843dcfb716a8
|
|
|
|
./fix-llvm-dylib-usage.patch
|
2023-04-17 06:14:26 +00:00
|
|
|
|
|
|
|
./force-install-cling-targets.patch
|
2022-11-22 05:37:41 +00:00
|
|
|
];
|
|
|
|
|
2023-04-15 09:45:35 +00:00
|
|
|
nativeBuildInputs = [ python3 git cmake ];
|
|
|
|
buildInputs = [ libffi zlib ncurses ];
|
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 = [
|
2023-04-15 09:48:16 +00:00
|
|
|
"-DLLVM_BINARY_DIR=${llvmPackages_9.llvm.out}"
|
|
|
|
"-DLLVM_CONFIG=${llvmPackages_9.llvm.dev}/bin/llvm-config"
|
|
|
|
"-DLLVM_LIBRARY_DIR=${llvmPackages_9.llvm.lib}/lib"
|
|
|
|
"-DLLVM_MAIN_INCLUDE_DIR=${fixedLlvmDev}/include"
|
|
|
|
"-DLLVM_TABLEGEN_EXE=${llvmPackages_9.llvm.out}/bin/llvm-tblgen"
|
|
|
|
"-DLLVM_TOOLS_BINARY_DIR=${llvmPackages_9.llvm.out}/bin"
|
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"
|
|
|
|
# "--trace-expand"
|
2020-11-19 19:29:02 +00:00
|
|
|
];
|
|
|
|
|
2021-01-23 13:15:07 +00:00
|
|
|
meta = with lib; {
|
2020-11-19 19:29:02 +00:00
|
|
|
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++"
|
2021-01-23 13:15:07 +00:00
|
|
|
"-isystem" "${lib.getDev stdenv.cc.libc}/include"
|
llvmPackages: Multuple outputs for everythting
Also begin to start work on cross compilation, though that will have to
be finished later.
The patches are based on the first version of
https://reviews.llvm.org/D99484. It's very annoying to do the
back-porting but the review has uncovered nothing super major so I'm
fine sticking with what I've got.
Beyond making the outputs work, I also strove to re-sync the packages,
as they have been drifting pointlessly apart for some time.
----
Other misc notes, highly incomplete
- lvm-config-native and llvm-config are put in `dev` because they are
tools just for build time.
- Clang no longer has an lld dep. That was introduced in
db29857eb391ed002046090851a44c452b80bdbd, but if clang needs help
finding lld when it is used we should just pass it flags / put in the
resource dir. Providing it at build time increases critical path
length for no good reason.
----
A note on `nativeCC`:
`stdenv` takes tools from the previous stage, so:
1. `pkgsBuildBuild`: `(?1, x, x)`
2. `pkgsBuildBuild.stdenv.cc`: `(?0, ?1, x)`
while:
1. `pkgsBuildBuild`: `(?1, x, x)`
2. `pkgsBuildBuild.targetPackages`: `(x, x, ?2)`
3. `pkgsBuildBuild.targetPackages.stdenv.cc`: `(?1, x, x)`
2020-10-15 08:23:57 +00:00
|
|
|
"-I" "${lib.getDev unwrapped}/include"
|
2023-04-15 09:48:16 +00:00
|
|
|
"-I" "${lib.getLib unwrapped}/lib/clang/9.0.1/include"
|
2020-11-19 19:29:02 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
# 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.
|
2021-08-15 15:12:23 +00:00
|
|
|
compilerIncludeFlags = runCommand "compiler-include-flags.txt" {} ''
|
2020-11-19 19:29:02 +00:00
|
|
|
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}" {
|
2022-07-15 17:21:54 +00:00
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
2020-11-19 19:29:02 +00:00
|
|
|
inherit unwrapped flags compilerIncludeFlags;
|
|
|
|
inherit (unwrapped) meta;
|
|
|
|
} ''
|
|
|
|
makeWrapper $unwrapped/bin/cling $out/bin/cling \
|
|
|
|
--add-flags "$(cat "$compilerIncludeFlags")" \
|
|
|
|
--add-flags "$flags"
|
|
|
|
''
|