internal/gapicgen: add proto3_optional flag to protoc calls
A specific flag is necessary to enable consumption of the proto3_optional
feature. If the flag is not present, but a proto using proto3_optional is
encountered, protoc exits with an error.
Change-Id: I52481503b34e4b8f73cfa66d218d01b8e77cb4a8
Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/56973
Reviewed-by: Tyler Bui-Palsulich <tbp@google.com>
diff --git a/internal/gapicgen/generator/gapics.go b/internal/gapicgen/generator/gapics.go
index d37e98f..15a3373 100644
--- a/internal/gapicgen/generator/gapics.go
+++ b/internal/gapicgen/generator/gapics.go
@@ -146,6 +146,7 @@
}
args := []string{"-I", googleapisDir,
+ "--experimental_allow_proto3_optional",
"-I", protoDir,
"--go_gapic_out", gocloudDir,
"--go_gapic_opt", fmt.Sprintf("go-gapic-package=%s;%s", conf.importPath, conf.pkg),
diff --git a/internal/gapicgen/generator/genproto.go b/internal/gapicgen/generator/genproto.go
index b4d1e9c..e39928e 100644
--- a/internal/gapicgen/generator/genproto.go
+++ b/internal/gapicgen/generator/genproto.go
@@ -195,7 +195,7 @@
// protoc executes the "protoc" command on files named in fnames, and outputs
// to "<genprotoDir>/generated".
func protoc(genprotoDir, googleapisDir, protoDir string, fnames []string) error {
- args := []string{fmt.Sprintf("--go_out=plugins=grpc:%s/generated", genprotoDir), "-I", googleapisDir, "-I", protoDir}
+ args := []string{"--experimental_allow_proto3_optional", fmt.Sprintf("--go_out=plugins=grpc:%s/generated", genprotoDir), "-I", googleapisDir, "-I", protoDir}
args = append(args, fnames...)
c := command("protoc", args...)
c.Stdout = os.Stdout