rules_ocaml icon indicating copy to clipboard operation
rules_ocaml copied to clipboard

OPAM implementation deps ("virtual" libs), e.g. digestif

Open mobileink opened this issue 4 years ago • 1 comments

digestif is an example of a library that affords multiple implementations. To use it one must depend on both digestif and either digestif.c or digestif.ocaml

We should be able to reduce this to a dependency on digestif and a build/config setting that automatically selects the implementation. This should work with the new "nocamlfind" version that generates BUILD.bazel files for opam libs. The following is currently generated for digestif

ocaml_import(
    name = "digestif",
    version = """0.9.0""",
    archive = select({
        "@ocaml//mode:bytecode": [

        "@ocaml//mode:native": [

    }),
    deps = [
        "@opam//lib/bigarray-compat",
        "@opam//lib/eqaf",
    ],
    visibility = ["//visibility:public"]
)

The idea is that we can add a select to the deps attribute to make digestif depend on an implementation, something like:

    struct = select({
        ":foo: "@opam/lib/digestif/c",
        ":bar": "@opam/lib/digestif/ocaml",
    }),

Here :foo and :bar could be platform constraints, for example.

mobileink avatar Sep 04 '21 04:09 mobileink

in the case of digestif, we can define build settings in the package, so e.g. the user can select an implementation by passing one of --@opam//lib/digestif:c or --@opam//lib/digestif:ocaml. default could be c, so the option would only be needed to switch to the ocaml impl.

mobileink avatar Sep 04 '21 05:09 mobileink