about summary refs log tree commit diff
path: root/pkgs/development/interpreters/cling
diff options
context:
space:
mode:
authorTom McLaughlin <tom@codedown.io>2023-04-15 02:45:35 -0700
committerTom McLaughlin <tom@codedown.io>2023-04-15 02:45:35 -0700
commitd77f11a719f78a8ab6dd000a640c5cad79d189a5 (patch)
tree12e017f95804145f6342d56794f4e358fa9f83f9 /pkgs/development/interpreters/cling
parentd7b1cb48aa8d150f9954a9cce99e95a799b8fd4c (diff)
Able to build cling 0.9
Diffstat (limited to 'pkgs/development/interpreters/cling')
-rw-r--r--pkgs/development/interpreters/cling/default.nix38
-rw-r--r--pkgs/development/interpreters/cling/fix-llvm-include.patch27
-rw-r--r--pkgs/development/interpreters/cling/use-patched-llvm.patch32
3 files changed, 46 insertions, 51 deletions
diff --git a/pkgs/development/interpreters/cling/default.nix b/pkgs/development/interpreters/cling/default.nix
index a4f5118db76fd..5ef6614af2a93 100644
--- a/pkgs/development/interpreters/cling/default.nix
+++ b/pkgs/development/interpreters/cling/default.nix
@@ -15,6 +15,14 @@
 }:
 
 let
+  # The LLVM 9 headers have a couple bugs we need to patch
+  fixedLlvmDev = runCommand "llvm-dev-${llvmPackages_9.llvm.version}" { buildInputs = [git]; } ''
+    cp -r ${llvmPackages_9.llvm.dev} $out
+    cd $out
+    chmod -R u+w include
+    git apply ${./fix-llvm-include.patch}
+  '';
+
   unwrapped = stdenv.mkDerivation rec {
     pname = "cling-unwrapped";
     version = "0.9";
@@ -24,7 +32,6 @@ let
       rev = "cling-v0.9";
       sha256 = "sha256-ft1NUIclSiZ9lN3Z3DJCWA0U9q/K1M0TKkZr+PjsFYk=";
     };
-    # src = /home/tom/tools/clang;
 
     clingSrc = fetchFromGitHub {
       owner = "root-project";
@@ -32,40 +39,33 @@ let
       rev = "v0.9";
       sha256 = "0wx3fi19wfjcph5kclf8108i436y79ddwakrcf0lgxnnxhdjyd29";
     };
-    # clingSrc = /home/tom/tools/cling;
-
-    llvmSrc = fetchgit {
-      url = "http://root.cern/git/llvm.git";
-      rev = "cling-v0.9";
-      sha256 = "sha256-jts7DMnXwZF/pzUfWEQeJmj5XlOb51aXn6KExMbmcXg=";
-    };
-    # llvmSrc = /home/tom/tools/llvm;
 
     prePatch = ''
       echo "add_llvm_external_project(cling)" >> tools/CMakeLists.txt
 
       cp -r $clingSrc ./tools/cling
       chmod -R a+w ./tools/cling
-
-      mkdir ./interpreter
-      cp -r $llvmSrc ./interpreter/llvm
-      chmod -R a+w ./interpreter/llvm
     '';
 
     patches = [
       # Applied to clang src
       ./no-clang-cpp.patch
-
-      # Applied to cling src
-      ./use-patched-llvm.patch
     ];
 
-    nativeBuildInputs = [ python3 git cmake llvmPackages_9.llvm.dev ];
-    buildInputs = [ libffi llvmPackages_9.llvm zlib ncurses ];
+    nativeBuildInputs = [ python3 git cmake ];
+    buildInputs = [ libffi zlib ncurses ];
 
     strictDeps = true;
 
     cmakeFlags = [
+      "-DLLVM_BINARY_DIR=${llvmPackages_9.llvm.out}" # llvm_dir
+      "-DLLVM_CONFIG=${llvmPackages_9.llvm.dev}/bin/llvm-config" # llvm_config_path
+      "-DLLVM_LIBRARY_DIR=${llvmPackages_9.llvm.lib}/lib" # os.path.join(llvm_dir, 'lib')
+      "-DLLVM_MAIN_INCLUDE_DIR=${fixedLlvmDev}/include" # os.path.join(llvm_dir, 'include')
+      "-DLLVM_TABLEGEN_EXE=${llvmPackages_9.llvm.out}/bin/llvm-tblgen" # os.path.join(llvm_dir, 'bin', 'llvm-tblgen')
+      "-DLLVM_TOOLS_BINARY_DIR=${llvmPackages_9.llvm.out}/bin" # os.path.join(llvm_dir, 'bin')
+      "-DLLVM_TOOL_CLING_BUILD=ON"
+
       "-DLLVM_TARGETS_TO_BUILD=host;NVPTX"
       "-DLLVM_ENABLE_RTTI=ON"
 
@@ -101,7 +101,7 @@ let
     "-nostdinc++"
     "-isystem" "${lib.getDev stdenv.cc.libc}/include"
     "-I" "${lib.getDev unwrapped}/include"
-    "-I" "${lib.getLib unwrapped}/lib/clang/5.0.2/include"
+    # "-I" "${lib.getLib 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
diff --git a/pkgs/development/interpreters/cling/fix-llvm-include.patch b/pkgs/development/interpreters/cling/fix-llvm-include.patch
new file mode 100644
index 0000000000000..801965d02d3a2
--- /dev/null
+++ b/pkgs/development/interpreters/cling/fix-llvm-include.patch
@@ -0,0 +1,27 @@
+diff --git a/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h b/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h
+index 16202d8..3afdac3 100644
+--- a/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h
++++ b/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h
+@@ -220,7 +220,7 @@ public:
+   Error removeModule(VModuleKey K) {
+     auto I = ModuleMap.find(K);
+     assert(I != ModuleMap.end() && "VModuleKey K not valid here");
+-    auto EDM = std::move(I.second);
++    auto EDM = std::move(I->second);
+     ModuleMap.erase(I);
+     return EDM->removeModuleFromBaseLayer(BaseLayer);
+   }
+diff --git a/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h b/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h
+index d9535ce..4c688c3 100644
+--- a/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h
++++ b/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h
+@@ -472,7 +472,9 @@ private:
+ 
+   // NB!  `LinkedObjects` needs to be destroyed before `NotifyFreed` because
+   // `~ConcreteLinkedObject` calls `NotifyFreed`
++protected:
+   std::map<VModuleKey, std::unique_ptr<LinkedObject>> LinkedObjects;
++private:
+   bool ProcessAllSections = false;
+ };
+ 
diff --git a/pkgs/development/interpreters/cling/use-patched-llvm.patch b/pkgs/development/interpreters/cling/use-patched-llvm.patch
deleted file mode 100644
index dc2ee15369974..0000000000000
--- a/pkgs/development/interpreters/cling/use-patched-llvm.patch
+++ /dev/null
@@ -1,32 +0,0 @@
-diff --git a/tools/cling/lib/Interpreter/CMakeLists.txt b/tools/cling/lib/Interpreter/CMakeLists.txt
-index 75396717..6a617ab4 100644
---- a/tools/cling/lib/Interpreter/CMakeLists.txt
-+++ b/tools/cling/lib/Interpreter/CMakeLists.txt
-@@ -344,3 +344,25 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h
-
- add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/CIFactory.cpp
-                       ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h)
-+
-+# If LLVM is external, but Clang is builtin, we must use some files
-+# from patched (builtin) version of LLVM
-+set(FixInclude "${CMAKE_SOURCE_DIR}/interpreter/llvm/include")
-+
-+get_property(P SOURCE IncrementalJIT.cpp PROPERTY INCLUDE_DIRECTORIES)
-+list(INSERT P 0 ${FixInclude})
-+set_property(SOURCE IncrementalJIT.cpp PROPERTY INCLUDE_DIRECTORIES "${P}")
-+
-+get_property(P SOURCE IncrementalExecutor.cpp PROPERTY INCLUDE_DIRECTORIES)
-+list(INSERT P 0 ${FixInclude})
-+set_property(SOURCE IncrementalExecutor.cpp PROPERTY INCLUDE_DIRECTORIES "${P}")
-+
-+get_property(P SOURCE Interpreter.cpp PROPERTY INCLUDE_DIRECTORIES)
-+list(INSERT P 0 ${FixInclude})
-+set_property(SOURCE Interpreter.cpp PROPERTY INCLUDE_DIRECTORIES "${P}")
-+
-+get_property(P SOURCE Transaction.cpp PROPERTY INCLUDE_DIRECTORIES)
-+list(INSERT P 0 ${FixInclude})
-+set_property(SOURCE Transaction.cpp PROPERTY INCLUDE_DIRECTORIES "${P}")
-+
-+get_property(P SOURCE TransactionUnloader.cpp PROPERTY INCLUDE_DIRECTORIES)
-+list(INSERT P 0 ${FixInclude})
-+endif()