This commit is contained in:
swrup 2025-11-11 02:07:51 +01:00
parent aa2ff7b2f0
commit 2f3113f55d
11742 changed files with 1223940 additions and 0 deletions

View file

@ -0,0 +1,10 @@
# Sample dune-coq project
This is a simple dune build which has 2 projects:
1. `example-ocaml` - simple pure OCaml library
2. `example-coq` - simple OCaml library extracted from Coq
In addition to Coq to OCaml extraction, it also demonstrates a
workaround for long-standing Coq [issue](https://github.com/coq/coq/issues/6614) and until it is fixed
could be used as a template for dune projects using Coq extraction.

View file

@ -0,0 +1 @@
Definition foo (_:unit) : nat := 42.

View file

@ -0,0 +1,5 @@
(coq.theory
(mode vo)
(name Common)
(package example-coq)
(modules Foo))

View file

@ -0,0 +1,2 @@
-R . ""
-R Common/ Common

View file

@ -0,0 +1,20 @@
(rule
(deps extracted/CRelationClasses.mli.patch extracted/patch.sh)
(package example-coq)
(target CRelationClasses.mli)
(action
(with-stdout-to
%{target}
(run %{dep:extracted/patch.sh} %{dep:extracted/CRelationClasses.mli}))))
(copy_files extracted/CRelationClasses.ml)
(copy_files extracted/Datatypes.{ml,mli})
(copy_files extracted/Foo.{ml,mli})
(library
(name extracted)
(public_name example-coq.coq)
(modules (:standard))
(libraries zarith coq-core.kernel)
(wrapped false)
(flags (:standard -rectypes -w -27-32-33-39-67-37-20-34)))

View file

@ -0,0 +1,11 @@
--- ml/extracted/CRelationClasses.mli 2018-10-08 20:41:02.000000000 -0700
+++ CRelationClasses.mli 2018-10-08 20:41:05.000000000 -0700
@@ -104,7 +104,7 @@
val flip_Equivalence :
('a1, 'a2) coq_Equivalence -> ('a1, 'a2) coq_Equivalence
-val eq_equivalence : ('a1, __) coq_Equivalence
+val eq_equivalence : (__, __) coq_Equivalence
val iff_equivalence : (__, __) coq_Equivalence

View file

@ -0,0 +1,25 @@
Require Import Common.Foo.
Require Import Coq.Classes.CRelationClasses.
From Coq Require Extraction.
Require ExtrOcamlBasic.
Require ExtrOcamlChar.
Require ExtrOcamlNativeString.
Require ExtrOCamlFloats.
Require ExtrOCamlInt63.
Require Import ExtrOcamlNatBigInt.
Require Import ExtrOcamlZBigInt.
Extraction Language OCaml.
Unset Extraction Optimize.
Extraction Blacklist String List Char Core Monad Bool Vector Format Nat Int Option Base Numbers FMapAVL OrderedType Map.
(* Used by Coq's Real library *)
Extract Constant ClassicalDedekindReals.sig_forall_dec => "fun _ -> assert false".
Extract Constant ClassicalDedekindReals.sig_not_dec => false. (* Ugh *)
Recursive Extraction Library Foo.
Recursive Extraction Library CRelationClasses.

View file

@ -0,0 +1,7 @@
(coq.extraction
(mode vo)
(prelude Extract)
(extracted_modules Foo CRelationClasses Datatypes)
(theories Common)
(flags -w -extraction-opaque-accessed))

View file

@ -0,0 +1,3 @@
#!/bin/sh
patch -p0 -r 0 -s --read-only=ignore --follow-symlinks -o - $1 -i extracted/CRelationClasses.mli.patch

View file

@ -0,0 +1,3 @@
(dirs coq ml)

View file

@ -0,0 +1,3 @@
(lang dune 3.8)
(name example)
(using coq 0.8)

View file

@ -0,0 +1 @@
let bar (_:unit) = 24

View file

@ -0,0 +1,6 @@
(library
(name bar)
(public_name example-ocaml.bar)
(modules bar)
(wrapped false)
(flags (:standard -rectypes -w -27-32-33-39-67-37-20-34)))

View file

@ -0,0 +1,123 @@
Testing for https://github.com/ocaml/dune/issues/9818
We first test the package builds as normal, when both are in scope:
$ dune build -p example-ocaml
$ dune build -p example-coq
$ cat example-ocaml.install
lib: [
"_build/install/default/lib/example-ocaml/META"
"_build/install/default/lib/example-ocaml/bar/bar.a" {"bar/bar.a"}
"_build/install/default/lib/example-ocaml/bar/bar.cma" {"bar/bar.cma"}
"_build/install/default/lib/example-ocaml/bar/bar.cmi" {"bar/bar.cmi"}
"_build/install/default/lib/example-ocaml/bar/bar.cmt" {"bar/bar.cmt"}
"_build/install/default/lib/example-ocaml/bar/bar.cmx" {"bar/bar.cmx"}
"_build/install/default/lib/example-ocaml/bar/bar.cmxa" {"bar/bar.cmxa"}
"_build/install/default/lib/example-ocaml/bar/bar.ml" {"bar/bar.ml"}
"_build/install/default/lib/example-ocaml/dune-package"
"_build/install/default/lib/example-ocaml/opam"
]
libexec: [
"_build/install/default/lib/example-ocaml/bar/bar.cmxs" {"bar/bar.cmxs"}
]
doc: [
"_build/install/default/doc/example-ocaml/README.md"
]
$ cat example-coq.install
lib: [
"_build/install/default/lib/example-coq/META"
"_build/install/default/lib/example-coq/coq/CRelationClasses.ml" {"coq/CRelationClasses.ml"}
"_build/install/default/lib/example-coq/coq/CRelationClasses.mli" {"coq/CRelationClasses.mli"}
"_build/install/default/lib/example-coq/coq/Datatypes.ml" {"coq/Datatypes.ml"}
"_build/install/default/lib/example-coq/coq/Datatypes.mli" {"coq/Datatypes.mli"}
"_build/install/default/lib/example-coq/coq/Foo.ml" {"coq/Foo.ml"}
"_build/install/default/lib/example-coq/coq/Foo.mli" {"coq/Foo.mli"}
"_build/install/default/lib/example-coq/coq/cRelationClasses.cmi" {"coq/cRelationClasses.cmi"}
"_build/install/default/lib/example-coq/coq/cRelationClasses.cmt" {"coq/cRelationClasses.cmt"}
"_build/install/default/lib/example-coq/coq/cRelationClasses.cmti" {"coq/cRelationClasses.cmti"}
"_build/install/default/lib/example-coq/coq/cRelationClasses.cmx" {"coq/cRelationClasses.cmx"}
"_build/install/default/lib/example-coq/coq/datatypes.cmi" {"coq/datatypes.cmi"}
"_build/install/default/lib/example-coq/coq/datatypes.cmt" {"coq/datatypes.cmt"}
"_build/install/default/lib/example-coq/coq/datatypes.cmti" {"coq/datatypes.cmti"}
"_build/install/default/lib/example-coq/coq/datatypes.cmx" {"coq/datatypes.cmx"}
"_build/install/default/lib/example-coq/coq/extracted.a" {"coq/extracted.a"}
"_build/install/default/lib/example-coq/coq/extracted.cma" {"coq/extracted.cma"}
"_build/install/default/lib/example-coq/coq/extracted.cmxa" {"coq/extracted.cmxa"}
"_build/install/default/lib/example-coq/coq/foo.cmi" {"coq/foo.cmi"}
"_build/install/default/lib/example-coq/coq/foo.cmt" {"coq/foo.cmt"}
"_build/install/default/lib/example-coq/coq/foo.cmti" {"coq/foo.cmti"}
"_build/install/default/lib/example-coq/coq/foo.cmx" {"coq/foo.cmx"}
"_build/install/default/lib/example-coq/dune-package"
"_build/install/default/lib/example-coq/opam"
]
lib_root: [
"_build/install/default/lib/coq/user-contrib/Common/Foo.glob" {"coq/user-contrib/Common/Foo.glob"}
"_build/install/default/lib/coq/user-contrib/Common/Foo.v" {"coq/user-contrib/Common/Foo.v"}
"_build/install/default/lib/coq/user-contrib/Common/Foo.vo" {"coq/user-contrib/Common/Foo.vo"}
]
libexec: [
"_build/install/default/lib/example-coq/coq/extracted.cmxs" {"coq/extracted.cmxs"}
]
doc: [
"_build/install/default/doc/example-coq/README.md"
]
$ cp example-ocaml.install example-ocaml.install.old
$ dune clean
We now test that the ocaml package still builds even when Coq rules can't be setup:
$ mkdir _path
$ ln -s $(command -v dune) _path/
$ ln -s $(command -v ocamlc) _path/
$ ln -s $(command -v ocamldep) _path/
$ (unset INSIDE_DUNE; PATH=_path dune build -p example-ocaml)
$ cat example-ocaml.install
lib: [
"_build/install/default/lib/example-ocaml/META"
"_build/install/default/lib/example-ocaml/bar/bar.cma" {"bar/bar.cma"}
"_build/install/default/lib/example-ocaml/bar/bar.cmi" {"bar/bar.cmi"}
"_build/install/default/lib/example-ocaml/bar/bar.cmt" {"bar/bar.cmt"}
"_build/install/default/lib/example-ocaml/bar/bar.ml" {"bar/bar.ml"}
"_build/install/default/lib/example-ocaml/dune-package"
"_build/install/default/lib/example-ocaml/opam"
]
doc: [
"_build/install/default/doc/example-ocaml/README.md"
]
$ diff -u --label install_old example-ocaml.install.old --label install_new example-ocaml.install
--- install_old
+++ install_new
@@ -1,18 +1,12 @@
lib: [
"_build/install/default/lib/example-ocaml/META"
- "_build/install/default/lib/example-ocaml/bar/bar.a" {"bar/bar.a"}
"_build/install/default/lib/example-ocaml/bar/bar.cma" {"bar/bar.cma"}
"_build/install/default/lib/example-ocaml/bar/bar.cmi" {"bar/bar.cmi"}
"_build/install/default/lib/example-ocaml/bar/bar.cmt" {"bar/bar.cmt"}
- "_build/install/default/lib/example-ocaml/bar/bar.cmx" {"bar/bar.cmx"}
- "_build/install/default/lib/example-ocaml/bar/bar.cmxa" {"bar/bar.cmxa"}
"_build/install/default/lib/example-ocaml/bar/bar.ml" {"bar/bar.ml"}
"_build/install/default/lib/example-ocaml/dune-package"
"_build/install/default/lib/example-ocaml/opam"
]
-libexec: [
- "_build/install/default/lib/example-ocaml/bar/bar.cmxs" {"bar/bar.cmxs"}
-]
doc: [
"_build/install/default/doc/example-ocaml/README.md"
]
[1]
Coq package should fail:
$ (unset INSIDE_DUNE; PATH=_path dune build -p example-coq)
Couldn't find Coq standard library, and theory is not using (stdlib no)
-> required by _build/default/coq/Common/Foo.glob
-> required by _build/install/default/lib/coq/user-contrib/Common/Foo.glob
-> required by _build/default/example-coq.install
-> required by alias install
[1]
$ cat example-coq.install
cat: example-coq.install: No such file or directory
[1]