Open mbarbin opened 8 months ago
Indeed I was more thinking of something without dependencies (besides the ocaml-protoc compiler-libs perhaps). :-).
I suspect it'd be possible to use the ocaml-protoc compiler-libs to compute the actual dependencies based on import
statements. But it's starting to be some work.
Why not just glob proto files in dune recursively (typically they are organized as a hierarchy corresponding to package names etc), and produce one output by ocaml-protoc
as the result, with all the modules scoped by corresponding packages/filenames?
I'm quoting an exchange we had with Simon in #231:
@c-cube:
Here is my response:
I support this idea. In fact, I've implemented a similar concept in a project of mine, calling it "protoc-helper". At the time, I didn't consider proposing it for upstream inclusion, but having something like that in the distribution makes sense to me.
My implementation cannot be directly reusable due to its dependency footprint, but I'm including it here as a data point.
Here's how it can be used in a dune file:
Note: I used
dune format-dune-file
to avoid worrying about formatting during generation. This requires thepipe-stdout
construct, introduced indune.2.7
, so may need to update your dune-project config to use it.I suspect that the dependency computation in my implementation might be flawed. I was concerned about whether the compiler needed to revisit a file, say
dep.proto
, while compiling another file,a.proto
, that depends ondep.proto
. As a result, I made all invocations depend on all proto files systematically. This might be an overkill and potentially unnecessary.