Quantcast
Channel: OCaml - Topics tagged dune
Viewing all articles
Browse latest Browse all 532

Proposal: a new `represents` field in `findlib` META files

$
0
0

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:

  1. For compiling.
    Let explicit_libs be the smallest set of library names that includes libs, their
    represents library names and recursively.

    Let hidden_libs be the smallest set of library names that includes the requires library names of each libs, the requires of each represents of each libs and recursively includes both their represents and requires libraries that are not in explicit_libs.

    For each library in the set explicit_libs we include its library directory with a -I. For each of library in hidden_libs with include its library directory with a -H.

  2. For linking.
    The library archives of libs, the library archives of their represent and requires 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:

  1. For compiling.
    Let overshoot_libs be the smallest set of library names that includes libs, their represents and requires library names and recursively. For each of the library in the set overshoot_libs we include its library directory with -I.

  2. For linking.
    The library archives of overshoot_libs are provided sorted in stable topological order.

Usage

The represents field can be used for two things:

  1. Along with a warning field a library name can be deprecated and be transparently replaced by a list of other libraries.
  2. 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

Read full topic


Viewing all articles
Browse latest Browse all 532

Trending Articles