Skip to content

Commit d595bc2

Browse files
committed
Add a doc entry for setting up an OxCaml project with dune pkg
Signed-off-by: Sudha Parimala <sudharg247@gmail.com>
1 parent d63da6b commit d595bc2

File tree

6 files changed

+103
-0
lines changed

6 files changed

+103
-0
lines changed

doc/tutorials/dune-package-management/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ setup
2424
dependencies
2525
pinning
2626
repos
27+
oxcaml
2728
:::
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(executable
2+
(public_name main))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(lang dune 3.20)
2+
3+
(package
4+
(name hello-oxcaml)
5+
(depends
6+
(ocaml-variants
7+
(= 5.2.0+ox))))
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(lang dune 3.20)
2+
3+
(repository
4+
(name oxcaml)
5+
(url git+https://github.com/oxcaml/opam-repository))
6+
7+
(lock_dir
8+
(repositories overlay oxcaml upstream))
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let () =
2+
let local_ i = 42 in
3+
let j = i + 1 in
4+
print_endline (Printf.sprintf "%d" j)
5+

0 commit comments

Comments
 (0)