-
Notifications
You must be signed in to change notification settings - Fork 0
/
circt.nix
116 lines (102 loc) · 3.44 KB
/
circt.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
{ lib, fetchpatch
, stdenv, cmake, pkg-config
, gnugrep
, coreutils
, libllvm, mlir, lit
, circt-src
, grpc
, verilator
# TODO: Shouldn't need to specify these deps, fix in upstream nixpkgs!
, or-tools, bzip2, cbc, eigen, glpk, re2
, python3
, llvm-third-party-src
, ninja
, doxygen
, graphviz-nox
, enableDocs ? false
, enableAssertions ? true
, enableOrTools ? false # stdenv.hostPlatform.isLinux
, slang
, enableSlang ? true
, enableLLHD ? false # Drops llhd-sim -> lib output dep.
, withVerilator ? !stdenv.hostPlatform.isDarwin
, z3
}:
# TODO: or-tools, needs cmake bits maybe?
let
mkVer = src:
let
date = builtins.substring 0 8 (src.lastModifiedDate or src.lastModified or "19700101");
rev = src.shortRev or "dirty";
in
"g${date}_${rev}";
tag = "1.89.0";
versionSuffix = mkVer circt-src;
version = "${tag}${versionSuffix}";
in stdenv.mkDerivation {
pname = "circt";
inherit version;
nativeBuildInputs = [ cmake python3 ninja pkg-config ]
++ lib.optionals enableDocs [ doxygen graphviz-nox ];
buildInputs = [ mlir libllvm grpc z3 ]
++ lib.optionals enableOrTools [ or-tools bzip2 cbc eigen glpk re2 ]
++ lib.optional enableSlang [ slang ]
++ lib.optional withVerilator [ verilator ];
src = circt-src;
patches = [
./patches/circt-mlir-tblgen-path.patch
./patches/circt-mlir-cpu-runner-target.patch
./patches/circt-install-dir.patch
./patches/circt-lit-dylib-paths.patch
];
postPatch = ''
substituteInPlace cmake/modules/GenVersionFile.cmake \
--replace-fail '"unknown git version"' '"firtool-${version}"'
find test -type f -exec \
sed -i -e 's,--test /usr/bin/env,--test ${lib.getBin coreutils}/bin/env,' \{\} \;
''
# slang library renamed to 'svlang'.
+ lib.optionalString enableSlang ''
substituteInPlace lib/Conversion/ImportVerilog/CMakeLists.txt \
--replace-fail slang_slang slang::slang
'';
outputs = [ "out" "lib" "dev" ];
cmakeFlags = [
"-DLLVM_EXTERNAL_LIT=${lit}/bin/.lit-wrapped" # eep
"-DLLVM_LIT_ARGS=-v"
"-DLLVM_THIRD_PARTY_DIR=${llvm-third-party-src}"
"-DCIRCT_INSTALL_PACKAGE_DIR==${placeholder "dev"}/lib/cmake/circt"
"-DCIRCT_TOOLS_INSTALL_DIR=${placeholder "out"}/bin"
"-DCIRCT_LIBRARY_DIR=${placeholder "lib"}/lib"
"-DCIRCT_LLHD_SIM_ENABLED=${if enableLLHD then "ON" else "OFF"}"
"-DMLIR_TABLEGEN_EXE=${lib.getOutput "bin" mlir}/bin/mlir-tblgen" # assumes not-cross for now
] ++ lib.optional enableDocs "-DCIRCT_INCLUDE_DOCS=ON"
++ lib.optional enableAssertions "-DLLVM_ENABLE_ASSERTIONS=ON"
++ lib.optionals enableSlang [
"-DCIRCT_SLANG_FRONTEND_ENABLED=ON"
"-DCIRCT_SLANG_BUILD_FROM_SOURCE=OFF"
];
postBuild = lib.optionalString enableDocs ''
ninja doxygen-circt circt-doc
'';
doCheck = true;
# No integration tests for now, bits aren't working
checkTarget = "check-circt"; # + " check-circt-integration";
preCheck = ''
patchShebangs bin/*.py
'';
# Manually install bits that don't have install rules yet.
postInstall = ''
install -Dm755 -t $out/bin bin/arcilator-header-cpp.py
# Doesn't belong in $out/bin, but that's where it's expected for now.
# $out/share/arcilator/ ?
install -Dt $out/bin bin/arcilator-runtime.h
'';
meta = with lib; {
description = " Circuit IR Compilers and Tools";
mainProgram = "firtool";
homepage = "https://circt.org";
license = with licenses; [ asl20-llvm];
maintainers = with maintainers; [ dtzWill ];
};
}