Proposal: represents
field in findlib
META files
Note: in what follows I use, following dune
terminology, the term library names for what is formally ocamlfind
package names.
Recently I have deprecated a few libraries names in some packages. Namely vg.svg
, uunf.string
and uuseg.string
.
To do so I made empty libraries in the META
files installed by these packages. These empty libraries simply requires
their replacement library and warn on usage with a warning
field (sample).
However this can’t work if you have a build system with correct dependencies – a.k.a implicit_transitive_deps
set to false
in dune
.
In this mode the includes (-I
) of the requires
of a specified library dependency are not added during the compilation phase. So using the requires
field to proxy a library for another one can’t work.
While it seems that correct dependencies break in all sorts of obscure ways, upstream has integrated support for hidden includes (-H
) in the upcoming OCaml 5.2.
So I propose to add a represents
field to META
files which has exactly the same syntax as requires
, i.e. a list of library names. In a nutshell, the idea of represents
is that the includes of these libraries are added during the compilation phase with -I
while those of requires
are only added with a -H
.
More precisely the semantics of requires
and represents
are as a follows.
Compiling with correct dependencies (OCaml >= 5.2)
Given a sequence of library names libs
to compile against:
-
For compiling.
Letexplicit_libs
be the smallest set of library names that includeslibs
, their
represents
library names and recursively.Let
hidden_libs
be the smallest set of library names that includes therequires
library names of eachlibs
, therequires
of eachrepresents
of eachlibs
and recursively includes both theirrepresents
andrequires
libraries that are not inexplicit_libs
.For each library in the set
explicit_libs
we include its library directory with a-I
. For each of library inhidden_libs
with include its library directory with a-H
. -
For linking.
The library archives oflibs
, the library archives of theirrepresent
andrequires
libraries and recursively need to be provided, sorted in stable topological order.
Compiling with incorrect dependencies (OCaml < 5.2)
Given a sequence of library names libs
to compile against:
-
For compiling.
Letovershoot_libs
be the smallest set of library names that includeslibs
, theirrepresents
andrequires
library names and recursively. For each of the library in the setovershoot_libs
we include its library directory with-I
. -
For linking.
The library archives ofovershoot_libs
are provided sorted in stable topological order.
Usage
The represents
field can be used for two things:
- Along with a
warning
field a library name can be deprecated and be transparently replaced by a list of other libraries. - A library name can be defined to define a “meta” library which represents a bunch of other libraries against which to compile and link. This library can also provide code itself.
Note that these two usages formally existed in the incorrect dependency world but is no longer possible in the correct dependency world. The represents
field allows to bring it back.
For compability with incorrect dependency compilation the represents
values should be for now replicated in the requires
field. This allows ocamlfind
to work in incorrect dependencies mode for the time being (it doesn’t mind fields it doesn’t know) while allowing other build tools to read and write represents
regardless and be more correct
4 posts - 2 participants