1{ stdenv
2, lib
3, cmake
4, coreutils
5, python3
6, git
7, fetchFromGitHub
8, ninja
9}:
10
11let
12 pythonEnv = python3.withPackages (ps: [ ps.psutil ]);
13in
14stdenv.mkDerivation rec {
15 pname = "circt";
16 version = "1.40.0";
17 src = fetchFromGitHub {
18 owner = "llvm";
19 repo = "circt";
20 rev = "firtool-${version}";
21 sha256 = "sha256-L114Xh0O/Wu8IyrKohxalyXeSe/8oVcAXD4hpa6ocwU=";
22 fetchSubmodules = true;
23 };
24
25 requiredSystemFeatures = [ "big-parallel" ];
26
27 nativeBuildInputs = [ cmake ninja git pythonEnv ];
28
29 cmakeDir = "../llvm/llvm";
30 cmakeFlags = [
31 "-DLLVM_ENABLE_BINDINGS=OFF"
32 "-DLLVM_ENABLE_OCAMLDOC=OFF"
33 "-DLLVM_BUILD_EXAMPLES=OFF"
34 "-DLLVM_OPTIMIZED_TABLEGEN=ON"
35 "-DLLVM_ENABLE_PROJECTS=mlir"
36 "-DLLVM_EXTERNAL_PROJECTS=circt"
37 "-DLLVM_EXTERNAL_CIRCT_SOURCE_DIR=.."
38 "-DCIRCT_LLHD_SIM_ENABLED=OFF"
39 ];
40
41 # There are some tests depending on `clang-tools` to work. They are activated only when detected
42 # `clang-tidy` in PATH, However, we cannot simply put `clang-tools` in checkInputs to make these
43 # tests work. Because
44 #
45 # 1. The absolute paths of binaries used in tests are resolved in configure phase.
46 # 2. When stdenv = clangStdenv, the `clang-tidy` binary appears in PATH via `clang-unwrapped`,
47 # which is always placed before `${clang-tools}/bin` in PATH. `clang-tidy` provided in
48 # `clang-unwrapped` cause tests failing because it is not wrapped to resolve header search paths.
49 # https://github.com/NixOS/nixpkgs/issues/214945 discusses this issue.
50 #
51 # As a temporary fix, we disabled these tests when using clang stdenv
52 # cannot use lib.optionalString as it creates an empty string, disabling all tests
53 LIT_FILTER_OUT = if stdenv.cc.isClang then "CIRCT :: Target/ExportSystemC/.*\.mlir" else null;
54
55 preConfigure = ''
56 substituteInPlace test/circt-reduce/test/annotation-remover.mlir --replace "/usr/bin/env" "${coreutils}/bin/env"
57 '';
58
59 installPhase = ''
60 runHook preInstall
61 mkdir -p $out/bin
62 mv bin/{{fir,hls}tool,circt-{as,dis,lsp-server,opt,reduce,translate}} $out/bin
63 runHook postInstall
64 '';
65
66 doCheck = true;
67 checkTarget = "check-circt check-circt-integration";
68
69 meta = {
70 description = "Circuit IR compilers and tools";
71 homepage = "https://circt.org/";
72 license = lib.licenses.asl20;
73 maintainers = with lib.maintainers; [ sharzy ];
74 platforms = lib.platforms.all;
75 };
76}
77