Using ocamlformat in a base-0.14 switch

(This is probably a specific instance of a more general question)

As we know, the 0.14 release of Jane Street’s base ecosystem recently landed, and I’d like to try it out to see if it’s easy enough to upgrade my OCaml projects. However, my opam switch has ocamlformat installed in it, and ocamlformat depends on base<0.14; it turns out that it supporting the new version requires a trivial but completely backwards incompatible codechange and this has been dropped in favour of the upper dependency limit.

If I wanted to play around with base and use ocamlformat I’m at a bit of an impasse, as my choices seem to be:

  • stick with 0.13;
  • fork and pin it locally, apply the codechange, manually keep my fork in sync with upstream;
  • find some way of getting a version of ocamlformat that’s statically linked, separately switched, or otherwise somehow not connected to my current opam switch.

It doesn’t seem realistic for me to expect ocamlformat to move to base-0.14, as it’d break backwards compatibility with older base versions and subject everyone else who can’t move off base-0.13 to the reverse of the problem I’m having.

Are there any obvious ‘good’ solutions to this that I’ve missed?

Yes, this is an inconvenience. Just for the record, note that this isn’t really about base, but it just happens to be the dependency involved this time. The usually more pressing dependency blocking loose constraints is the compiler and compiler-libs. It is also possible for the output of ocamlformat to vary based on the version of compiler-libs used to build it. This means that the solution needs to be a convenient way to use ocamlformat from a different switch.

For now, this is manual: e.g. I build ocamlformat in its own switch and install the binary in PATH and do not install ocamlformat in other switches.

Eventually it would be good to use something like ocaml-secondary-compiler to automate this, but this is WIP.


Simple solution: create a new switch. Compile ocamlformat in it. Save the built binary ocamlformat somewhere in you PATH e.g ~/.local/bin

Now you can use this on any switch. Delete the ocamlformat on your old switch so that it does not interfere with Base etc.

P.S. jjb has suggested the same thing. I should have read his reply fully before replying !