blob: 26ed67cd17bff65a4f1c02cc5c536ba5464ff0a4 [file] [log] [blame] [view]
zhangkun83da3c3f82015-03-11 18:03:31 -07001gRPC Java Codegen Plugin for Protobuf Compiler
zhangkun83d54a4632015-01-26 10:53:17 -08002==============================================
3
zhangkun83da3c3f82015-03-11 18:03:31 -07004This generates the Java interfaces out of the service definition from a
5`.proto` file. It works with the Protobuf Compiler (``protoc``).
zhangkun83d54a4632015-01-26 10:53:17 -08006
zhangkun83da3c3f82015-03-11 18:03:31 -07007Normally you don't need to compile the codegen by yourself, since pre-compiled
8binaries for common platforms are available on Maven Central. However, if the
9pre-compiled binaries are not compatible with your system, you may want to
10build your own codegen.
zhangkun83d54a4632015-01-26 10:53:17 -080011
zhangkun83da3c3f82015-03-11 18:03:31 -070012## System requirement
zhangkun83d54a4632015-01-26 10:53:17 -080013
zhangkun83da3c3f82015-03-11 18:03:31 -070014* Linux, Mac OS X with Clang, or Windows with MSYS2
15* Java 7 or up
16* [Protobuf](https://github.com/google/protobuf) 3.0.0-alpha-2 or up
17
18## Compiling and testing the codegen
zhangkun83d54a4632015-01-26 10:53:17 -080019Change to the `compiler` directory:
20```
21$ cd $GRPC_JAVA_ROOT/compiler
22```
23
24To compile the plugin:
25```
zhangkun83da3c3f82015-03-11 18:03:31 -070026$ ../gradlew local_archJava_pluginExecutable
zhangkun83d54a4632015-01-26 10:53:17 -080027```
28
29To test the plugin with the compiler:
30```
zhangkun83da3c3f82015-03-11 18:03:31 -070031$ ../gradlew test
zhangkun83d54a4632015-01-26 10:53:17 -080032```
33You will see a `PASS` if the test succeeds.
34
35To compile a proto file and generate Java interfaces out of the service definitions:
36```
zhangkun83da3c3f82015-03-11 18:03:31 -070037$ protoc --plugin=protoc-gen-java_rpc=build/binaries/java_pluginExecutable/local_arch/protoc-gen-grpc-java \
zhangkun83d54a4632015-01-26 10:53:17 -080038 --java_rpc_out="$OUTPUT_FILE" --proto_path="$DIR_OF_PROTO_FILE" "$PROTO_FILE"
39```
Xiao Hang6f0b21e2015-02-26 11:19:59 -080040To generate Java interfaces with protobuf nano:
41```
zhangkun83da3c3f82015-03-11 18:03:31 -070042$ protoc --plugin=protoc-gen-java_rpc=build/binaries/java_pluginExecutable/local_arch/protoc-gen-grpc-java \
Xiao Hang6f0b21e2015-02-26 11:19:59 -080043 --java_rpc_out=nano=true:"$OUTPUT_FILE" --proto_path="$DIR_OF_PROTO_FILE" "$PROTO_FILE"
44```
zhangkun83da3c3f82015-03-11 18:03:31 -070045
46## Installing the codegen to Maven local repository
47This will compile a codegen and put it under your ``~/.m2/repository``. This
48will make it available to any build tool that pulls codegens from Maven
49repostiories.
50```
51$ ../gradlew install
52```
53
54## Pushing the codegen to Maven Central
55This will compile both the 32-bit and 64-bit versions of the codegen and upload
56them to Maven Central.
57
58You need to have both the 32-bit and 64-bit versions of Protobuf installed.
59It's recommended that you install Protobuf to custom locations (e.g.,
60``~/protobuf-3.0.0-32`` and ``~/protobuf-3.0.0-64``) rather than the system
61default location, so that different version of Protobuf won't mess up. It
62should also be compiled statically linked.
63
64Generally speaking, to compile and install both 32-bit and 64-bit artifacts
65locally. You may want to use ``--info`` so that you know what executables are
66produced.
67```
68$ TARGET_ARCHS="<list-of-archs>" ../gradlew install --info
69```
70
71To compile and upload the artifacts to Maven Central:
72```
73$ TARGET_ARCHS="<list-of-archs>" ../gradlew uploadArchives
74```
75
76It's recommended that you run ``install --info`` prior to ``uploadArchives``
77and examine the produced artifacts before running ``uploadArchives``.
78
79Additional environments need to be set so that the compiler and linker can find
80the protobuf headers and libraries. Follow the platform-specific instructions
81below.
82
83### Note for using Sonatype OSSRH services
84
85A full fledged release is done by running ``uploadArchives`` on multiple
86platforms. After you have successfully run ``uploadArchives`` on the first
87platfrom, you should go to OSSRH UI and find the staging repository that has
88been automatically created. At the subsequent runs of ``uploadArchives``, you
89need to append ``-DrepositoryId=<repository-id-you-just-found>`` to your
90command line, so that the artifacts can be merged in a single release.
91
92### Linux
93You must have multilib GCC installed on your system.
94
95Compile and install 32-bit protobuf:
96```
97protobuf$ CXXFLAGS="-m32" ./configure --disable-shared --prefix=$HOME/protobuf-32
98protobuf$ make clean && make && make install
99```
100
101Compile and install 64-bit protobuf:
102```
103protobuf$ CXXFLAGS="-m64" ./configure --disable-shared --prefix=$HOME/protobuf-64
104protobuf$ make clean && make && make install
105```
106
107Compile and deploy GRPC codegen:
108```
109$ CXXFLAGS="-I$HOME/protobuf-32/include" \
110 LDFLAGS="-L$HOME/protobuf-32/lib -L$HOME/protobuf-64/lib" \
111 TARGET_ARCHS="x86_32 x86_64" ../gradlew uploadArchives
112```
113
114### Windows 64-bit with MSYS2 (Recommended for Windows)
115Because the gcc shipped with MSYS2 doesn't support multilib, you have to
116compile and deploy 32-bit and 64-bit binaries in separate steps.
117
118#### Under MinGW-w64 Win32 Shell
119Compile and install 32-bit protobuf:
120```
121protobuf$ ./configure --disable-shared --prefix=$HOME/protobuf-32
122protobuf$ make clean && make && make install
123```
124
125Compile and deploy GRPC 32-bit codegen
126```
127$ CXXFLAGS="-I$HOME/protobuf-32/include" \
128 LDFLAGS="-L$HOME/protobuf-32/lib" \
129 TARGET_ARCHS="x86_32" ../gradlew uploadArchives
130```
131
132#### Under MinGW-w64 Win64 Shell
133Compile and install 64-bit protobuf:
134```
135protobuf$ ./configure --disable-shared --prefix=$HOME/protobuf-64
136protobuf$ make clean && make && make install
137```
138
139Compile and deploy GRPC 64-bit codegen:
140```
141$ CXXFLAGS="-I$HOME/protobuf-64/include" \
142 LDFLAGS="-L$HOME/protobuf-64/lib" \
143 TARGET_ARCHS="x86_64" ../gradlew uploadArchives
144```
145
146### Windows 64-bit with Cygwin64 (TODO: incomplete)
147Because the MinGW gcc shipped with Cygwin64 doesn't support multilib, you have
148to compile and deploy 32-bit and 64-bit binaries in separate steps.
149
150Compile and install 32-bit protobuf. ``-static-libgcc -static-libstdc++`` are
151needed for ``protoc`` to be successfully run in the unit test.
152```
153protobuf$ LDFLAGS="-static-libgcc -static-libstdc++" ./configure --host=i686-w64-mingw32 --disable-shared --prefix=$HOME/protobuf-32
154protobuf$ make clean && make && make install
155```
156
157Compile and install 64-bit protobuf:
158```
159protobuf$ ./configure --host=x86_64-w64-mingw32 --disable-shared --prefix=$HOME/protobuf-64
160protobuf$ make clean && make && make install
161```
162
163### Mac
164Please refer to [Protobuf
165README](https://github.com/google/protobuf/blob/master/README.md) for how to
166set up GCC and Unix tools on Mac.
167
168Mac OS X has been 64-bit-only since 10.7 and we are compiling for 10.7 and up.
169We only build 64-bit artifact for Mac.
170
171Compile and install protobuf:
172```
173protobuf$ CXXFLAGS="-m64" ./configure --disable-shared --prefix=$HOME/protobuf
174protobuf$ make clean && make && make install
175```
176
177Compile and deploy GRPC codegen:
178```
179$ CXXFLAGS="-I$HOME/protobuf/include" \
180 LDFLAGS="$HOME/protobuf/lib/libprotobuf.a $HOME/protobuf/lib/libprotoc.a" \
181 TARGET_ARCHS="x86_64" ../gradlew uploadArchives
182```