What is the preferred way to structure and build OCaml projects?

Incomprehensible to newcomers to the ecosystem, is the canonically preferred way to structure and manage small and medium sized OCaml projects. I understand the basics of ocamlc , & c. - they mirror ordinary UNIX C compilers, sufficient for seemingly simple. But, above the one-time compilation level of individual files, it is unclear how best to manage compilation simply and cleanly. The problem is not the search for potential tools, but the search for one or several correct (sufficient) ways - as confirmed by community experience - for structuring and building standard OCaml projects.

My example of using the model is a modest but non-trivial project, pure OCaml or OCaml plus C dependency. Such a project:

  • contains several source files
  • links to several standard libraries
  • links to one or more third-party libraries
  • optionally includes the C library and the OCaml shell as a subproject (although this can also be managed separately and included as a third-party library, as in (3))

Several alternative tools stand out:

  • Custom Makefiles appear to be the standard standard in most open source OCaml packages, but they look disappointing and complicated - even more so than for modest C / C ++ projects. Worse, many even seemingly simple OCaml libraries use autoconf / automake from above for even more complexity.
  • ocamlbuild seems to offer a modern, optimized build automation engine with minimal configuration, but it is poorly documented for beginners, presented as an example in the introductory materials in the OCaml ecosystem, and is clearly not used by any of the various published OCaml projects that I looked for inspiration.
  • OASIS seems like a convention and library code layer on other build systems to support building a package manager and library such as Cabal.

(I also saw OMake , which looks like the self-styled " make++ ", which also includes a set of standard rules for common languages, including OCaml, and ocaml-make née OCamlMakefile, which provides a standard rules template for GNU make .)

Are any of these the preferred, modern way to manage OCaml?

How are project files best structured?

How are third-party library dependencies included and managed? Is it advisable to install them at the system level, or is there a standard and easy way to manage them locally for a project? I would prefer a model in which projects remain as self-sufficient as possible.

+56
build ocaml ocamlbuild makefile
May 10 '11 at 20:50
source share
4 answers

You have a detailed list of available options, but there will be no clear answer to this question. My personal recommendation is also to use ocamlbuild. The myocamlbuild.ml file provided here is a good start. This will allow you to easily compile projects depending on different libraries. I don't think it handles the case of binding to C libraries, but there are additional examples in the wiki that may help.

Some people object to ocamlbuild because it is another build tool that makes package managers difficult. However, its ease of use and the fact that it is included in the official distribution makes it more and more widely used.

You can also skip all this and use the oasis directly. This is very new, and a stable release has not yet been announced, but it is very useful. It automatically generates myocamlbuild.ml for you. This is probably the way in the very near future, if not earlier. In addition, using the oasis, you will immediately get the advantage of oasis-db, such as the OCaml CPAN system, which is under development.

As for library management, the answer is ocamlfind. If you have multiple instances of OCaml installed, invoking the appropriate copy of ocamlfind will automatically cause all library links to be such for that particular instance if you use ocamlfind systematically for all libraries. I am currently using godi to install OCaml and libraries. It uses ocamlfind and I have no problem installing multiple instances of OCaml.

+21
May 11 '11 at 12:43
source share

Personally, I would give +1 for ocamlbuild. Its default rules are good enough for compiling small to medium sized projects with a single command, and none of them have a minimal configuration. It also applies some very reasonable conventions (without mixing sources with build results). And for large projects, it can be configured to one desire, with additional rules and plugins. In the company where I work, we use it for a large project (Ocaml + some C + some preprocessors + ...), and it works like a charm (and gives us much less headaches than Makefiles).

As with the manuals, I think that the user manual (accessible from the author’s web page ) should be enough to get you started. More funky things may require a bit more digging.

+14
May 10 '11 at 9:45
source share

+1 for OMake.

We upgraded our build infrastructure a few years ago and chose OMake for the following reasons:

  • Our products consist of a mixture of C, C ++, Managed C ++, Ruby and OCaml.
  • we focus on both Linux and Windows.
  • We interact with databases at build time.
  • for some productions we had to use OCaml 3.10.
  • our original build system uses autoconf / automake.
  • we need assemblies outside the source code *.

Honestly, I do not know if we could do this with ocamlbuild, I have not tested it. This tool is used because there is activity in OCaml bugtracker. If you choose ocamlbuild, make sure you have an updated version of OCaml.

* OMake supports custom builds in a slightly unobvious way. It also has some problems when sources are read-only. We had to plan and rebuild our version of OMake for Windows.

+10
May 11 '11 at 13:51
source share

good question. I would say:

1) ocamlbuild Most likely, this is a standard compilation method, because it is efficient, fast and the default tool provided by the official distribution. The fact that it is in the official distribution is a good point, since it is likely to remain with time. In addition, it has ocamlfind enabled, so it can manage packages installed with ocamlfind, another standard for installing packages (ocamlfind is a bit like pkg-config for C)

2) But this will not be enough for your project. Integration with C is core with ocamlbuild. Therefore, I could advise you to use the oasis to finally answer your question. I also tried Omake, but I did not like it.

3) However, your build scripts are unlikely to work if you cannot other users download and create your project on your own machine. In addition, the oasis does not handle pkg-config. For these reasons, I would advise you to use ocaml-autoconf (ocaml macros for autotools). Since autotools are the standard for managing C libraries and are well known to package developers. It can also handle cross compilation ...

=> ocaml-autoconf with ocamlbuild

+3
May 22 '12 at 17:57
source share



All Articles