1{ lib, stdenv, jre, setJavaClassPath, coursier, makeWrapper }:
2
3stdenv.mkDerivation rec {
4 pname = "firrtl";
5 version = "1.5.3";
6 scalaVersion = "2.13"; # pin, for determinism
7
8 deps = stdenv.mkDerivation {
9 pname = "${pname}-deps";
10 inherit version;
11 nativeBuildInputs = [ coursier ];
12 buildCommand = ''
13 export COURSIER_CACHE=$(pwd)
14 cs fetch edu.berkeley.cs:${pname}_${scalaVersion}:${version} > deps
15 mkdir -p $out/share/java
16 cp $(< deps) $out/share/java
17 '';
18 outputHashMode = "recursive";
19 outputHash = "sha256-xy3zdJZk6Q2HbEn5tRQ9Z0AjyXEteXepoWDaATjiUUw=";
20 };
21
22 nativeBuildInputs = [ makeWrapper setJavaClassPath ];
23 buildInputs = [ deps ];
24
25 dontUnpack = true;
26
27 installPhase = ''
28 runHook preInstall
29
30 makeWrapper ${jre}/bin/java $out/bin/${pname} \
31 --add-flags "-cp $CLASSPATH firrtl.stage.FirrtlMain"
32
33 runHook postInstall
34 '';
35
36 doInstallCheck = true;
37 installCheckPhase = ''
38 $out/bin/firrtl --firrtl-source "${''
39 circuit test:
40 module test:
41 input a: UInt<8>
42 input b: UInt<8>
43 output o: UInt
44 o <= add(a, not(b))
45 ''}" -o test.v
46 cat test.v
47 grep -qFe "module test" -e "endmodule" test.v
48 '';
49
50 meta = with lib; {
51 description = "Flexible Intermediate Representation for RTL";
52 longDescription = ''
53 Firrtl is an intermediate representation (IR) for digital circuits
54 designed as a platform for writing circuit-level transformations.
55 '';
56 homepage = "https://www.chisel-lang.org/firrtl/";
57 license = licenses.asl20;
58 maintainers = with maintainers; [ dtzWill ];
59 };
60}