mransan/ocaml-protoc

Add file level option to customize resulting module name

Lupus opened this issue · 2 comments

Lupus commented

Would be great to be able to specify the name of the module for specific .proto file using some option instead of deriving it by the file name. In large repositories with a lot of protos there might be files named just options.proto and their path matches the package, i.e. foo/bar/options.proto for package foo.bar.options (this convention is enforced by buf tool, which is popular for linting protobufs and checking backwards compatibility of their evolution in CI). Currently ocaml-protoc just generates Options_*.{ml,mli} files, which is prone to collisions and confusion.

I think it makes sense to have an option, certainly. However it can't really be a sub-directory thing, with dune the project layout is generally flat-ish.

It may be useful to have a CLI option for a prefix for a file (rather than taking the basename of the .proto file, use this particular prefix). Another option imho is to take a file that maps .proto paths to .ml paths, because this would work better in presence of multiple files importing one another?

Lupus commented

I mean subdirectories in proto hierarchy already scope file names, and file names might be the same in different subdirectories with proto files. Currently I just use a bash script, that iterates through all .proto files in my hierarchy and feed each file to generator. I want to avoid keeping complex logic in the bash script itself, rather have some options in source proto files that tell the generator what prefix should be in the resulting files with OCaml modules.

Another option imho is to take a file that maps .proto paths to .ml paths, because this would work better in presence of multiple files importing one another?

Hm, typically there are options for Golang, Java and other languages right in .proto files which specify what package should this file belong to. Generators for these languages use these options to resolve includes/imports.