ocamlfind
ocamlfind copied to clipboard
Patch to make ocamlfind relocatable (via a binary installer on macOS, Windows, Snap)
I maintain the Coq Platform project, which provides binary installers for MacOS, Windows and Linux (snap) for INRIA Coq (a proof assistant). In version 8.16 (autumn 2022) Coq switched to use ocamlfind. Now ocamlfind was not designed with relocation by an installer in mind.
I patched ocamlfind such that it works with relocation.
The main changes are:
- ocamlfind searches the directory structure upwards from the executable until it finds a file
findlib.root
or reaches/
. - The OCAML_SITELIB, OCAMLFIND_CONF are augmented with a _RUN variant which allows to give e.g. relative path to the path of the findlib.root file (three leading dots are replaced with the path of findlib.root).
This mechanism has the advantage, that one need not patch files with directories during installation - one just has to put the findlib.root at the proper place, which is no issue on the supported platforms.
This system should have a few 1000 installations meanwhile on macOS, Windows and Snap and I did not hear anything negative. If this is desirable for other ocamlfind users is a different question.
Please let me know what you think and if you would like to see a PR or if you have a better idea I can also keep this as a Coq Platform local patch - it shouldn't kill me to port the patch.
Hello @MSoegtropIMC , first of all, welcome to the Findlib community.
Relocatibility is a feature that is requested from time to time, but I am still very skeptical. I know that it works for a lot of app programs, but I also know situations where it breaks - in particular for incompatibile libraries and when security problems are not tolerable (like for most professional software).
My other remark is that you can already have your own config file and relocate everything there. It is not as convenient because you need an install script, but it is not a big problem either.
Can you point me to the documentation for the runtime config file? This might indeed be an option - I was not aware of such a mechanism.
Here you go: http://projects.camlcity.org/projects/dl/findlib-1.9.6/doc/ref-html/r865.html
Ah yes - I think I came across it, but discarded the possibility of using it because of:
The directory containing findlib.conf is determined at build time (by running the configure script), the fallback default is /usr/local/etc. You can set a different location by changing the environment variable OCAMLFIND_CONF which must contain the absolute path of findlib.conf.
I can't have a compile time determined or fixed location to look for findlib.conf.
(Using environment variables is not an option either).
Well, the patch you propose will break many other installations, so any relocation feature would have to be optional and enabled somehow. It is a bit unclear to me how to do that if you can't even use environment variables.
The mechanism I am using is to introduce two new configure time variables:
OCAML_SITELIB_RUN
OCAMLFIND_CONF_RUN
which point to the respective locations at run time. If either of these these variables starts with three leading dots "...", these 3 dots are replaced with the location of the findlib.root file. If OCAML_SITELIB_RUN
or OCAMLFIND_CONF_RUN
are not given at configure time, the default to the non RUN variants and findlib behaves normally (it does some additional path normalisation which should be a nop then). If the variables don't start with 3 dots, the paths are fixed (but might be different between compile and run time).
Just a very brief note that my patches for relocation in the compiler approach the absolute path problem for ld.conf
(which is related to findlib's search for findlib.conf
) by using a configure
'd relative path, rather than a search up from the directory.
For ocamlrun
, that means that it evaluates ../lib/ocaml
from the directory where ocamlrun is. Could a similar trick be deployed for ocamlfind - so instead of, say, /home/dra/.opam/dev-4.14/lib/findlib.conf
being a hard-coded path, it instead has ../lib/findlib.conf
? The OCaml patches for that are all opt-in as well - so opam can use it, but the default for Unix distributions and so forth is absolute paths.
I tried this, but it does not work for Coq Platform, because the executables end up ind different folders at different levels.