1{ lib
2, stdenv
3, fetchFromGitHub
4, fetchurl
5, autoconf
6, automake
7, fontconfig
8, libX11
9, perl
10, flex
11, bison
12, pkg-config
13, tcl
14, tk
15, xorg
16, yices
17, zlib
18, ghc
19, gmp-static
20, verilog
21, asciidoctor
22, tex
23, which
24}:
25
26let
27 ghcWithPackages = ghc.withPackages (g: (with g; [ old-time regex-compat syb split ]));
28
29in stdenv.mkDerivation rec {
30 pname = "bluespec";
31 version = "2023.01";
32
33 src = fetchFromGitHub {
34 owner = "B-Lang-org";
35 repo = "bsc";
36 rev = version;
37 sha256 = "sha256-kFHQtRaQmZiHo+IQ+mwbW23i3kbdAh/XH0OE7P/ibd0=";
38 };
39
40 yices-src = fetchurl {
41 url = "https://github.com/B-Lang-org/bsc/releases/download/${version}/yices-src-for-bsc-${version}.tar.gz";
42 sha256 = "sha256-pyEdCJvmgwOYPMZEtw7aro76tSn/Y/2GcKTyARmIh4E=";
43 };
44
45 enableParallelBuilding = true;
46
47 outputs = [ "out" "doc" ];
48
49 # https://github.com/B-Lang-org/bsc/pull/278
50 patches = [ ./libstp_stub_makefile.patch ];
51
52 postUnpack = ''
53 tar -C $sourceRoot/ -xf ${yices-src}
54 chmod -R +rwX $sourceRoot/src/vendor/yices/v2.6/yices2
55 '';
56
57 preBuild = ''
58 patchShebangs \
59 src/Verilog/copy_module.pl \
60 src/comp/update-build-version.sh \
61 src/comp/update-build-system.sh \
62 src/comp/wrapper.sh
63
64 substituteInPlace src/comp/Makefile \
65 --replace 'BINDDIR' 'BINDIR' \
66 --replace 'install-bsc install-bluetcl' 'install-bsc install-bluetcl $(UTILEXES) install-utils'
67
68 # allow running bsc to bootstrap
69 export LD_LIBRARY_PATH=$PWD/inst/lib/SAT
70 '';
71
72 buildInputs = yices.buildInputs ++ [
73 fontconfig
74 libX11 # tcltk
75 tcl
76 tk
77 which
78 xorg.libXft
79 zlib
80 ];
81
82 nativeBuildInputs = [
83 automake
84 autoconf
85 asciidoctor
86 bison
87 flex
88 ghcWithPackages
89 perl
90 pkg-config
91 tex
92 ];
93
94 makeFlags = [
95 "release"
96 "NO_DEPS_CHECKS=1" # skip the subrepo check (this deriviation uses yices-src instead of the subrepo)
97 "NOGIT=1" # https://github.com/B-Lang-org/bsc/issues/12
98 "LDCONFIG=ldconfig" # https://github.com/B-Lang-org/bsc/pull/43
99 "STP_STUB=1"
100 ];
101
102 doCheck = true;
103
104 nativeCheckInputs = [
105 gmp-static
106 verilog
107 ];
108
109 checkTarget = "check-smoke";
110
111 installPhase = ''
112 mkdir -p $out
113 mv inst/bin $out
114 mv inst/lib $out
115
116 # fragile, I know..
117 mkdir -p $doc/share/doc/bsc
118 mv inst/README $doc/share/doc/bsc
119 mv inst/ReleaseNotes.* $doc/share/doc/bsc
120 mv inst/doc/*.pdf $doc/share/doc/bsc
121 '';
122
123 meta = {
124 description = "Toolchain for the Bluespec Hardware Definition Language";
125 homepage = "https://github.com/B-Lang-org/bsc";
126 license = lib.licenses.bsd3;
127 platforms = [ "x86_64-linux" ];
128 mainProgram = "bsc";
129 # darwin fails at https://github.com/B-Lang-org/bsc/pull/35#issuecomment-583731562
130 # aarch64 fails, as GHC fails with "ghc: could not execute: opt"
131 maintainers = with lib.maintainers; [ jcumming thoughtpolice ];
132 };
133}