rules_ocaml icon indicating copy to clipboard operation
rules_ocaml copied to clipboard

PPX optimizations

Open mobileink opened this issue 3 years ago • 0 comments

  • Lots of PPXes: optimize build time
  • Lots of PPX transformations: optimize ppx executables for speed

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.

mobileink avatar Jul 01 '22 14:07 mobileink