Can I use an "opam switch" as an immutable base of another one?

To answer the original question: no, opam does not currently support sharing build artifact across switches. One reason why this is not obvious to implement nicely is that the OCaml compiler is not relocatable by default, its behavior depends on the path it was installed into, so removing or updating the “parent” switch could break “children” switches that reused the parent compiler – even if the build artifacts were copied when creating the children switches. (Esy works around this problem with a path-rewriting hack. It is also possible to play with the filesystem to pretend that all switches are at the same path.)

@dra27 has been working on making the OCaml compiler relocatable, see Relocatable compiler work , which would open a way forward to binary caching without hacks or restrictions.

2 Likes