-
Notifications
You must be signed in to change notification settings - Fork 455
Add a doc entry for setting up an OxCaml project with dune pkg #12780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,4 +24,5 @@ setup | |
| dependencies | ||
| pinning | ||
| repos | ||
| oxcaml | ||
| ::: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| # Setting up an OxCaml project | ||
|
|
||
| As an example of how to add custom repositories and pin dependencies in projects | ||
| using Dune Package Management, let's look at setting up a basic OxCaml project. | ||
| [OxCaml](https://oxcaml.org/) is a compiler branch with fast moving set of | ||
| extensions to OCaml. Some tweaks are required to set up a project that compiles | ||
| with OxCaml when using dune package management. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick but we should be consistent about how we capitalize Dune (and Dune package management). |
||
|
|
||
| ## Setting up the `dune-workspace` | ||
|
|
||
| OxCaml has a custom `opam-repository` that provides compatible dependencies. | ||
| This is specified in the `dune-workspace`. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sounds like the opam repository is configured in |
||
|
|
||
| ```{code-block} dune | ||
| (lang dune 3.20) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make this 3.21 |
||
|
|
||
| (pkg enabled) | ||
|
|
||
| (repository | ||
| (name oxcaml) | ||
| (url git+https://github.com/oxcaml/opam-repository)) | ||
|
|
||
| (lock_dir | ||
| (repositories overlay oxcaml upstream)) | ||
| ``` | ||
|
|
||
| In the `dune-project`, we also need to add a constraint to depend on the OxCaml | ||
| compiler. Otherwise, the solver may pick up the latest upstream compiler, which | ||
| does not support the OxCaml extensions. | ||
|
Comment on lines
+27
to
+29
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "We would like dune to pick the oxcaml compiler rather than the latest upstream one. This can be achieved by manually adding a constraint on the compiler that is picked in the |
||
|
|
||
| ```{code-block} dune | ||
| (lang dune 3.20) | ||
|
|
||
| (package | ||
| (name hello-oxcaml) | ||
| (depends | ||
| (ocaml-variants | ||
| (= 5.2.0+ox)))) | ||
| ``` | ||
|
|
||
| Let's add a test program that uses OxCaml syntax. | ||
|
|
||
| ::::{dropdown} `main.ml` | ||
| :icon: file-code | ||
|
|
||
| :::{literalinclude} oxcaml/main.ml | ||
| :language: dune | ||
| ::: | ||
|
|
||
| :::: | ||
|
|
||
| And to build it, we add a `dune` file. | ||
|
|
||
| ```{code-block} dune | ||
| (executable | ||
| (public_name main)) | ||
| ``` | ||
|
|
||
| ## Building the project | ||
|
|
||
| As usual, let's build the project with: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not assume users are used to the usual way of doing things here. Let's instead say, we can now build and execute our binary compiled with You should probably mention the passage of time here, since this step takes a while and dune atm doesn't give too much feedback.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. Unfortunately at the moment the compilation of OxCaml is glacial, partly because of limited concurrency but possibly also due to |
||
|
|
||
| ``` | ||
| $ dune exec ./main.exe | ||
| ... | ||
| 43 | ||
| ``` | ||
| We have successfully built the project with the OxCaml compiler and run the executable. | ||
|
|
||
| ## Developer tools | ||
|
|
||
| Note that OxCaml provides its own forks of the developer tools | ||
| `ocaml-lsp-server`, `ocamlformat`, etc. Make sure to include constraints for the | ||
| tools in the `dune-workspace` if you intend to use them for your development | ||
| workflows. | ||
Sudha247 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| For `ocamlformat` it would look something like this: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should add a warning that this configuration is likely to change in the future as our method for achieving this settles. Especially once the patches themselves are upstreamed. I think some prose explaining and linking the stanzas would also be a good idea.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be nice to document configuring dev-tools in general as part of #12756, then the resulting document could be linked here. |
||
|
|
||
| ```{code-block} dune | ||
|
|
||
| (lang dune 3.20) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lang 3.21 |
||
|
|
||
| (pkg enabled) | ||
|
|
||
| (repository | ||
| (name oxcaml) | ||
| (url "git+https://github.com/oxcaml/opam-repository")) | ||
|
|
||
| (pin | ||
| (name ocamlbuild) | ||
| (url "git+https://github.com/Sudha247/ocamlbuild#oxcaml+dune") | ||
shonfeder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| (package | ||
| (name ocamlbuild) | ||
| (version 0.15.0+ox))) | ||
|
|
||
| (pin | ||
| (name odoc-parser) | ||
| (url "git+https://github.com/Sudha247/odoc#replace-symlinks") | ||
| (package | ||
| (name odoc-parser) | ||
| (version 3.1.0+ox))) | ||
|
|
||
| (lock_dir | ||
| (path "dune.lock") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This path is probably optional. |
||
| (repositories :standard oxcaml)) | ||
|
|
||
| (lock_dir | ||
| (path "dev-tools.locks/ocamlformat") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This path needs to be adjusted now that #12671 is merged, it should be |
||
| (pins ocamlbuild) | ||
| (constraints | ||
| (ocaml-lsp-server (= 1.19.0+ox)) | ||
| (ocaml-variants (= 5.2.0+ox))) | ||
| (repositories overlay oxcaml upstream)) | ||
| ``` | ||
|
|
||
| Observe that this includes pins to dependencies `ocamlbuild` and `odoc-parser` as they are required by the OxCaml version of `ocamlformat`. | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,6 @@ | ||||||
| let () = | ||||||
| (* The `local_` keyword requires OxCaml *) | ||||||
| let local_ i = 42 in | ||||||
| let j = i + 1 in | ||||||
| print_endline (Printf.sprintf "%d" j) | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some newline issue here. |
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put the link on the mention of
OxCamljust before.