1- # Example: Setting up an OxCaml project
1+ # Setting up an OxCaml project
22
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.
3+ As an example of how to add custom repositories and pin dependencies in projects
4+ using ` dune pkg ` , let's look at setting up a basic OxCaml project.
5+ [ OxCaml] ( https://oxcaml.org/ ) is a compiler branch with fast moving set of
6+ extensions to OCaml. Some tweaks are required to set up a project that compiles
7+ with OxCaml when using dune package management.
78
8- ## Setting up the workspace
9+ ## Setting up the ` dune- workspace`
910
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 ` .
11+ OxCaml has a custom ` opam-repository ` that provides compatible dependencies.
12+ This is specified in the ` dune-workspace ` .
1213
13- ::::{dropdown} ` dune-workspace `
14- :icon: file-code
14+ ``` {code-block} dune
15+ (lang dune 3.20)
1516
16- :::{literalinclude} oxcaml/dune-workspace
17- :language: dune
18- :emphasize-lines: 3-5
19- :::
17+ (pkg enabled)
2018
21- ::::
19+ (repository
20+ (name oxcaml)
21+ (url git+https://github.com/oxcaml/opam-repository))
22+
23+ (lock_dir
24+ (repositories overlay oxcaml upstream))
25+ ```
2226
2327In the ` dune-project ` , we also need to add a constraint to depend on the OxCaml
2428compiler. Otherwise, the solver may pick up the latest upstream compiler, which
2529does not support the OxCaml extensions.
2630
27- ::::{dropdown} ` dune-project `
28- :icon: file-code
29-
30- :::{literalinclude} oxcaml/dune-project
31- :language: dune
32- :::
31+ ``` {code-block} dune
32+ (lang dune 3.20)
3333
34- ::::
34+ (package
35+ (name hello-oxcaml)
36+ (depends
37+ (ocaml-variants
38+ (= 5.2.0+ox))))
39+ ```
3540
3641Let's add a test program that uses OxCaml syntax.
3742
@@ -46,35 +51,66 @@ Let's add a test program that uses OxCaml syntax.
4651
4752And to build it, we add a ` dune ` file.
4853
49- ::::{dropdown} ` dune `
50- :icon: file-code
51-
52- :::{literalinclude} oxcaml/dune
53- :language: dune
54- :::
55-
56- ::::
54+ ``` {code-block} dune
55+ (executable
56+ (public_name main))
57+ ```
5758
5859## Building the project
5960
60- As usual, let's lock the dependencies and build the project with:
61+ As usual, let's build the project with:
6162
6263```
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
64+ $ dune exec ./main.exe
7065...
716643
7267```
73- We have successfully built the project with the OxCaml compiler.
68+ We have successfully built the project with the OxCaml compiler and run the executable .
7469
7570## Developer tools
7671
7772Note that OxCaml provides its own forks of the developer tools
7873` ocaml-lsp-server ` , ` ocamlformat ` , etc. Make sure to include constraints for the
7974tools in the ` dune-workspace ` if you intend to use them for your development
8075workflows.
76+
77+ For ` ocamlformat ` it would look something like this:
78+
79+ ``` {code-block} dune
80+
81+ (lang dune 3.20)
82+
83+ (pkg enabled)
84+
85+ (repository
86+ (name oxcaml)
87+ (url "git+https://github.com/oxcaml/opam-repository"))
88+
89+ (pin
90+ (name ocamlbuild)
91+ (url "git+https://github.com/Sudha247/ocamlbuild#oxcaml+dune")
92+ (package
93+ (name ocamlbuild)
94+ (version 0.15.0+ox)))
95+
96+ (pin
97+ (name odoc-parser)
98+ (url "git+https://github.com/Sudha247/odoc#replace-symlinks")
99+ (package
100+ (name odoc-parser)
101+ (version 3.1.0+ox)))
102+
103+ (lock_dir
104+ (path "dune.lock")
105+ (repositories :standard oxcaml))
106+
107+ (lock_dir
108+ (path "dev-tools.locks/ocamlformat")
109+ (pins ocamlbuild)
110+ (constraints
111+ (ocaml-lsp-server (= 1.19.0+ox))
112+ (ocaml-variants (= 5.2.0+ox)))
113+ (repositories overlay oxcaml upstream))
114+ ```
115+
116+ Observe that this includes pins to dependencies ` ocamlbuild ` and ` odoc-parser ` as they are required by the OxCaml version of ` ocamlformat ` .
0 commit comments