How can the ocamlfind/ocamlbuild toolchain be used with project-local copies of packages?
Asked Answered
C

1

6

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?

Corporative answered 1/9, 2011 at 18:45 Comment(0)
A
3

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

Adjournment answered 2/9, 2011 at 7:33 Comment(1)
I haven't wound up going down this route so far, so I have been slow to confirm success, but I expect it should work.Corporative

© 2022 - 2024 — McMap. All rights reserved.