@@ -0,0 +1,78 @@
1+{ stdenv, fetchFromGitHub, mono, fsharp, dotnetPackages, z3, ocamlPackages, openssl, makeWrapper }:
2+
3+stdenv.mkDerivation rec {
4+ name = "fstar-${version}";
5+ version = "2016-01-12";
6+
7+ src = fetchFromGitHub {
8+ owner = "FStarLang";
9+ repo = "FStar";
10+ rev = "af9a231566ca52c9bc3409398c801ae9e8191cfa";
11+ sha256 = "1zri4gqr6j6hygnh0ckfhq93mqwk9i19vng8chnmvlr27zq734a2";
12+ };
13+
14+ buildInputs = with ocamlPackages; [
15+ mono fsharp z3 dotnetPackages.FsLexYacc ocaml findlib ocaml_batteries openssl makeWrapper
16+ ];
17+
18+ preBuild = ''
19+ substituteInPlace src/Makefile --replace "\$(RUNTIME) VS/.nuget/NuGet.exe" "true"
20+
21+ source setenv.sh
22+ '';
23+
24+ makeFlags = [
25+ "FSYACC=${dotnetPackages.FsLexYacc}/bin/fsyacc"
26+ "FSLEX=${dotnetPackages.FsLexYacc}/bin/fslex"
27+ "NUGET=true"
28+ "PREFIX=$(out)"
29+ ];
30+
31+ buildFlags = "-C src";
32+
33+ # Now that the .NET fstar.exe is built, use it to build the native OCaml binary
34+ postBuild = ''
35+ patchShebangs bin/fstar.exe
36+
37+ # Workaround for fsharp/fsharp#419
38+ cp ${fsharp}/lib/mono/4.5/FSharp.Core.dll bin/
39+
40+ # Use the built .NET binary to extract the sources of itself from F* to OCaml
41+ make ''${enableParallelBuilding:+-j''${NIX_BUILD_CORES} -l''${NIX_BUILD_CORES}} \
42+ $makeFlags "''${makeFlagsArray[@]}" \
43+ ocaml -C src
44+
45+ # Build the extracted OCaml sources
46+ make ''${enableParallelBuilding:+-j''${NIX_BUILD_CORES} -l''${NIX_BUILD_CORES}} \
47+ $makeFlags "''${makeFlagsArray[@]}" \
48+ -C src/ocaml-output
49+ '';
50+
51+ doCheck = true;
52+
53+ preCheck = "ulimit -s unlimited";
54+
55+ # Basic test suite:
56+ #checkFlags = "VERBOSE=y -C examples";
57+
58+ # Complete, but heavyweight test suite:
59+ checkTarget = "regressions";
60+ checkFlags = "VERBOSE=y -C src";
61+
62+ installFlags = "-C src/ocaml-output";
63+
64+ postInstall = ''
65+ # Workaround for FStarLang/FStar#456
66+ mv $out/lib/fstar/* $out/lib/
67+ rmdir $out/lib/fstar
68+
69+ wrapProgram $out/bin/fstar.exe --prefix PATH ":" "${z3}/bin"
70+ '';
71+
72+ meta = with stdenv.lib; {
73+ description = "ML-like functional programming language aimed at program verification";
74+ homepage = "https://www.fstar-lang.org";
75+ license = licenses.asl20;
76+ platforms = with platforms; linux;
77+ };
78+}