开发者

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

开发者 https://www.devze.com 2023-04-02 08:36 出处:网络
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 ocamlbuil

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 dyna开发者_开发百科mically 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).

0

精彩评论

暂无评论...
验证码 换一张
取 消