dune
dune copied to clipboard
[pkg] Build OxCaml with Dune package management
This issue will serve as a meta issue to describe the changes required to build OxCaml with Dune package management.
Currently, I have trying to build it using @gridbugs small repository, hello-oxcaml. The locking happens correctly, but the build encounters various errors:
- Building the
init-compilerrequires it to be added totoolchainssupported list. Otherwise, as it is not relocatable, it will suffer the same problem as the compiler. - The
init-*.pkguse the%{prefix}variable, which is causing a problem with Dune Package Management because it points to the_build/.sanbox/...path. We extend the path with the dependencies instead of having a global state asopamwould do. The semantic of%{prefix}is not really clear for me in this context. I'm not confident it has one. - If we change the path using
%{pkg:init-compiler:share}in theinit-*.pkglock files, we are able to build it to a findable path. However, when doing the variable expansion in other*.pkgfiles (which updates thePATHaccordingly), it is not using the path within toolchains but the one within the_builddirectory. I'm writing a test to reproduce this error. - In the final stage, when building the
ocaml-variantspackage (after buildinginit-*packages), it fails because of the problem discovered in #11514. Indeed,(run autoconf)generates aconfigurebut it can't be executed.
I have been discussing with @rgrinberg on how to make Dune Package Management worked with OxCaml and more broadly on how to generalize it to support non-relocatable packages.
I'll update the issue to point to the various resources and changes.
The opam packaging has been designed to work well for opam - in particular to allow OxCaml to be updated without having to rebuild all the constituent parts.
The obvious Dune fit would be to building OxCaml in a separate build context (i.e. compiling the Dune stage of OxCaml in a build context which has the correct compiler). I'm wondering (= quite strongly recommending) not adding features to dune pkg just to support the init-* packages, but rather how about looking at refactoring the packages themselves so that OxCaml is installable as a single package in the first instance?
Just as a proof-of-concept for simplifying:
--- a/dune-workspace
+++ b/dune-workspace
@@ -2,7 +2,7 @@
(repository
(name jst)
- (url git+https://github.com/janestreet/opam-repository#with-extensions))
+ (url git+https://github.com/dra27/opam-repository#with-extensions-dp))
(lock_dir
(repositories upstream overlay jst))
and then:
$ dune --version
"Dune Developer Preview: build 2025-04-26, git revision
1a0d3646a365210cb42a4366cb3a026b4c8928e3"
$ dune pkg lock
$ time dune build
Downloading ocaml-variants.5.2.0+flambda2
Building ocaml-variants.5.2.0+flambda2
real 12m59.186s
The first build is taking an inordinately long time[^1], but the caching is definitely working after that:
$ git clean -dfX
$ time dune build
Building ocaml-variants.5.2.0+flambda2
real 0m1.483s
[^1]: I haven't figured out what's going on, but my hunch is it's a failure to detect the appropriate parallelism in the "internal" Dune call in OxCaml's build: forcing a higher -j brought the first-time build down to the ~6minutes that an opam switch switch with the same package was taking.
+1 to modifying the package metadata rather than modifying dune. Thanks for the proof-of-concept @dra27!
I've updated my example project to use @dra27's fork of the JST repo which internalizes the "init-*" packages and changed the example program to use the new oxcaml syntax to demonstrate that it's being built with the oxcaml compiler.
@dra27 thanks for the proof-of-concept! I agree with your point. Note that some problems we encountered here are related to non-relocatable packages in general. This isn't exclusive to OxCaml. We need to fix these problems anyway for Dune Package Management.
As @gridbugs, I have tried the solution, and I'm able to make it build and run the code!
Some feedback about it, I have been able to push a working version using @dra27 patches and using a custom repository. It can be found at https://github.com/gridbugs/hello-oxcaml/tree/with-custom-patch.
I've also reproduced the example here. IMO, we can close this issue with some documentation explaining how to set up a project to build with oxcaml. (But there is still a lot of related work to make working with oxcaml via dune pkg easier!
@art-w is planning to do the finishing (documentation) work here and discovery for followups.
I've tested this and it works. Workspace:
(lang dune 3.20)
(lock_dir
(repositories :standard oxcaml))
(repository
(name oxcaml)
(url "git+https://github.com/oxcaml/opam-repository.git"))
and project:
(package
(name oxcaml_experiements)
(depends (ocaml-variants (= 5.2.0+ox))))
Autoconf was required, which wasn't the case for ocaml. That might be worth trying to improve.
Shouldn't there be a conf-autoconf dependency in the opam file then?
@rgrinberg That appears to be the case https://github.com/oxcaml/opam-repository/blob/a1ea0d33dd5662b89183f751c3fec566d7860b75/packages/ocaml-variants/ocaml-variants.5.2.0%2Box/opam#L11.
My point was not that it wasn't clear, but that it was surprising since it wasn't exactly a drop-in replacement for ocaml.
I still don't really get the point then. Regular OCaml also depends on autoconf, so in what way it isn't drop-in?
Regular OCaml uses autoconf to generate their configure scripts, but they don't use it when building:
- https://github.com/ocaml/opam-repository/blob/master/packages/ocaml/ocaml.5.4.1/opam
- https://github.com/ocaml/opam-repository/blob/master/packages/ocaml-compiler/ocaml-compiler.5.4/opam
- https://github.com/ocaml/opam-repository/blob/master/packages/ocaml-variants/ocaml-variants.5.4.0%2Boptions/opam
- https://github.com/ocaml/opam-repository/blob/master/packages/ocaml-option-flambda/ocaml-option-flambda.1/opam
OxCaml on the otherhand appears to be running autoconf on the fly.
End-result for the user is that you need the autoconf binary to build OxCaml but no for OCaml.
I still don't really get the point then. Regular OCaml also depends on autoconf, so in what way it isn't drop-in?
Regular OCaml doesn’t ever depend on autoconf… it’d be better if the OxCaml release tarballs included configure (which is how autotools is intended to be deployed - end users are not supposed to have to run it). Upstream simplifies this by choosing to commit configure (which is a commit crime, as it’s a generated artefact!)
It’s a material concern as the number of distributions building OxCaml grows, because autoconf compatibility is not guaranteed between versions (for example, 2.71 can’t build the branches of OCaml using 2.69 correctly)