1{ stdenv
2, lib
3, cmake
4, coreutils
5, python3
6, git
7, fetchFromGitHub
8, ninja
9, lit
10, z3
11, gitUpdater
12, callPackage
13}:
14
15let
16 pythonEnv = python3.withPackages (ps: [ ps.psutil ]);
17 circt-llvm = callPackage ./circt-llvm.nix { };
18in
19stdenv.mkDerivation rec {
20 pname = "circt";
21 version = "1.79";
22 src = fetchFromGitHub {
23 owner = "llvm";
24 repo = "circt";
25 rev = "firtool-${version}";
26 hash = "sha256-/PEny7+E/s1Y08NigO22uDnhFfMBtccqaI8hsBOO2fI=";
27 fetchSubmodules = true;
28 };
29
30 requiredSystemFeatures = [ "big-parallel" ];
31
32 nativeBuildInputs = [ cmake ninja git pythonEnv z3 ];
33 buildInputs = [ circt-llvm ];
34
35 cmakeFlags = [
36 "-DBUILD_SHARED_LIBS=ON"
37 "-DMLIR_DIR=${circt-llvm.dev}/lib/cmake/mlir"
38
39 # LLVM_EXTERNAL_LIT is executed by python3, the wrapped bash script will not work
40 "-DLLVM_EXTERNAL_LIT=${lit}/bin/.lit-wrapped"
41 "-DCIRCT_LLHD_SIM_ENABLED=OFF"
42 ];
43
44 # There are some tests depending on `clang-tools` to work. They are activated only when detected
45 # `clang-tidy` in PATH, However, we cannot simply put `clang-tools` in checkInputs to make these
46 # tests work. Because
47 #
48 # 1. The absolute paths of binaries used in tests are resolved in configure phase.
49 # 2. When stdenv = clangStdenv, the `clang-tidy` binary appears in PATH via `clang-unwrapped`,
50 # which is always placed before `${clang-tools}/bin` in PATH. `clang-tidy` provided in
51 # `clang-unwrapped` cause tests failing because it is not wrapped to resolve header search paths.
52 # https://github.com/NixOS/nixpkgs/issues/214945 discusses this issue.
53 #
54 # As a temporary fix, we disabled these tests when using clang stdenv
55 # cannot use lib.optionalString as it creates an empty string, disabling all tests
56 LIT_FILTER_OUT = if stdenv.cc.isClang then "CIRCT :: Target/ExportSystemC/.*\.mlir" else null;
57
58 preConfigure = ''
59 find ./test -name '*.mlir' -exec sed -i 's|/usr/bin/env|${coreutils}/bin/env|g' {} \;
60 # circt uses git to check its version, but when cloned on nix it can't access git.
61 # So this hard codes the version.
62 substituteInPlace cmake/modules/GenVersionFile.cmake --replace "unknown git version" "${src.rev}"
63 '';
64
65 doCheck = true;
66 checkTarget = "check-circt check-circt-integration";
67
68 outputs = [ "out" "lib" "dev" ];
69
70 # Copy circt-llvm's postFixup stage so that it can make all our dylib references
71 # absolute as well.
72 #
73 # We don't need `postPatch` because circt seems to be automatically inheriting
74 # the config somehow, presumably via. `-DMLIR_DIR`.
75 postFixup = circt-llvm.postFixup;
76
77 postInstall = ''
78 moveToOutput lib "$lib"
79 '';
80
81 passthru = {
82 updateScript = gitUpdater {
83 rev-prefix = "firtool-";
84 };
85 llvm = circt-llvm;
86 };
87
88 meta = {
89 description = "Circuit IR compilers and tools";
90 homepage = "https://circt.org/";
91 license = lib.licenses.asl20;
92 maintainers = with lib.maintainers; [ sharzy pineapplehunter ];
93 platforms = lib.platforms.all;
94 };
95}