I am trying to keep my project self-contained, with all major 3rd party library dependencies built and referenced within the project repository. The main ocaml portions of my project rely on ocamlbuild.
But for complex packages like Batteries Included, there seems to be a strong expectation that they be linked into a project via ocamlfind. ocamlfind seems to assume that packages will be installed globally. (I realize it allows environment variables and its conf to point to alternate locations, but it fundamentally still seems to be built around the assumption that packages are globally configured--it has no equivalent of -I
or -L
flags to dynamically extend the search path for packages, for example. It may be possible to set environment variables to dynamically override the ocamlfind configuration to search the project-local tree, but this is much more awkward than mere arguments, and it also seems like it would be challenging to do so without simultaneously removing discoverability of the main system packages in the primary site-lib
, which may also be needed.)
What is a sane strategy for building and building against nontrivial 3rd party packages within a project-local tree for a project using ocamlbuild?
Using environment variables (or separate findlib.conf) is a way to go (and easy). And it doesn't require removing discoverability of global packages, see reference manual for path
and destdir
in findlib.conf
(OCAMLPATH
and OCAMLFIND_DESTDIR
environment variables respectively).
Basically you set destdir
to local path when installing project-local packages, and prepend to path
when using them (don't forget to create stublibs
in destdir
(and add it to ld.conf
in stdlib
if you are building bytecode binaries)).
PS I think this is the approach used in ocsigen-bundler.
Please tell if you experience any problems (cause I am interested in using this same approach too).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With