-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow using together with protoc-gen-go
#67
Comments
As written in README, TinyGo doesn't work with the code generated by |
However, that was two years ago. The situation might have changed. tinygo-org/tinygo#2667 |
Did a test using:
And: https://github.com/containerd/nri/blob/main/pkg/api/api.proto mkdir tmp && protoc --go_out=tmp --go_opt=paths=source_relative ./pkg/api/api.proto Then using a package main
import (
"github.com/containerd/nri/tmp/pkg/api"
)
func main() {
_ = &api.RegisterPluginRequest{}
} Which builds successfully using tinygo: tinygo build -scheduler=none -target=wasi -no-debug main.go |
If I remember correctly, some errors occur at runtime. Did you successfully run the code? |
I'am still getting errors when compiling using more or less complex proto definitions:
Tracking issues: tinygo-org/tinygo#2704 and tinygo-org/tinygo#4580 |
@inliquid this is probably because of the gRPC generated code |
Most likely it is. The package referred to by the wasm module is quite complex, I would like to just import it, but can't, so have to re-generate these definitions locally as well using |
We may be able to add a new option to disable generating pb.go files as below. Then, we can run diff --git a/cmd/protoc-gen-go-plugin/main.go b/cmd/protoc-gen-go-plugin/main.go
index 0e64222..6945787 100644
--- a/cmd/protoc-gen-go-plugin/main.go
+++ b/cmd/protoc-gen-go-plugin/main.go
@@ -10,6 +11,7 @@ import (
func main() {
var flags flag.FlagSet
+ disablePbGen := flags.Bool("disable_pb_gen", false, "disable .pb.go generation")
protogen.Options{ParamFunc: flags.Set}.Run(func(plugin *protogen.Plugin) error {
g, err := gen.NewGenerator(plugin)
if err != nil {
@@ -20,7 +22,7 @@ func main() {
if !f.Generate {
continue
}
- g.GenerateFiles(f)
+ g.GenerateFiles(f, gen.Options{DisablePBGen: *disablePbGen})
}
plugin.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
diff --git a/gen/main.go b/gen/main.go
index 3d96403..3d29c83 100644
--- a/gen/main.go
+++ b/gen/main.go
@@ -89,6 +89,10 @@ type Generator struct {
vtgen *vtgenerator.Generator
}
+type Options struct {
+ DisablePBGen bool
+}
+
func NewGenerator(plugin *protogen.Plugin) (*Generator, error) {
ext := &vtgenerator.Extensions{}
featureNames := []string{"marshal", "unmarshal", "size"}
@@ -138,9 +142,11 @@ func replaceImport(m *protogen.Message) {
}
// GenerateFiles generates the contents of a .pb.go file.
-func (gg *Generator) GenerateFiles(file *protogen.File) *protogen.GeneratedFile {
+func (gg *Generator) GenerateFiles(file *protogen.File, opts Options) *protogen.GeneratedFile {
f := gg.newFileInfo(file)
- gg.generatePBFile(f)
+ if !opts.DisablePBGen {
+ gg.generatePBFile(f)
+ }
gg.generateHostFile(f)
gg.generatePluginFile(f)
gg.generateVTFile(f)
@@ -252,7 +258,7 @@ func (gg *Generator) genImport(g *protogen.GeneratedFile, f *fileInfo, imp proto
// Generate public imports by generating the imported file, parsing it,
// and extracting every symbol that should receive a forwarding declaration.
- impGen := gg.GenerateFiles(impFile)
+ impGen := gg.GenerateFiles(impFile, Options{})
impGen.Skip()
b, err := impGen.Content()
if err != nil { |
Hey, right now using both
protoc-gen-go
andprotoc-gen-go-plugin
together will result in:Would it be possible to run both plugins together so that they can share the types?
Somehow related to cri-o/cri-o#8715, containerd/nri#120
The text was updated successfully, but these errors were encountered: