Skip to content
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

Patch to make ocamlfind relocatable (via a binary installer on macOS, Windows, Snap) #60

Open
MSoegtropIMC opened this issue Feb 23, 2023 · 9 comments

Comments

@MSoegtropIMC
Copy link

MSoegtropIMC commented Feb 23, 2023

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.

@gerdstolpmann
Copy link
Contributor

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.

@MSoegtropIMC
Copy link
Author

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.

@gerdstolpmann
Copy link
Contributor

@MSoegtropIMC
Copy link
Author

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.

@MSoegtropIMC
Copy link
Author

(Using environment variables is not an option either).

@gerdstolpmann
Copy link
Contributor

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.

@MSoegtropIMC
Copy link
Author

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).

@dra27
Copy link
Member

dra27 commented Mar 6, 2023

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.

@MSoegtropIMC
Copy link
Author

I tried this, but it does not work for Coq Platform, because the executables end up ind different folders at different levels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants