1{
2 lib,
3 stdenv,
4 darwin,
5 fetchurl,
6 buildDunePackage,
7 base64,
8 omd,
9 menhir,
10 menhirLib,
11 ott,
12 linenoise,
13 dune-site,
14 pprint,
15 makeWrapper,
16 lem,
17 linksem,
18 yojson,
19 version ? "0.19",
20}:
21
22buildDunePackage {
23 pname = "sail";
24 inherit version;
25
26 src = fetchurl {
27 url = "https://github.com/rems-project/sail/releases/download/${version}/sail-${version}.tbz";
28 hash = "sha256-VFjmmsCl2fUnONGUZQnFAYl/VIesy5YQsfIMMDBdI+A=";
29 };
30
31 minimalOCamlVersion = "4.08";
32
33 nativeBuildInputs =
34 [
35 makeWrapper
36 ott
37 menhir
38 lem
39 ]
40 ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [
41 darwin.sigtool
42 ];
43
44 propagatedBuildInputs = [
45 base64
46 omd
47 dune-site
48 linenoise
49 menhirLib
50 pprint
51 linksem
52 yojson
53 ];
54
55 preBuild = ''
56 rm -r aarch* # Remove code derived from non-bsd2 arm spec
57 rm -r snapshots # Some of this might be derived from stuff in the aarch dir, it builds fine without it
58 '';
59 # `buildDunePackage` only builds the [pname] package
60 # This doesnt work in this case, as sail includes multiple packages in the same source tree
61 buildPhase = ''
62 runHook preBuild
63 dune build --release ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
64 runHook postBuild
65 '';
66 checkPhase = ''
67 runHook preCheck
68 dune runtest ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
69 runHook postCheck
70 '';
71 installPhase = ''
72 runHook preInstall
73 dune install --prefix $out --libdir $OCAMLFIND_DESTDIR
74 runHook postInstall
75 '';
76 postInstall = ''
77 wrapProgram $out/bin/sail --set SAIL_DIR $out/share/sail
78 '';
79
80 meta = with lib; {
81 homepage = "https://github.com/rems-project/sail";
82 description = "Language for describing the instruction-set architecture (ISA) semantics of processors";
83 maintainers = with maintainers; [ genericnerdyusername ];
84 license = licenses.bsd2;
85 };
86}