Skip to content

Commit fb28ad2

Browse files
committed
Improve Gradle build of protoc grpc plugin
A Gradle protoc plugin is used for generating and compiling the grpc codegen. The code organization was changed to match what Gradle expects. Proto 3 is now required.
1 parent d0e883a commit fb28ad2

10 files changed

Lines changed: 68 additions & 39 deletions

File tree

README.md

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,48 @@
11
grpc-java
22
=========
33

4+
How to Build
5+
------------
6+
7+
grpc-java requires Netty 5, which is still in flux. The version we need can be
8+
found in the lib/netty submodule:
9+
```
10+
$ git submodule update --init
11+
$ cd lib/netty
12+
$ mvn install -pl codec-http2 -am -DskipTests=true
13+
```
14+
15+
The codegen plugin requires a recent protobuf build from master (what will
16+
become proto3):
17+
```
18+
$ git clone https://github.com/google/protobuf.git
19+
$ cd protobuf
20+
$ ./autogen.sh
21+
$ ./configure
22+
$ make
23+
$ make check
24+
$ sudo make install
25+
$ cd java
26+
$ mvn install
27+
```
28+
29+
If you are comfortable with C++ compilation and autotools, you can specify a
30+
--prefix for protobuf and use -I in CXXFLAGS, -L in LDFLAGS, LD\_LIBRARY\_PATH,
31+
and PATH to reference it. The environment variables will be used when building
32+
grpc-java.
33+
34+
Now to build grpc-java itself:
35+
```
36+
$ ./gradlew install
37+
```
38+
39+
Navigating Around the Source
40+
----------------------------
41+
442
Heres a quick readers guide to the code to help folks get started. At a high level there are three distinct layers
543
to the library: stub, channel & transport.
644

7-
## Stub
45+
### Stub
846

947
The 'stub' layer is what is exposed to most developers and provides type-safe bindings to whatever
1048
datamodel/IDL/interface you are adapting. An example is provided of a binding to code generated by the protocol-buffers compiler but others should be trivial to add and are welcome.
@@ -14,7 +52,7 @@ datamodel/IDL/interface you are adapting. An example is provided of a binding to
1452
[Stream Observer](https://github.com/google/grpc-java/blob/master/stub/src/main/java/io/grpc/stub/StreamObserver.java)
1553

1654

17-
## Channel
55+
### Channel
1856

1957
The 'channel' layer is an abstraction over transport handling that is suitable for interception/decoration and exposes more behavior to the application than the stub layer. It is intended to be easy for application frameworks to use this layer to address cross-cutting concerns such as logging, monitoring, auth etc. Flow-control is also exposed at this layer to allow more sophisticated applications to interact with it directly.
2058

@@ -33,7 +71,7 @@ The 'channel' layer is an abstraction over transport handling that is suitable f
3371
* [Server Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ServerCall.java)
3472

3573

36-
## Transport
74+
### Transport
3775

3876
The 'transport' layer does the heavy lifting of putting & taking bytes off the wire. The interfaces to it are abstract just enough to allow plugging in of different implementations. Transports are modeled as 'Stream' factories. The variation in interface between a server stream and a client stream exists to codify their differing semantics for cancellation and error reporting.
3977

@@ -53,6 +91,6 @@ The 'transport' layer does the heavy lifting of putting & taking bytes off the w
5391
* [Server Stream Listener](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ServerStreamListener.java)
5492

5593

56-
# Examples
94+
### Examples
5795

5896
Tests showing how these layers are composed to execute calls using protobuf messages can be found here https://github.com/google/grpc-java/tree/master/integration-testing/src/main/java/io/grpc/testing/integration

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ subprojects {
2020

2121
// External dependency management
2222
ext.libraries = [
23-
protobuf: 'com.google.protobuf:protobuf-java:2.6.1',
23+
protobuf: 'com.google.protobuf:protobuf-java:3.0.0-pre',
2424
guava: 'com.google.guava:guava:18.0',
2525
jsr305: 'com.google.code.findbugs:jsr305:3.0.0',
2626
oauth_client: 'com.google.oauth-client:google-oauth-client:1.18.0-rc',

compiler/build.gradle

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
apply plugin: "cpp"
2+
apply plugin: "protobuf"
23

34
description = 'The protoc plugin for gRPC Java'
45

6+
buildscript {
7+
repositories {
8+
mavenCentral()
9+
}
10+
dependencies {
11+
classpath libraries.protobuf_plugin
12+
}
13+
}
14+
515
executables {
616
java_plugin {}
717
}
818

19+
dependencies {
20+
compile project(':grpc-stub'),
21+
libraries.protobuf
22+
}
23+
924
binaries.all {
1025
if (toolChain in Gcc) {
1126
cppCompiler.args "-std=c++11"
@@ -22,19 +37,13 @@ binaries.all {
2237
}
2338
}
2439

25-
sources {
26-
java_plugin {
27-
// Configure an existing CppSourceSet
28-
cpp {
29-
source {
30-
srcDirs "src/"
31-
include "**/*.cc"
32-
}
33-
}
34-
}
35-
}
40+
protobufCodeGenPlugins = ["java_plugin:$buildDir/binaries/java_pluginExecutable/java_plugin"]
41+
42+
generateTestProto.dependsOn 'java_pluginExecutable'
43+
test.dependsOn 'testGolden'
3644

37-
task test(type: Exec, dependsOn: 'java_pluginExecutable') {
38-
environment 'TEST_TMP_DIR', temporaryDir
39-
commandLine './run_test.sh'
45+
task testGolden(type: Exec, dependsOn: 'generateTestProto') {
46+
executable "diff"
47+
args "$buildDir/generated-sources/test/io/grpc/testing/integration/TestServiceGrpc.java",
48+
"$projectDir/src/test/golden/TestService.java.txt"
4049
}

compiler/run_test.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ include ":grpc-auth"
55
include ":grpc-okhttp"
66
include ":grpc-netty"
77
include ":grpc-testing"
8+
include ":grpc-compiler"
89
include ":grpc-integration-testing"
910
include ":grpc-all"
1011

@@ -14,5 +15,6 @@ project(':grpc-auth').projectDir = "$rootDir/auth" as File
1415
project(':grpc-okhttp').projectDir = "$rootDir/okhttp" as File
1516
project(':grpc-netty').projectDir = "$rootDir/netty" as File
1617
project(':grpc-testing').projectDir = "$rootDir/testing" as File
18+
project(':grpc-compiler').projectDir = "$rootDir/compiler" as File
1719
project(':grpc-integration-testing').projectDir = "$rootDir/integration-testing" as File
1820
project(':grpc-all').projectDir = "$rootDir/all" as File

0 commit comments

Comments
 (0)