buf icon indicating copy to clipboard operation
buf copied to clipboard

Support inputs in buf.gen.yaml

Open Aqours opened this issue 1 year ago • 4 comments

Usage Scenario

Generate multiple BSR modules

buf generate buf.build/googleapis/example1
buf generate buf.build/googleapis/example2
buf generate buf.build/googleapis/example3

Expected

  1. Support multiple input modules
buf generate buf.build/googleapis/example1 \
             buf.build/googleapis/example2 \
             buf.build/googleapis/example3
  1. Support config in buf.gen.yaml
version: v1
plugins:
  - name: xxx
modules:
  - buf.build/googleapis/example1
    buf.build/googleapis/example2
    buf.build/googleapis/example3
buf generate

Aqours avatar Sep 21 '22 04:09 Aqours

Regarding point 2, buf.gen.yaml's intention is to be input agnostic and the current stance is that we will not support inputs in the generate config file (see also https://github.com/bufbuild/buf/issues/510). Similarly various parts of buf are designed to operate on one module at a time and there are no plans to support multi module inputs. If you have a need to have only one buf invocation, would xargs -n1 suit your needs?

Based on https://github.com/bufbuild/buf/issues/1407#issuecomment-1248761198 we may revisit the input agnostic idea of buf.gen.yaml in the future. This ticket is linked now and we'll take the feedback into account for those discussions.

robbertvanginkel avatar Sep 21 '22 14:09 robbertvanginkel

This isn't going to happen in the near-term, but is something we're reconsidering. Generally, we may want buf.gen.yaml files to be input-aware. Going to keep open for now.

bufdev avatar Jan 14 '23 19:01 bufdev

When looking at this issue in the future, we should also look at https://github.com/bufbuild/buf/issues/1407 - going to close that issue and track this only here.

bufdev avatar Jan 14 '23 19:01 bufdev

Another use case (similar to #1407) would be to allow type filtering and (a new feature) option redaction at the plugin level. The latter would be useful to omit certain options from generated code in order to not ship them in a frontend bundle (https://github.com/bufbuild/protobuf-es/issues/397).

timostamm avatar Mar 28 '23 09:03 timostamm

buf.gen.yaml v2 supports multiple inputs now. Your file may look like:

version: v2
plugins:
# ...
inputs:
  - module: buf.build/googleapis/example1
  - module: buf.build/googleapis/example2
  - module: buf.build/googleapis/example3

Before adding an inputs section, you can have the rest of your buf.gen.yaml ready by running the migration command:

buf config migrate

or

buf config migrate --buf-gen-yaml path/to/buf.gen.yaml

if your buf.gen.yaml is not at the current directory or named differently. Use the --diff flag to only display the difference between your upgraded and current file.

oliversun9 avatar Jun 05 '24 22:06 oliversun9