Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix: various improvements #3182

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions .nix/bootstrap.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{ fstar, fstar-dune, fstar-ocaml-snapshot, fstar-ulib, stdenv }:

{
fstar,
fstar-dune,
fstar-ocaml-snapshot,
fstar-ulib,
stdenv,
}:
let
ocaml-src = stdenv.mkDerivation {
name = "src";
Expand All @@ -15,11 +20,18 @@ let
pname = "fstar-bootstrap-dune";
src = ocaml-src;
});
fstar-ulib-bootstrap = (fstar-ulib.override
(_: { fstar-dune = fstar-dune-bootstrap; })).overrideAttrs
(_: { pname = "fstar-bootstrap-ulib"; });

in (fstar.override (_: {
fstar-ulib-bootstrap =
(fstar-ulib.override (_: {
fstar-dune = fstar-dune-bootstrap;
})).overrideAttrs
(_: {
pname = "fstar-bootstrap-ulib";
});
in
(fstar.override (_: {
fstar-dune = fstar-dune-bootstrap;
fstar-ulib = fstar-ulib-bootstrap;
})).overrideAttrs (_: { pname = "fstar-bootstrap"; })
})).overrideAttrs
(_: {
pname = "fstar-bootstrap";
})
57 changes: 57 additions & 0 deletions .nix/dune.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
batteries,
buildDunePackage,
lib,
memtrace,
menhir,
menhirLib,
ocaml,
pprint,
ppx_deriving,
ppx_deriving_yojson,
ppxlib,
process,
sedlex,
stdint,
version,
yojson,
zarith,
}:
buildDunePackage {
pname = "fstar";
inherit version;

duneVersion = "3";

src = lib.sourceByRegex ./.. [
"ocaml.*"
"version.txt"
];

prePatch = ''
patchShebangs ocaml/fstar-lib/make_fstar_version.sh
cd ocaml
'';

FSTAR_COMMIT = version;

nativeBuildInputs = [ menhir ];

buildInputs = [ memtrace ];

propagatedBuildInputs = [
batteries
menhirLib
pprint
ppx_deriving
ppx_deriving_yojson
ppxlib
process
sedlex
stdint
yojson
zarith
];

enableParallelBuilding = true;
}
39 changes: 26 additions & 13 deletions .nix/fstar.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
{ callPackage, fstar-dune, fstar-ulib, installShellFiles, lib, makeWrapper
, stdenv, version, z3 }:

{
fstar-dune,
fstar-ulib,
installShellFiles,
lib,
makeWrapper,
ocamlPackages,
stdenv,
removeReferencesTo,
version,
z3,
}:
stdenv.mkDerivation {
pname = "fstar";
inherit version;

buildInputs = [ installShellFiles makeWrapper ];
buildInputs = [
installShellFiles
makeWrapper
removeReferencesTo
];

src = lib.sourceByRegex ./.. [
".common.mk"
Expand All @@ -15,6 +28,8 @@ stdenv.mkDerivation {
"ucontrib.*"
];

inherit (fstar-dune) propagatedBuildInputs;

dontBuild = true;

installPhase = ''
Expand All @@ -26,17 +41,15 @@ stdenv.mkDerivation {

PREFIX=$out make -C src/ocaml-output install-sides

for binary in $out/bin/*
do
chmod +x $binary
wrapProgram $binary --prefix PATH ":" ${z3}/bin
done
chmod +x $out/bin/fstar.exe
wrapProgram $out/bin/fstar.exe --prefix PATH ":" ${z3}/bin
remove-references-to -t '${ocamlPackages.ocaml}' $out/bin/fstar.exe

substituteInPlace $out/lib/ocaml/${ocamlPackages.ocaml.version}/site-lib/fstar/dune-package \
--replace ${fstar-dune} $out

cd $out
installShellCompletion --bash ${../.completion/bash/fstar.exe.bash}
installShellCompletion --fish ${../.completion/fish/fstar.exe.fish}
installShellCompletion --zsh --name _fstar.exe ${
../.completion/zsh/__fstar.exe
}
installShellCompletion --zsh --name _fstar.exe ${../.completion/zsh/__fstar.exe}
'';
}
45 changes: 45 additions & 0 deletions .nix/ocaml-snapshot.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
fstar,
lib,
ocamlPackages,
stdenv,
version,
}:
stdenv.mkDerivation {
pname = "fstar-ocaml-snapshot";
inherit version;

src = lib.cleanSourceWith {
src = ./..;
filter =
path: _:
let
relPath = lib.removePrefix (toString ./.. + "/") (toString path);
in
lib.any (lib.flip lib.hasPrefix relPath) [
"src"
"ulib"
]
|| (
lib.hasPrefix "ocaml" relPath
&& !(lib.hasInfix "/generated/" relPath)
&& !(lib.hasInfix "/dynamic/" relPath)
)
|| lib.hasSuffix ".common.mk" relPath;
};

postPatch = ''
mkdir -p bin
cp ${fstar}/bin/fstar.exe bin
cd src/ocaml-output
'';

nativeBuildInputs = with ocamlPackages; [
ocaml
menhir
];

installPhase = "mv ../../ocaml $out";

enableParallelBuilding = true;
}
21 changes: 15 additions & 6 deletions ulib/default.nix → .nix/ulib.nix
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
{ fstar-dune, lib, stdenv, version, z3 }:

{
fstar-dune,
lib,
stdenv,
version,
z3,
}:
stdenv.mkDerivation {
pname = "fstar-ulib";
inherit version;

src = lib.sourceByRegex ./.. [ "ulib.*" ".common.mk" ];
src = lib.sourceByRegex ./.. [
"ulib.*"
".common.mk"
];

nativeBuildInputs = [ z3 ];

postPatch = ''
mkdir -p bin
cp ${fstar-dune}/bin/fstar.exe bin
export PATH="$(pwd)/bin:${z3}/bin:$PATH"
patchShebangs ulib/install-ulib.sh
cd ulib
'';

enableParallelBuilding = true;
makeFlags = [ "PREFIX=$(out)" ];

preInstall = "export PREFIX=$out";
enableParallelBuilding = true;
}
11 changes: 0 additions & 11 deletions .nix/z3.nix

This file was deleted.

24 changes: 13 additions & 11 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading