|
| 1 | +# Example: Setting up an OxCaml project |
| 2 | + |
| 3 | +As an example to adding custom repositories and pinning projects, let's look at |
| 4 | +setting up a basic OxCaml project. [OxCaml](https://oxcaml.org/) is a compiler |
| 5 | +branch with fast moving set of extenstions to OCaml. Some tweaks are required to |
| 6 | +set up an OxCaml project with dune package management. |
| 7 | + |
| 8 | +## Setting up the workspace |
| 9 | + |
| 10 | +OxCaml has a custom `opam-repository` that we need in order to pull in its |
| 11 | +dependencies. This is specified in the `dune-workspace`. |
| 12 | + |
| 13 | +::::{dropdown} `dune-workspace` |
| 14 | +:icon: file-code |
| 15 | + |
| 16 | +:::{literalinclude} oxcaml/dune-workspace |
| 17 | +:language: dune |
| 18 | +:emphasize-lines: 3-5 |
| 19 | +::: |
| 20 | + |
| 21 | +:::: |
| 22 | + |
| 23 | +In the `dune-project`, we also need to add a constraint to depend on the OxCaml |
| 24 | +compiler. Otherwise, the solver may pick up the latest upstream compiler, which |
| 25 | +does not support the OxCaml extensions. |
| 26 | + |
| 27 | +::::{dropdown} `dune-project` |
| 28 | +:icon: file-code |
| 29 | + |
| 30 | +:::{literalinclude} oxcaml/dune-project |
| 31 | +:language: dune |
| 32 | +::: |
| 33 | + |
| 34 | +:::: |
| 35 | + |
| 36 | +Let's add a test program that uses OxCaml syntax. |
| 37 | + |
| 38 | +::::{dropdown} `main.ml` |
| 39 | +:icon: file-code |
| 40 | + |
| 41 | +:::{literalinclude} oxcaml/main.ml |
| 42 | +:language: dune |
| 43 | +::: |
| 44 | + |
| 45 | +:::: |
| 46 | + |
| 47 | +And to build it, we add a `dune` file. |
| 48 | + |
| 49 | +::::{dropdown} `dune` |
| 50 | +:icon: file-code |
| 51 | + |
| 52 | +:::{literalinclude} oxcaml/dune |
| 53 | +:language: dune |
| 54 | +::: |
| 55 | + |
| 56 | +:::: |
| 57 | + |
| 58 | +## Building the project |
| 59 | + |
| 60 | +As usual, let's lock the dependencies and build the project with: |
| 61 | + |
| 62 | +``` |
| 63 | +$ dune pkg lock |
| 64 | +Solution for dune.lock: |
| 65 | +- conf-autoconf.0.2 |
| 66 | +- conf-which.1 |
| 67 | +- ocaml-variants.5.2.0+ox |
| 68 | +
|
| 69 | +$ dune build && dune exec ./main.exe |
| 70 | +... |
| 71 | +43 |
| 72 | +``` |
| 73 | +We have successfully built the project with the OxCaml compiler. |
| 74 | + |
| 75 | +## Developer tools |
| 76 | + |
| 77 | +Note that OxCaml provides its own forks of the developer tools |
| 78 | +`ocaml-lsp-server`, `ocamlformat`, etc. Make sure to include constraints for the |
| 79 | +tools in the `dune-workspace` if you intend to use them for your development |
| 80 | +workflows. |
0 commit comments