Skip to content
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

Example : generate for GO #263

Closed
fiftoine opened this issue Aug 29, 2018 · 6 comments
Closed

Example : generate for GO #263

fiftoine opened this issue Aug 29, 2018 · 6 comments

Comments

@fiftoine
Copy link

Hi,

From a set of proto files, I would like to generate stubs for both java and go.

Reading the doc I can't find a way of generating stubs for go even if it's mentioned in others issues.

Could you provide an example on how to generate for go alone and for java and go?

Thanks in advance

@zhangkun83
Copy link
Collaborator

You should follow the Step 2 from the protobuf documentation to install the Go protocol buffers plugin.

Then add go {} to the plugins of all protobuf generating tasks:

protobuf {
  generateProtoTasks {
    all().each { task ->
      task.plugins {
        go { }
      }
    }
  }
}

Run ./gradlew generateProto and you should find the generated files under build/generated/source/proto. We have done nothing to integrate the generated files into Go compilation, you would have to wire them up manually.

@Groostav
Copy link

Groostav commented Oct 14, 2018

@zhangkun83 what about extending this to grpc?

specifically im interested in C#, and I've been trying to create a workaround a le:

        generateProtoTasks {
            all().each { task ->
                task.plugins {
                    grpc {
                        logger.warn("TODO: currently not generating grpc for csharp, because protoc plugins on gradle plugins are NFG.")
//                        def path = file("$projectDir/../.kinda-nuget/packages/grpc.tools/1.15.0/tools/windows_x64/grpc_csharp_plugin.exe").absolutePath
//                        option "protoc-gen-grpc=$path"
                    }
                }
                task.builtins {
                    java { }
                    csharp { }
                }
            }
        }

@zhangkun83
Copy link
Collaborator

@Groostav, to use the C# grpc plugin, you would need to first define it, with either an artifact spec or a local path, e.g.,

protobuf {
  ...
  // Configure the codegen plugins
  plugins {
    // Define a plugin with name 'grpc'
    grpc {
      path = file("$projectDir/../.kinda-nuget/packages/grpc.tools/1.15.0/tools/windows_x64/grpc_csharp_plugin.exe").absolutePath
    }
    // Any other plugins
    ...
  }
  ...
}

@Groostav
Copy link

Groostav commented Nov 2, 2018

Works like a charm.

protobuf {

     protoc {
         artifact = "com.google.protobuf:protoc:3.5.1-1"
     }
     plugins {
         grpc_java {
             artifact = 'io.grpc:protoc-gen-grpc-java:1.15.1'
         }
         grpc_csharp {
             path = file("$projectDir/../.kinda-nuget/packages/grpc.tools/1.15.0/tools/windows_x64/grpc_csharp_plugin.exe").absolutePath
         }
     }

     generateProtoTasks {
         all().each { task ->
             task.plugins {
                 grpc_java {}
                 grpc_csharp {}
             }
             task.builtins {
                 java { }
                 csharp {}
             }
         }
     }
 }

The way I generated by .kinda-nuget was by copying a chunk of a nuget provided package into that folder. I didnt want to try and get gradle downloading nuget packages, so I simply checked that (multi-megabyte) portion into my repo. I don't think it'l be too volatile, though it does mean I'll have to do more work than simply changing a version string when I want to update grpc.

But, @zhangkun83, I cant help but feel I've hijacked the OPs quesiton and others googling "go grpc gradle", given that you cant simply put a path = file(".../grpc-go-plugin") there, what would the OP do?

zhangkun83 added a commit to zhangkun83/protobuf-gradle-plugin-1 that referenced this issue Nov 3, 2018
protoc will by default look for protoc-gen-${name} from system search
path.  In cases plugins need to be installed locally, this would allow
projects to be able to use the locally installed plugins without
having to check in their absolute paths.

Resolves google#263
@zhangkun83
Copy link
Collaborator

OP's problem could be solved by allowing referring "undefined" plugins, since protoc will search in $PATH for the plugin if its path is not specified. I have created #270 for that.

Unfortunately the CI is broken and we are short-staffed, and we can't make a release with CI broken. Any help to fix the CI is welcome.

zhangkun83 added a commit that referenced this issue Nov 5, 2018
protoc will by default look for protoc-gen-${name} from system search
path.  In cases plugins need to be installed locally, this would allow
projects to be able to use the locally installed plugins without
having to check in their absolute paths.

Resolves #263
zhangkun83 added a commit to zhangkun83/protobuf-gradle-plugin-1 that referenced this issue Nov 7, 2018
protoc will by default look for protoc-gen-${name} from system search
path.  In cases plugins need to be installed locally, this would allow
projects to be able to use the locally installed plugins without
having to check in their absolute paths.

Resolves google#263
@zhangkun83
Copy link
Collaborator

0.8.7 is released and includes #270

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants