| Eric Anderson | 1b1c646 | 2015-08-14 08:49:56 -0700 | [diff] [blame] | 1 | Building gRPC-Java | 
 | 2 | ================== | 
 | 3 |  | 
 | 4 | Building is only necessary if you are making changes to gRPC-Java. | 
 | 5 |  | 
 | 6 | Building requires JDK 8, as our tests use TLS. | 
 | 7 |  | 
 | 8 | grpc-java has a C++ code generation plugin for protoc. Since many Java | 
 | 9 | developers don't have C compilers installed and don't need to modify the | 
 | 10 | codegen, the build can skip it. To skip, create the file | 
 | 11 | `<project-root>/gradle.properties` and add `skipCodegen=true`. | 
 | 12 |  | 
 | 13 | Then, to build, run: | 
 | 14 | ``` | 
 | 15 | $ ./gradlew build | 
 | 16 | ``` | 
 | 17 |  | 
 | 18 | To install the artifacts to your Maven local repository for use in your own | 
 | 19 | project, run: | 
 | 20 | ``` | 
 | 21 | $ ./gradlew install | 
 | 22 | ``` | 
 | 23 |  | 
 | 24 | How to Build Code Generation Plugin | 
 | 25 | ----------------------------------- | 
 | 26 | This section is only necessary if you are making changes to the code | 
 | 27 | generation. Most users only need to use `skipCodegen=true` as discussed above. | 
 | 28 |  | 
 | 29 | ### Build Protobuf | 
| Kun Zhang | bd23a8d | 2015-08-28 18:47:06 -0700 | [diff] [blame] | 30 | The codegen plugin is C++ code and requires protobuf 3.0.0-beta-1. | 
| Eric Anderson | 1b1c646 | 2015-08-14 08:49:56 -0700 | [diff] [blame] | 31 |  | 
 | 32 | For Linux, Mac and MinGW: | 
 | 33 | ``` | 
 | 34 | $ git clone https://github.com/google/protobuf.git | 
 | 35 | $ cd protobuf | 
| Kun Zhang | bd23a8d | 2015-08-28 18:47:06 -0700 | [diff] [blame] | 36 | $ git checkout v3.0.0-beta-1 | 
| Eric Anderson | 1b1c646 | 2015-08-14 08:49:56 -0700 | [diff] [blame] | 37 | $ ./autogen.sh | 
 | 38 | $ ./configure | 
 | 39 | $ make | 
 | 40 | $ make check | 
 | 41 | $ sudo make install | 
 | 42 | ``` | 
 | 43 |  | 
 | 44 | If 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 | 
 | 47 | environment variables will be used when building grpc-java. | 
 | 48 |  | 
 | 49 | Protobuf installs to ``/usr/local`` by default. | 
 | 50 |  | 
 | 51 | For Visual C++, please refer to the [Protobuf README](https://github.com/google/protobuf/blob/master/vsprojects/readme.txt) | 
 | 52 | for how to compile Protobuf. | 
 | 53 |  | 
 | 54 | #### Linux and MinGW | 
 | 55 | If ``/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 | 
 | 62 | Some versions of Mac OS X (e.g., 10.10) doesn't have ``/usr/local`` in the | 
 | 63 | default search paths for header files and libraries. It will fail the build of | 
 | 64 | the 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 |  | 
 | 71 | When building on Windows and VC++, you need to specify project properties for | 
 | 72 | Gradle to find protobuf: | 
 | 73 | ``` | 
 | 74 | .\gradlew install ^ | 
| Kun Zhang | bd23a8d | 2015-08-28 18:47:06 -0700 | [diff] [blame] | 75 |     -PvcProtobufInclude=C:\path\to\protobuf-3.0.0-beta-1\src ^ | 
 | 76 |     -PvcProtobufLibs=C:\path\to\protobuf-3.0.0-beta-1\vsprojects\Release | 
| Eric Anderson | 1b1c646 | 2015-08-14 08:49:56 -0700 | [diff] [blame] | 77 | ``` | 
 | 78 |  | 
 | 79 | Since specifying those properties every build is bothersome, you can instead | 
 | 80 | create ``<project-root>\gradle.properties`` with contents like: | 
 | 81 | ``` | 
| Kun Zhang | bd23a8d | 2015-08-28 18:47:06 -0700 | [diff] [blame] | 82 | vcProtobufInclude=C:\\path\\to\\protobuf-3.0.0-beta-1\\src | 
 | 83 | vcProtobufLibs=C:\\path\\to\\protobuf-3.0.0-beta-1\\vsprojects\\Release | 
| Eric Anderson | 1b1c646 | 2015-08-14 08:49:56 -0700 | [diff] [blame] | 84 | ``` | 
 | 85 |  | 
 | 86 | The build script will build the codegen for the same architecture as the Java | 
 | 87 | runtime installed on your system. If you are using 64-bit JVM, the codegen will | 
 | 88 | be compiled for 64-bit, that means you must have compiled Protobuf in 64-bit. | 
 | 89 |  | 
 | 90 | ### Notes for MinGW on Windows | 
 | 91 | If you have both MinGW and VC++ installed on Windows, VC++ will be used by | 
 | 92 | default. To override this default and use MinGW, add ``-PvcDisable=true`` | 
 | 93 | to your Gradle command line or add ``vcDisable=true`` to your | 
 | 94 | ``<project-root>\gradle.properties``. | 
 | 95 |  | 
 | 96 | ### Notes for Unsupported Operating Systems | 
 | 97 | The build script pulls pre-compiled ``protoc`` from Maven Central by default. | 
 | 98 | We have built ``protoc`` binaries for popular systems, but they may not work | 
 | 99 | for your system. If ``protoc`` cannot be downloaded or would not run, you can | 
 | 100 | use the one that has been built by your own, by adding this property to | 
 | 101 | ``<project-root>/gradle.properties``: | 
 | 102 | ``` | 
 | 103 | protoc=/path/to/protoc | 
 | 104 | ``` |