Comments (15)
Thanks @ejona86 and @mehrdada for confirming what I suspected. I would like to see the plugin be its own distribution (or be a part of the grpcio-tools
package), I can move forward with the grpc_tools.protoc
approach.
Thanks everybody for fast responses!
from protobuf-gradle-plugin.
@mkobit You can try this (haven't run it in awhile):
project(":proto") { apply plugin: "java" apply plugin: "com.google.protobuf" buildDir = "$rootProject.buildDir/proto" protobuf { protoc { artifact = "com.google.protobuf:protoc:${protoVersion}" } plugins { grpc_java { artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" } grpc_python { path = getPluginPath("python") } grpc_ruby { path = getPluginPath("ruby") } grpc_cpp { path = getPluginPath("cpp") } } generateProtoTasks { all()*.builtins { java {} python {} ruby {} cpp {} } all()*.plugins { grpc_java { outputSubDir = "java" } grpc_python { outputSubDir = "python" } grpc_ruby { outputSubDir = "ruby" } grpc_cpp { outputSubDir = "cpp" } } } generatedFilesBaseDir = "$buildDir/generated/src" } dependencies { compile "com.google.protobuf:protobuf-java:${protoVersion}" compile "io.grpc:grpc-protobuf:${grpcVersion}" compile "io.grpc:grpc-netty:${grpcVersion}" compile "io.grpc:grpc-stub:${grpcVersion}" } } static def getPluginPath(name) { def path = "which grpc_${name}_plugin".execute() path.waitFor() path = path.in.text.trim() return path }
For people using this solution and would like something that doesn't require installing dependencies, only a valid docker environment, you can use something along the lines of
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.13.0'
}
plugins {
grpc_java {
...
}
grpc_csharp {
path = project.projectDir.absolutePath + "/bin/grpc_csharp_plugin"
}
}
generateProtoTasks {
all()*.builtins {
java {}
csharp {}
}
all()*.plugins {
grpc_java {
outputSubDir = "java"
}
grpc_csharp {
outputSubDir = "csharp_grpc"
}
}
}
}
where an executable file is placed in your project at ./bin/grpc_csharp_plugin
for example:
#!/usr/bin/env bash
docker run -v "$(pwd)":/defs -w "/defs" --rm --entrypoint /usr/bin/grpc_csharp_plugin namely/protoc-all "$@"
I am unsure if Docker for Desktop on Windows will (1) add docker
to your path and (2) correctly expand pwd
. If you need Windows and modify the command / author a valid .ps1
that is treated as executable, please post it here.
from protobuf-gradle-plugin.
@mkobit You can try this (haven't run it in awhile):
project(":proto") {
apply plugin: "java"
apply plugin: "com.google.protobuf"
buildDir = "$rootProject.buildDir/proto"
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:${protoVersion}"
}
plugins {
grpc_java {
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
}
grpc_python {
path = getPluginPath("python")
}
grpc_ruby {
path = getPluginPath("ruby")
}
grpc_cpp {
path = getPluginPath("cpp")
}
}
generateProtoTasks {
all()*.builtins {
java {}
python {}
ruby {}
cpp {}
}
all()*.plugins {
grpc_java {
outputSubDir = "java"
}
grpc_python {
outputSubDir = "python"
}
grpc_ruby {
outputSubDir = "ruby"
}
grpc_cpp {
outputSubDir = "cpp"
}
}
}
generatedFilesBaseDir = "$buildDir/generated/src"
}
dependencies {
compile "com.google.protobuf:protobuf-java:${protoVersion}"
compile "io.grpc:grpc-protobuf:${grpcVersion}"
compile "io.grpc:grpc-netty:${grpcVersion}"
compile "io.grpc:grpc-stub:${grpcVersion}"
}
}
static def getPluginPath(name) {
def path = "which grpc_${name}_plugin".execute()
path.waitFor()
path = path.in.text.trim()
return path
}
from protobuf-gradle-plugin.
would be nice if this played well with things like prototool, its difficult to generate stubs for a variety of languages with these off cases
from protobuf-gradle-plugin.
The python code generator is in the main grpc repository. Unlike the Java gRPC code generator which provides precompiled artifacts, you will need to compile the python generator by yourself. Feel free to ask questions on [email protected] on how to do it.
from protobuf-gradle-plugin.
As an alternative, there's this plugin, which seems to support building for both java an python: https://github.com/andrewkroh/gradle-protobuf-plugin
from protobuf-gradle-plugin.
This would be a cool addition. Personally could use it for cpp.
from protobuf-gradle-plugin.
Is there an easy way to execute the Python gRPC generation using the Gradle plugin? I tried searching the forum, but did not find much of anything. Or, is there something similar to #177 for Python gRPC?
from protobuf-gradle-plugin.
@mkobit Also looks like theres a Python example in the README.md
Edit: Added the getPluginPath function definition above.
from protobuf-gradle-plugin.
@gnz00 thanks, the example you provided is helpful. Hopefully I can take that and run with it. I did see the Python in the README but haven't figured out yet how to get gRPC plugin-side of it to work.
I'm looking through some Python gRPC documentation, but I am really struggling trying to find the path to the plugin that is installed. Everything I see is doing python -m grpc_tools.protoc <args>
with no reference to using it as a plugin to protoc
(which looks like it is executed by Java in this case). I feel like with my pip installation I should be finding a grpc_python_plugin
binary somewhere but I'm definitely just stupidly missing something.
from protobuf-gradle-plugin.
@mkobit
Here is how I was building with Docker on RHEL. Mac OSX I think you just need brew install grpc protobuf
.
RUN yum install -y autoconf \
automake \
build-essential \
gcc-c++ \
gflags-devel \
glibc-headers \
git \
java-1.8.0-openjdk-devel \
libtool \
make \
unzip \
wget \
&& yum -y clean all
ENV APP_DIR=...
ENV PROTOBUF_DIR=/opt/protobuf
ENV GRPC_DIR=/opt/grpc
ARG PROTOBUF_VERSION=3.4.0
ARG GRPC_VERSION=1.6.6
ARG GRADLE_VERSION=4.2.1
RUN wget https://services.gradle.org/distributions/gradle-$GRADLE_VERSION-bin.zip
RUN unzip -d /opt/gradle gradle-$GRADLE_VERSION-bin.zip
RUN git clone --depth 1 --branch v$PROTOBUF_VERSION https://github.com/google/protobuf $PROTOBUF_DIR
RUN git clone --depth 1 --branch v$GRPC_VERSION https://github.com/grpc/grpc/ $GRPC_DIR
ENV PATH=$PATH:/opt/gradle/gradle-$GRADLE_VERSION/bin/
ENV PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig
ENV LD_LIBRARY_PATH=$LD_LIBARY_PATH:/usr/local/lib/
# Install protobuf
WORKDIR $PROTOBUF_DIR
RUN git submodule update --init --recursive
RUN ./autogen.sh
RUN ./configure
RUN make
RUN sudo make install
RUN sudo ldconfig
# Install GRPC
WORKDIR $GRPC_DIR
RUN git submodule update --init --recursive
RUN make
RUN sudo make install
RUN sudo ldconfig
COPY . $APP_DIR
WORKDIR $APP_DIR
# Build projects
RUN gradle :proto:build
RUN gradle build
from protobuf-gradle-plugin.
@mkobit You might just need: python -m pip install grpcio-tools
from protobuf-gradle-plugin.
Thanks @gnz00 - if I install grpcio-tools
(latest releases) I don't find grpc_python_plugin
anywhere on the path or in any of the installed directories. It looks like there is an entire protoc
-like executable that is built as part of the Python setup.py
installation process. I'm just kind of figuring this out by looking at the gRPC source code, but I am still new to it so could be off on some of this. I'm wondering if some of the tooling is different now?
To give a summary of what I'm triyng to do - I'm attempting to generate Python server and client gRPC code as well as Java client code by using this Gradle plugin. I'm not having much luck doing them both, so I might just have to shell out to the Python gRPC tooling with python -m grpc_tools.protoc
.
from protobuf-gradle-plugin.
It appears grpcio-tools uses an .so version of the plugin, not a normal binary.
from protobuf-gradle-plugin.
@mkobit As @ejona86 pointed out the Python grpcio-tools
package compiles protoc
and the plugin into a single Python extension, unlike most other language packages. This has some advantages like the whole thing being installable via pip install
even for esoteric architectures. We still do have the Python plugin available if you need it, but you'll need to manually checkout the gRPC source tree and run make plugins -j12
to build it.
from protobuf-gradle-plugin.
Related Issues (20)
- Could not find method protobuf() HOT 5
- Task generateProto is not executed before task compileJava during build in version 0.9.3 HOT 7
- How to avoid package proto files into apk HOT 1
- Unable to use lite version - multiple versions of class HOT 31
- How config proto src dir when proto files import by path HOT 2
- Java keyword "public" not escaped during proto generation HOT 1
- doc improvement HOT 1
- How can I disable registering the generated Java code as sources? HOT 7
- KSP dependency on generateProto - unable to build project due to KspTaskJvm issue HOT 1
- Fail on protoc warnings HOT 1
- Feature Request: Allow configuration of java executable HOT 2
- Kotlin only generated classes HOT 2
- extractIncludeProto execute so slowly
- protobuf dependency configuration is marked consumable
- Gradle Java project running into many proto related errors "cannot find symbol" randomly on compiling Java srcs
- Plugin not compiling java code after migration from 0.8.19 -> 0.9.0 HOT 8
- Update sample to use latest plugin version HOT 1
- How can I compile proto files using Protobuf Editions
- Compilation of the generated code fails with protobuf 4.26.0 HOT 1
- Example/documentation for generating kotlin classes with kotlin DSL HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protobuf-gradle-plugin.