I am interested in understanding whether bazel can handle "two stage builds", where dependencies are discovered based on the file contents and dependencies must be compiled before the code that depends on them (unlike C/C++ where dependencies are mostly header files that are not separately compiled). Concretely, I am building the Coq language which is like Ocaml.
My intuition for creating a build plan would use an (existing) tool (called coqdep
) that reads a .v
file and returns a list of all of its direct dependencies. Here's the algorithm that I have in mind:
- invoke
coqdep
on the target file and (transitively) on each of its dependent files, - once transitive dependencies for a target are computed, add a rule to build the
.vo
from the.v
that includes transitive dependencies.
Ideally, the calls to coqdep
(in step 1) would be cached between builds and so only need to be re-computed when the file changes. And the transitive closure of the dependency information would also be cached.
Is it possible to implement this in bazel? Are there any pointers to setting up builds for languages like this? Naively, it seems to be a two-stage build and I'm not sure how this fits into bazel's compilation model. When I looked at the rules for Ocaml, it seemed like it was relying on ocamlbuild
to satisfy the build order and dependency requirements rather than doing it "natively" in bazel.
Thanks for any pointers or insights.