Fil-C on Nix

Filnix wiki

mbrock/filnix

nanofil/nix/crane.nix

Crane (https://github.com/bloomberg/crane), Bloomberg's extraction of Rocq to C++, for the Gallina backend (rocq/backend/crane, docs/gallina-backend.md, M6). Pinned to one commit and patched (crane-nanofil.patch, whose parts the doc lists): Crane's own tree builds against Rocq 9.0, the backend against 9.1.

Only the plugin and the four theory files the backend's extraction imports are built. $out/lib/coq/9.1/user-contrib/Crane goes on ROCQPATH and $out/lib/ocaml/site-lib on OCAMLPATH; the headers the extracted C++ includes are in $out/include.

λpkgs
let
13coq=
pkgs.coqPackages_9_1
used by ocamlPackages
14ocamlPackages=
coq.coq.ocamlPackages
uses coq
in
pkgs.stdenv.mkDerivation
17pname=
"rocq-crane"
18version=
"0-unstable-c2aadd9"
19src=
pkgs.fetchFromGitHub
20owner=
"bloomberg"
21repo=
"crane"
22rev=
"c2aadd996f86425a486a1343d9cf2a1f5c4ed334"
23sha256=
"13a9n608hjknbqkwzi4imwc4kv50z95f5d4l58p9813hazsyqf6w"
26nativeBuildInputs=
coq.coq ocamlPackages.ocaml ocamlPackages.findlib ocamlPackages.dune_3
32buildInputs=
coq.stdlib

The theory's dune stanza names ITree, ExtLib and Paco, for files that are not built here.

35postPatch=
substituteInPlace theories/dune \
--replace-fail "(theories Stdlib ITree ExtLib Paco)" "(theories Stdlib)"
39buildPhase=
runHook preBuild
dune build -j "$NIX_BUILD_CORES" src \
theories/Extraction.vo theories/Mapping/Shared.vo theories/Mapping/Std.vo \
theories/Mapping/NatIntStd.vo theories/Mapping/AsciiChar.vo
runHook postBuild
46installPhase=
runHook preInstall
mkdir -p $out/lib/ocaml/site-lib $out/lib/coq/9.1/user-contrib/Crane $out/include
cp -rL _build/install/default/lib/rocq-crane $out/lib/ocaml/site-lib/
(cd _build/default/theories && find . -name '*.vo' -exec cp --parents {} $out/lib/coq/9.1/user-contrib/Crane/ \;)
cp theories/cpp/*.h $out/include/
runHook postInstall
54passthru=
inherit coq ocamlPackages;