obazl / rules_ocaml

A Bazel Language Support Package for OCaml
https://obazl.github.io/docs_obazl
Apache License 2.0
32 stars 7 forks source link

adjunct_deps: add support for "adjunct_modules" #5

Open mobileink opened 3 years ago

mobileink commented 3 years ago

PPX executables may inject code that induces additional compile-time dependencies. The injected code may also induce the need to add open directives. Usually these are added to the source files. But we could treat them the same we we treat adjunct deps: attach them to the ppx_executable rule, and then add -open params when the executable is used.

Example: ppx_sexp_conv induces a dependency on libs Sexplib and Sexplib.Std. Instead of adding open directives to source files, we can augment the command line for the compile with -open Sexplib -open Sexplib.Std. I don't know if this is a good idea but it works.

What are the pros and cons of supporting this?

For an annotated example, see https://github.com/obazl/dev_obazl/tree/main/demos/ppx/adjunct_deps

mobileink commented 3 years ago

one way to do this: make adjunct_deps a label_keyed_string_dict, and list the modules to be opened in the string value. E.g. something like:

adjunct_deps = {
    "@opam//pkg:sexplib": "Sexplib Sexplib.Std",
    "@opam//pkg:ppx_sexp_conv.runtime-lib": ""
}

This kinda makes sense, since "deps" broadly interpreted covers both pkg/lib deps and module deps. Code depends on module which is included in a pkg.