about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/compilers/circt
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/compilers/circt')
-rw-r--r--nixpkgs/pkgs/development/compilers/circt/circt-llvm.nix59
-rw-r--r--nixpkgs/pkgs/development/compilers/circt/default.nix42
2 files changed, 81 insertions, 20 deletions
diff --git a/nixpkgs/pkgs/development/compilers/circt/circt-llvm.nix b/nixpkgs/pkgs/development/compilers/circt/circt-llvm.nix
new file mode 100644
index 000000000000..b3005af55fbb
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/circt/circt-llvm.nix
@@ -0,0 +1,59 @@
+{ stdenv
+, cmake
+, ninja
+, circt
+, llvm
+, python3
+}: stdenv.mkDerivation {
+  pname = circt.pname + "-llvm";
+  inherit (circt) version src;
+
+  requiredSystemFeatures = [ "big-parallel" ];
+
+  nativeBuildInputs = [ cmake ninja python3 ];
+
+  preConfigure = ''
+    cd llvm/llvm
+  '';
+
+  cmakeFlags = [
+    "-DBUILD_SHARED_LIBS=ON"
+    "-DLLVM_ENABLE_BINDINGS=OFF"
+    "-DLLVM_ENABLE_OCAMLDOC=OFF"
+    "-DLLVM_BUILD_EXAMPLES=OFF"
+    "-DLLVM_OPTIMIZED_TABLEGEN=ON"
+    "-DLLVM_ENABLE_PROJECTS=mlir"
+    "-DLLVM_TARGETS_TO_BUILD="
+
+    # This option is needed to install llvm-config
+    "-DLLVM_INSTALL_UTILS=ON"
+  ];
+
+  outputs = [ "out" "lib" "dev" ];
+
+  postInstall = ''
+    # move llvm-config to $dev to resolve a circular dependency
+    moveToOutput "bin/llvm-config*" "$dev"
+
+    # move all lib files to $lib except lib/cmake
+    moveToOutput "lib" "$lib"
+    moveToOutput "lib/cmake" "$dev"
+
+    # patch configuration files so each path points to the new $lib or $dev paths
+    substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \
+      --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "'"$lib"'")'
+    substituteInPlace \
+      "$dev/lib/cmake/llvm/LLVMExports-release.cmake" \
+      "$dev/lib/cmake/mlir/MLIRTargets-release.cmake" \
+      --replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \
+      --replace "\''${_IMPORT_PREFIX}/lib/objects-Release" "$lib/lib/objects-Release" \
+      --replace "$out/bin/llvm-config" "$dev/bin/llvm-config" # patch path for llvm-config
+  '';
+
+  doCheck = true;
+  checkTarget = "check-mlir";
+
+  meta = llvm.meta // {
+    inherit (circt.meta) maintainers;
+  };
+}
diff --git a/nixpkgs/pkgs/development/compilers/circt/default.nix b/nixpkgs/pkgs/development/compilers/circt/default.nix
index 4c4f69bc74ff..6fb609699bad 100644
--- a/nixpkgs/pkgs/development/compilers/circt/default.nix
+++ b/nixpkgs/pkgs/development/compilers/circt/default.nix
@@ -6,36 +6,37 @@
 , git
 , fetchFromGitHub
 , ninja
+, lit
 , gitUpdater
+, callPackage
 }:
 
 let
   pythonEnv = python3.withPackages (ps: [ ps.psutil ]);
+  circt-llvm = callPackage ./circt-llvm.nix { };
 in
 stdenv.mkDerivation rec {
   pname = "circt";
-  version = "1.59.0";
+  version = "1.61.0";
   src = fetchFromGitHub {
     owner = "llvm";
     repo = "circt";
     rev = "firtool-${version}";
-    sha256 = "sha256-HsfvLxXyYvzUL+FO/i8iRbyQV8OFF3Cx8/g8/9aJE2M=";
+    sha256 = "sha256-3zuaruaveUeJ7uKP5fMiDFPOGKcs6aTNuGOuhxV6nss=";
     fetchSubmodules = true;
   };
 
   requiredSystemFeatures = [ "big-parallel" ];
 
   nativeBuildInputs = [ cmake ninja git pythonEnv ];
+  buildInputs = [ circt-llvm ];
 
-  cmakeDir = "../llvm/llvm";
   cmakeFlags = [
-    "-DLLVM_ENABLE_BINDINGS=OFF"
-    "-DLLVM_ENABLE_OCAMLDOC=OFF"
-    "-DLLVM_BUILD_EXAMPLES=OFF"
-    "-DLLVM_OPTIMIZED_TABLEGEN=ON"
-    "-DLLVM_ENABLE_PROJECTS=mlir"
-    "-DLLVM_EXTERNAL_PROJECTS=circt"
-    "-DLLVM_EXTERNAL_CIRCT_SOURCE_DIR=.."
+    "-DBUILD_SHARED_LIBS=ON"
+    "-DMLIR_DIR=${circt-llvm.dev}/lib/cmake/mlir"
+
+    # LLVM_EXTERNAL_LIT is executed by python3, the wrapped bash script will not work
+    "-DLLVM_EXTERNAL_LIT=${lit}/bin/.lit-wrapped"
     "-DCIRCT_LLHD_SIM_ENABLED=OFF"
   ];
 
@@ -60,18 +61,20 @@ stdenv.mkDerivation rec {
     substituteInPlace cmake/modules/GenVersionFile.cmake --replace "unknown git version" "${src.rev}"
   '';
 
-  installPhase = ''
-    runHook preInstall
-    mkdir -p $out/bin
-    mv bin/{{fir,hls}tool,circt-{as,dis,lsp-server,opt,reduce,translate}} $out/bin
-    runHook postInstall
-  '';
-
   doCheck = true;
   checkTarget = "check-circt check-circt-integration";
 
-  passthru.updateScript = gitUpdater {
-    rev-prefix = "firtool-";
+  outputs = [ "out" "lib" "dev" ];
+
+  postInstall = ''
+    moveToOutput lib "$lib"
+  '';
+
+  passthru = {
+    updateScript = gitUpdater {
+      rev-prefix = "firtool-";
+    };
+    llvm = circt-llvm;
   };
 
   meta = {
@@ -82,4 +85,3 @@ stdenv.mkDerivation rec {
     platforms = lib.platforms.all;
   };
 }
-