blob: 0e4b5e668d32c0702343dbad600d3d4ecdce5a3a [file] [log] [blame] [view]
Eric Anderson1b1c6462015-08-14 08:49:56 -07001Building gRPC-Java
2==================
3
4Building is only necessary if you are making changes to gRPC-Java.
5
6Building requires JDK 8, as our tests use TLS.
7
8grpc-java has a C++ code generation plugin for protoc. Since many Java
9developers don't have C compilers installed and don't need to modify the
10codegen, the build can skip it. To skip, create the file
11`<project-root>/gradle.properties` and add `skipCodegen=true`.
12
13Then, to build, run:
14```
15$ ./gradlew build
16```
17
18To install the artifacts to your Maven local repository for use in your own
19project, run:
20```
21$ ./gradlew install
22```
23
24How to Build Code Generation Plugin
25-----------------------------------
26This section is only necessary if you are making changes to the code
27generation. Most users only need to use `skipCodegen=true` as discussed above.
28
29### Build Protobuf
Eric Andersonb1d72e52016-09-27 17:15:12 -070030The codegen plugin is C++ code and requires protobuf 3.0.0 or later.
Eric Anderson1b1c6462015-08-14 08:49:56 -070031
32For Linux, Mac and MinGW:
33```
34$ git clone https://github.com/google/protobuf.git
35$ cd protobuf
Kun Zhang86d64122018-01-05 16:40:20 -080036$ git checkout v3.5.1
Eric Anderson1b1c6462015-08-14 08:49:56 -070037$ ./autogen.sh
38$ ./configure
39$ make
40$ make check
41$ sudo make install
42```
43
44If you are comfortable with C++ compilation and autotools, you can specify a
45``--prefix`` for Protobuf and use ``-I`` in ``CXXFLAGS``, ``-L`` in
46``LDFLAGS``, ``LD_LIBRARY_PATH``, and ``PATH`` to reference it. The
47environment variables will be used when building grpc-java.
48
49Protobuf installs to ``/usr/local`` by default.
50
Eric Andersond04994f2015-09-24 15:27:26 -070051For Visual C++, please refer to the [Protobuf README](https://github.com/google/protobuf/blob/master/cmake/README.md)
52for how to compile Protobuf. gRPC-java assumes a Release build.
Eric Anderson1b1c6462015-08-14 08:49:56 -070053
54#### Linux and MinGW
55If ``/usr/local/lib`` is not in your library search path, you can add it by running:
56```
57$ sudo sh -c 'echo /usr/local/lib >> /etc/ld.so.conf'
58$ sudo ldconfig
59```
60
61#### Mac
62Some versions of Mac OS X (e.g., 10.10) doesn't have ``/usr/local`` in the
63default search paths for header files and libraries. It will fail the build of
64the codegen. To work around this, you will need to set environment variables:
65```
66$ export CXXFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"
67```
68
69### Notes for Visual C++
70
71When building on Windows and VC++, you need to specify project properties for
72Gradle to find protobuf:
73```
74.\gradlew install ^
Kun Zhang86d64122018-01-05 16:40:20 -080075 -PvcProtobufInclude=C:\path\to\protobuf-3.5.1\src ^
76 -PvcProtobufLibs=C:\path\to\protobuf-3.5.1\vsprojects\Release ^
Eric Andersond04994f2015-09-24 15:27:26 -070077 -PtargetArch=x86_32
Eric Anderson1b1c6462015-08-14 08:49:56 -070078```
79
80Since specifying those properties every build is bothersome, you can instead
81create ``<project-root>\gradle.properties`` with contents like:
82```
Kun Zhang86d64122018-01-05 16:40:20 -080083vcProtobufInclude=C:\\path\\to\\protobuf-3.5.1\\src
84vcProtobufLibs=C:\\path\\to\\protobuf-3.5.1\\vsprojects\\Release
Eric Andersond04994f2015-09-24 15:27:26 -070085targetArch=x86_32
Eric Anderson1b1c6462015-08-14 08:49:56 -070086```
87
Eric Andersond04994f2015-09-24 15:27:26 -070088By default, the build script will build the codegen for the same architecture as
89the Java runtime installed on your system. If you are using 64-bit JVM, the
90codegen will be compiled for 64-bit. Since Protobuf is only built for 32-bit by
91default, the `targetArch=x86_32` is necessary.
Eric Anderson1b1c6462015-08-14 08:49:56 -070092
93### Notes for MinGW on Windows
94If you have both MinGW and VC++ installed on Windows, VC++ will be used by
95default. To override this default and use MinGW, add ``-PvcDisable=true``
96to your Gradle command line or add ``vcDisable=true`` to your
97``<project-root>\gradle.properties``.
98
99### Notes for Unsupported Operating Systems
100The build script pulls pre-compiled ``protoc`` from Maven Central by default.
101We have built ``protoc`` binaries for popular systems, but they may not work
102for your system. If ``protoc`` cannot be downloaded or would not run, you can
103use the one that has been built by your own, by adding this property to
104``<project-root>/gradle.properties``:
105```
106protoc=/path/to/protoc
107```