-
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?
Conversation
|
The main title doesn't need to say |
shonfeder
left a comment
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.
Glad to have this included!
65b4bc6 to
64d39ec
Compare
|
At some point these how-to's turned into markdown rather than being rst documents which is slightly confusing. In rst we have syntax highlighting for dune files etc. Does anybody remember why markdown was chosen for these? I would suggest writing this tutorial in rst, not only for consistency, but because it will play better with cross-linking that we have elsewhere in the docs. |
Signed-off-by: Sudha Parimala <[email protected]>
Signed-off-by: Sudha Parimala <[email protected]>
64d39ec to
135bb8e
Compare
Signed-off-by: Sudha Parimala <[email protected]>
135bb8e to
9f8c4b7
Compare
I'm not opposed to doing this, but wouldn't be weird if only one of the dune-package-management entries is in rst, while others are in markdown? |
|
Ideally they should be all in rst, but would blow this PR out of scope. If you think it would be too much work to do in this PR, let's instead create an issue so that we remember to do it eventually. I won't block on this point. |
|
Ah, I dug a bit around and it is because of this PR by @emillon where he notes:
Which all sound like pretty decent points. |
|
|
||
| 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 |
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 OxCaml just before.
| ## Setting up the `dune-workspace` | ||
|
|
||
| OxCaml has a custom `opam-repository` that provides compatible dependencies. | ||
| This is specified in the `dune-workspace`. |
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.
This sounds like the opam repository is configured in dune-workspace. I would probably say something like: Dune can use packages from this repositories by configuring it in the dune-workspace file using the repository (link) and lock_dir (link) stanzas.
| This is specified in the `dune-workspace`. | ||
|
|
||
| ```{code-block} dune | ||
| (lang dune 3.20) |
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.
Let's make this 3.21
| 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. |
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.
"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 package stanza (link) in the dune-project.
|
|
||
| ## Building the project | ||
|
|
||
| As usual, let's build the project with: |
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.
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 OxCaml. We use the dune exec command which will first build all the packages we need, including the OxCaml compiler and then builds our binary and runs it.
You should probably mention the passage of time here, since this step takes a while and dune atm doesn't give too much feedback.
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.
Agreed. Unfortunately at the moment the compilation of OxCaml is glacial, partly because of limited concurrency but possibly also due to flambda being enabled. The former we can fix with #12737, the latter is outside of our control.
|
|
||
| ```{code-block} dune | ||
|
|
||
| (lang dune 3.20) |
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.
lang 3.21
| tools in the `dune-workspace` if you intend to use them for your development | ||
| workflows. | ||
|
|
||
| For `ocamlformat` it would look something like this: |
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.
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.
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 think it would be nice to document configuring dev-tools in general as part of #12756, then the resulting document could be linked here.
| As an example to adding custom repositories and pinning projects, let's look at | ||
| setting up a basic OxCaml project. [OxCaml](https://oxcaml.org/) is a compiler | ||
| branch with fast moving set of extenstions to OCaml. Some tweaks are required to | ||
| set up an OxCaml project with dune package management. |
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.
| set up an OxCaml project with dune package management. | |
| set up an OxCaml project with Dune package management. |
|
|
||
| As an example to adding custom repositories and pinning projects, let's look at | ||
| setting up a basic OxCaml project. [OxCaml](https://oxcaml.org/) is a compiler | ||
| branch with fast moving set of extenstions to OCaml. Some tweaks are required to |
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.
| branch with fast moving set of extenstions to OCaml. Some tweaks are required to | |
| branch with fast moving set of extensions to OCaml. Some tweaks are required to |
| tools in the `dune-workspace` if you intend to use them for your development | ||
| workflows. | ||
|
|
||
| For `ocamlformat` it would look something like this: |
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 think it would be nice to document configuring dev-tools in general as part of #12756, then the resulting document could be linked here.
| 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. |
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.
Nitpick but we should be consistent about how we capitalize Dune (and Dune package management).
|
|
||
| ## Building the project | ||
|
|
||
| As usual, let's build the project with: |
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.
Agreed. Unfortunately at the moment the compilation of OxCaml is glacial, partly because of limited concurrency but possibly also due to flambda being enabled. The former we can fix with #12737, the latter is outside of our control.
| (version 3.1.0+ox))) | ||
|
|
||
| (lock_dir | ||
| (path "dune.lock") |
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.
This path is probably optional.
| (repositories :standard oxcaml)) | ||
|
|
||
| (lock_dir | ||
| (path "dev-tools.locks/ocamlformat") |
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.
This path needs to be adjusted now that #12671 is merged, it should be "_build/.dev-tools.locks/ocamlformat"
| let local_ i = 42 in | ||
| let j = i + 1 in | ||
| print_endline (Printf.sprintf "%d" j) | ||
|
No newline at end of file |
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.
Some newline issue here.
| (* The `local_` keyword requires OxCaml *) | ||
| let local_ i = 42 in | ||
| let j = i + 1 in | ||
| print_endline (Printf.sprintf "%d" j) |
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.
| print_endline (Printf.sprintf "%d" j) | |
| Printf.printf "%d\n" j |
|
We also have a macros for the latest dune lang version which might be sensible to use. |

Closes #11652
Adds a tutorial for setting up an OxCaml project with Dune package management.
I contemplated where this should go, and thought this might be a good place, after all. It shows (1) how to setup an OxCaml project, (2) servers as a live example of the previous two tutorials.
#12111 is a more comprehensive tutorial about parametric libraries and OxCaml, but it doesn't specifically cover the topic of Dune package management with OxCaml. I recently ported an OxCaml project to build with Dune package management and the configuration was not as straightforward as I expected, and thought a tutorial on this topic might be useful.
This takes some material from https://github.com/gridbugs/hello-oxcaml (thanks @gridbugs!).