| 1 | # Beginner's guide to hacking Rocq |
| 2 | |
| 3 | ## Getting dependencies |
| 4 | |
| 5 | See the first section of [`INSTALL.md`](../../INSTALL.md). Developers are |
| 6 | recommended to use a recent OCaml version, which they can get through |
| 7 | opam or Nix, in particular. |
| 8 | |
| 9 | ## Configuring Dune caching and default verbosity |
| 10 | |
| 11 | There are several configuration settings that you can control globally |
| 12 | by creating a Dune configuration file (see `man dune-config` to learn |
| 13 | more). This file is generally located in `~/.config/dune/config` (this |
| 14 | is system-dependent). It should start with the version of the Dune |
| 15 | language used (by the configuration file---which can be different from |
| 16 | the one used in the Rocq repository), e.g.: |
| 17 | |
| 18 | ``` |
| 19 | (lang dune 2.0) |
| 20 | ``` |
| 21 | |
| 22 | - You will get faster rebuilds if you enable Dune caching. This is |
| 23 | true in all cases, but even more so when using the targets in |
| 24 | `Makefile` (see below). |
| 25 | |
| 26 | To set up Dune caching, you should append the following line to your |
| 27 | Dune configuration file: |
| 28 | |
| 29 | ``` |
| 30 | (cache enabled) |
| 31 | ``` |
| 32 | |
| 33 | Note that by default, Dune caching will use up to 10GB of disk size. |
| 34 | See the [official documentation](https://dune.readthedocs.io/en/stable/caching.html#on-disk-size) |
| 35 | to learn how to change the default. |
| 36 | |
| 37 | - Dune is not very verbose by default. If you want to change the |
| 38 | behavior to a more verbose one, you may append the following line to |
| 39 | your Dune configuration file: |
| 40 | |
| 41 | ``` |
| 42 | (display short) |
| 43 | ``` |
| 44 | |
| 45 | ## Building `rocq` binary |
| 46 | |
| 47 | We recommend that you use the targets in the `Makefile`. Calling `make` will |
| 48 | show the available targets. See [`build-system.dune.md`](build-system.dune.md) |
| 49 | to learn more about them. |
| 50 | |
| 51 | ``` |
| 52 | $ git clone https://github.com/rocq-prover/rocq.git |
| 53 | $ cd coq |
| 54 | $ make |
| 55 | # to get an idea of the available targets |
| 56 | $ make check |
| 57 | # build all OCaml files as fast as possible |
| 58 | $ make world |
| 59 | # build coq and the complete stdlib and setup it for use under _build/install/default |
| 60 | # In particular, you may run, e.g., coq_makefile from _build/install/default |
| 61 | # to build some test project |
| 62 | $ dune exec -- rocq test.v |
| 63 | # compile file test.v |
| 64 | # The "rocq" shim will be updated if needed, |
| 65 | # but not the worker binary and not the corelib .vo files |
| 66 | ``` |
| 67 | |
| 68 | When running the `make` targets above, you may set |
| 69 | `DUNEOPT=--display=short` for a more verbose build |
| 70 | (and use eg `dune exec --display=short -- rocq test.v` when calling dune directly) |
| 71 | (not required if you have already set the default verbosity globally |
| 72 | as described in the previous section). |
| 73 | |
| 74 | To learn how to run the test suite, you can read |
| 75 | [`test-suite/README.md`](../../test-suite/README.md). |
| 76 | |
| 77 | ## Rocq functions of interest |
| 78 | - `Coqtop.start`: This function is the main entry point of coqtop. |
| 79 | - `Coqtop.parse_args `: This function is responsible for parsing command-line arguments. |
| 80 | - `Coqloop.loop`: This function implements the read-eval-print loop. |
| 81 | - `Vernacentries.interp`: This function is called to execute the Vernacular command user have typed. |
| 82 | It dispatches the control to specific functions handling different Vernacular command. |
| 83 | - `Vernacentries.vernac_check_may_eval`: This function handles the `Check ...` command. |
| 84 | |
| 85 | |
| 86 | ## Development environment + tooling |
| 87 | |
| 88 | - [`Merlin`](https://github.com/ocaml/merlin) for autocomplete. |
| 89 | - [Wiki pages on tooling containing `emacs`, `vim`, and `git` information](https://github.com/rocq-prover/rocq/wiki/DevelSetup) |
| 90 | - [`ocamlformat`](https://github.com/ocaml-ppx/ocamlformat) provides |
| 91 | support for automatic formatting of OCaml code. To use it please run |
| 92 | `dune build @fmt`, see `ocamlformat`'s documentation for more help. |
| 93 | |
| 94 | ## A note about rlwrap |
| 95 | |
| 96 | When using `rlwrap rocq repl` make sure the version of `rlwrap` is at least |
| 97 | `0.42`, otherwise you will get |
| 98 | |
| 99 | ``` |
| 100 | rlwrap: error: Couldn't read completions from /usr/share/rlwrap/completions/coqtop: No such file or directory |
| 101 | ``` |
| 102 | |
| 103 | If this happens either update or use an alternate readline wrapper like `ledit`. |