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

PPX optimizations #46

Open mobileink opened 2 years ago

mobileink commented 2 years ago

We can control ppx_executable builds using Bazel's toolchain and platform mechanisms. The ppx attribute on ocaml_module and ocaml_signature is marked as executable, which requires that it also be marked (via the cfg attribute) for configuration transition. Currently we use cfg = "target", which ensures that the ppx_executable and all of its dependencies target the same platform as the depending (module or signature) target. This is essential since ppxes may carry ppx co-dependencies, which they inject into the sources they transform.

We should be able to control this config transition using a custom transition function. That function would set the host_platform and platforms settings, thereby controlling selection of the toolchain used to build the ppx executable and its deps. So to optimize for build time, we would select a toolchain that runs in the vm. To optimize for ppx execution time, we would select a toolchain that emits native code.

This would require some additional machinery to control the build of co-dependencies, since they would have to be built with the original toolchain, not the one selected to build the ppx executable.