Skip to content

Commit 181555d

Browse files
authored
Merge pull request #3210 from ejgallego/coq+native
[coq] Add support for native-mode compilation.
2 parents 51fc74e + 454dae6 commit 181555d

31 files changed

+329
-60
lines changed

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ Unreleased
9191

9292
- [coq] Add `-q` flag to `:standard` `coqc` flags , fixes #3924, (#3931 , @ejgallego)
9393

94+
- Add support for Coq's native compute compilation mode (@ejgallego, #3210)
95+
9496
2.7.1 (2/09/2020)
9597
-----------------
9698

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ BIN := ./dune.exe
1111
TEST_DEPS := \
1212
bisect_ppx \
1313
cinaps \
14-
coq \
14+
"coq>=8.12.1" \
1515
core_bench \
1616
"csexp>=1.3.0" \
1717
js_of_ocaml \

doc/dune-files.rst

+15-3
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,7 @@ The basic form for defining Coq libraries is very similar to the OCaml form:
16251625
(modules <ordered_set_lang>)
16261626
(libraries <ocaml_libraries>)
16271627
(flags <coq_flags>)
1628+
(mode <coq_native_mode>)
16281629
(theories <coq_theories>))
16291630
16301631
The stanza will build all ``.v`` files on the given directory. The semantics of fields is:
@@ -1668,6 +1669,17 @@ The stanza will build all ``.v`` files on the given directory. The semantics of
16681669
composition with the Coq's standard library is supported, but in
16691670
this case the ``Coq`` prefix will be made available in a qualified
16701671
way. Since Coq's lang version ``0.2``.
1672+
- you can enable the production of Coq's native compiler object files
1673+
by setting ``<coq_native_mode>`` to ``native``, this will pass
1674+
``-native-compiler on`` to Coq and install the corresponding object
1675+
files under `.coq-native`. Note that the support for native compute
1676+
is **experimental**, and requires Coq >= 8.12.1; moreover, depending
1677+
libraries *must* be built with ``(mode native)`` too for this to
1678+
work; also Coq must be configured to support native
1679+
compilation. Note that Dune will by explicitly disable output of
1680+
native compilation objects when `(mode vo)` even if the default
1681+
Coq's configure flag enabled it. This will be improved in the
1682+
future.
16711683

16721684
Recursive qualification of modules
16731685
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1899,9 +1911,9 @@ a typical ``dune-workspace`` file looks like:
18991911
.. code:: scheme
19001912
19011913
(lang dune 2.8)
1902-
(context (opam (switch 4.02.3)))
1903-
(context (opam (switch 4.03.0)))
1904-
(context (opam (switch 4.04.0)))
1914+
(context (opam (switch 4.07.1)))
1915+
(context (opam (switch 4.08.1)))
1916+
(context (opam (switch 4.11.1)))
19051917
19061918
The rest of this section describe the stanzas available.
19071919

src/dune_rules/coq_lib.ml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ open! Dune_engine
22

33
(* This file is licensed under The MIT License *)
44
(* (c) MINES ParisTech 2018-2019 *)
5+
(* (c) INRIA 2020 *)
56
(* Written by: Emilio Jesús Gallego Arias *)
67

78
open! Stdune

src/dune_rules/coq_lib_name.mli

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ open! Dune_engine
22

33
(* This file is licensed under The MIT License *)
44
(* (c) MINES ParisTech 2018-2019 *)
5+
(* (c) INRIA 2020 *)
56
(* Written by: Emilio Jesús Gallego Arias *)
67

78
open! Stdune

src/dune_rules/coq_mode.ml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(* This file is licensed under The MIT License *)
2+
(* (c) MINES ParisTech 2018-2019 *)
3+
(* (c) INRIA 2020 *)
4+
(* Written by: Emilio Jesús Gallego Arias *)
5+
6+
type t =
7+
| VoOnly
8+
| Native
9+
10+
let decode = Dune_lang.Decoder.(enum [ ("vo", VoOnly); ("native", Native) ])

src/dune_rules/coq_mode.mli

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(* This file is licensed under The MIT License *)
2+
(* (c) MINES ParisTech 2018-2019 *)
3+
(* (c) INRIA 2020 *)
4+
(* Written by: Emilio Jesús Gallego Arias *)
5+
6+
type t =
7+
| VoOnly
8+
| Native
9+
10+
val decode : t Dune_lang.Decoder.t

src/dune_rules/coq_module.ml

+39-17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ open! Dune_engine
22

33
(* This file is licensed under The MIT License *)
44
(* (c) MINES ParisTech 2018-2019 *)
5+
(* (c) INRIA 2020 *)
56
(* Written by: Emilio Jesús Gallego Arias *)
67

78
open! Stdune
@@ -39,23 +40,44 @@ let name x = x.name
3940
let build_vo_dir ~obj_dir x =
4041
List.fold_left x.prefix ~init:obj_dir ~f:Path.Build.relative
4142

42-
type obj =
43-
| Dep
44-
| Aux
45-
| Glob
46-
| Obj
47-
48-
let fname_of_obj t obj =
49-
match obj with
50-
| Dep -> t.name ^ ".v.d"
51-
| Aux -> "." ^ t.name ^ ".aux"
52-
| Glob -> t.name ^ ".glob"
53-
| Obj -> t.name ^ ".vo"
54-
55-
let obj_file t obj ~obj_dir =
56-
let vo_dir = build_vo_dir ~obj_dir t in
57-
let fname = fname_of_obj t obj in
58-
Path.Build.relative vo_dir fname
43+
let cmxs_of_mod ~wrapper_name x =
44+
let native_base =
45+
"N" ^ String.concat ~sep:"_" ((wrapper_name :: x.prefix) @ [ x.name ])
46+
in
47+
[ native_base ^ ".cmi"; native_base ^ ".cmxs" ]
48+
49+
let dep_file x ~obj_dir =
50+
let vo_dir = build_vo_dir ~obj_dir x in
51+
Path.Build.relative vo_dir (x.name ^ ".v.d")
52+
53+
type obj_files_mode =
54+
| Build
55+
| Install
56+
57+
(* XXX: Remove the install .coq-native hack once rules can output targets in
58+
multiple subdirs *)
59+
let obj_files x ~wrapper_name ~mode ~obj_dir ~obj_files_mode =
60+
let vo_dir = build_vo_dir ~obj_dir x in
61+
let install_vo_dir = String.concat ~sep:"/" x.prefix in
62+
let native_objs =
63+
match mode with
64+
| Coq_mode.Native ->
65+
let cmxs_obj = cmxs_of_mod ~wrapper_name x in
66+
List.map
67+
~f:(fun x ->
68+
( Path.Build.relative vo_dir x
69+
, Filename.(concat (concat install_vo_dir ".coq-native") x) ))
70+
cmxs_obj
71+
| VoOnly -> []
72+
in
73+
let obj_files =
74+
match obj_files_mode with
75+
| Build -> [ x.name ^ ".vo"; "." ^ x.name ^ ".aux"; x.name ^ ".glob" ]
76+
| Install -> [ x.name ^ ".vo" ]
77+
in
78+
List.map obj_files ~f:(fun fname ->
79+
(Path.Build.relative vo_dir fname, Filename.concat install_vo_dir fname))
80+
@ native_objs
5981

6082
let to_dyn { source; prefix; name } =
6183
let open Dyn.Encoder in

src/dune_rules/coq_module.mli

+17-7
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,23 @@ val prefix : t -> string list
3838

3939
val name : t -> Name.t
4040

41-
type obj =
42-
| Dep
43-
| Aux
44-
| Glob
45-
| Obj
46-
47-
val obj_file : t -> obj -> obj_dir:Path.Build.t -> Path.Build.t
41+
val dep_file : t -> obj_dir:Path.Build.t -> Path.Build.t
42+
43+
(** Some of the object files should not be installed, we control this with the
44+
following parameter *)
45+
type obj_files_mode =
46+
| Build
47+
| Install
48+
49+
(** This returns a list of pairs [(obj_file, install_path)] due to native files
50+
having a different install location *)
51+
val obj_files :
52+
t
53+
-> wrapper_name:string
54+
-> mode:Coq_mode.t
55+
-> obj_dir:Path.Build.t
56+
-> obj_files_mode:obj_files_mode
57+
-> (Path.Build.t * string) list
4858

4959
val to_dyn : t -> Dyn.t
5060

0 commit comments

Comments
 (0)