mirror of https://github.com/grpc/grpc.git
The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)
https://grpc.io/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
4.6 KiB
145 lines
4.6 KiB
7 years ago
|
gRPC C++ - Building from source
|
||
|
===========================
|
||
9 years ago
|
|
||
8 years ago
|
# Pre-requisites
|
||
9 years ago
|
|
||
8 years ago
|
## Linux
|
||
9 years ago
|
|
||
|
```sh
|
||
7 years ago
|
$ [sudo] apt-get install build-essential autoconf libtool pkg-config
|
||
9 years ago
|
```
|
||
|
|
||
8 years ago
|
If you plan to build from source and run tests, install the following as well:
|
||
|
```sh
|
||
|
$ [sudo] apt-get install libgflags-dev libgtest-dev
|
||
|
$ [sudo] apt-get install clang libc++-dev
|
||
|
```
|
||
|
|
||
7 years ago
|
## MacOS
|
||
9 years ago
|
|
||
8 years ago
|
On a Mac, you will first need to
|
||
|
install Xcode or
|
||
|
[Command Line Tools for Xcode](https://developer.apple.com/download/more/)
|
||
|
and then run the following command from a terminal:
|
||
9 years ago
|
|
||
|
```sh
|
||
|
$ [sudo] xcode-select --install
|
||
|
```
|
||
|
|
||
7 years ago
|
To build gRPC from source, you may need to install the following
|
||
|
packages from [Homebrew](https://brew.sh):
|
||
8 years ago
|
|
||
|
```sh
|
||
|
$ brew install autoconf automake libtool shtool
|
||
|
```
|
||
|
|
||
8 years ago
|
If you plan to build from source and run tests, install the following as well:
|
||
|
```sh
|
||
|
$ brew install gflags
|
||
|
```
|
||
|
|
||
|
*Tip*: when building,
|
||
8 years ago
|
you *may* want to explicitly set the `LIBTOOL` and `LIBTOOLIZE`
|
||
|
environment variables when running `make` to ensure the version
|
||
|
installed by `brew` is being used:
|
||
|
|
||
|
```sh
|
||
|
$ LIBTOOL=glibtool LIBTOOLIZE=glibtoolize make
|
||
|
```
|
||
|
|
||
7 years ago
|
## Windows
|
||
|
|
||
|
To prepare for cmake + Microsoft Visual C++ compiler build
|
||
|
- Install Visual Studio 2015 or 2017 (Visual C++ compiler will be used).
|
||
|
- Install [Git](https://git-scm.com/).
|
||
|
- Install [CMake](https://cmake.org/download/).
|
||
|
- Install [Active State Perl](https://www.activestate.com/activeperl/) (`choco install activeperl`) - *required by boringssl*
|
||
|
- Install [Go](https://golang.org/dl/) (`choco install golang`) - *required by boringssl*
|
||
|
- Install [yasm](http://yasm.tortall.net/) and add it to `PATH` (`choco install yasm`) - *required by boringssl*
|
||
|
- (Optional) Install [Ninja](https://ninja-build.org/) (`choco install ninja`)
|
||
|
|
||
8 years ago
|
## Protoc
|
||
9 years ago
|
|
||
|
By default gRPC uses [protocol buffers](https://github.com/google/protobuf),
|
||
|
you will need the `protoc` compiler to generate stub server and client code.
|
||
|
|
||
9 years ago
|
If you compile gRPC from source, as described below, the Makefile will
|
||
7 years ago
|
automatically try compiling the `protoc` in third_party if you cloned the
|
||
|
repository recursively and it detects that you do not already have 'protoc' compiler
|
||
9 years ago
|
installed.
|
||
9 years ago
|
|
||
7 years ago
|
If 'protoc' compiler has not been installed, following commands can be used for installation.
|
||
7 years ago
|
|
||
|
```sh
|
||
|
$ cd grpc/third_party/protobuf
|
||
|
$ sudo make install # 'make' should have been run by core grpc
|
||
|
```
|
||
|
|
||
7 years ago
|
# Clone the repository (including submodules)
|
||
9 years ago
|
|
||
7 years ago
|
Before building, you need to clone the gRPC github repository and download submodules containing source code
|
||
|
for gRPC's dependencies (that's done by the `submodule` command or `--recursive` flag). The following commands will clone the gRPC
|
||
|
repository at the latest stable version.
|
||
|
|
||
|
## Unix
|
||
9 years ago
|
|
||
|
```sh
|
||
8 years ago
|
$ git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc
|
||
9 years ago
|
$ cd grpc
|
||
|
$ git submodule update --init
|
||
7 years ago
|
```
|
||
8 years ago
|
|
||
8 years ago
|
## Windows
|
||
8 years ago
|
|
||
7 years ago
|
```
|
||
|
> @rem You can also do just "git clone --recursive -b THE_BRANCH_YOU_WANT https://github.com/grpc/grpc"
|
||
|
> powershell git clone --recursive -b ((New-Object System.Net.WebClient).DownloadString(\"https://grpc.io/release\").Trim()) https://github.com/grpc/grpc
|
||
|
> cd grpc
|
||
|
> @rem To update submodules at later time, run "git submodule update --init"
|
||
|
```
|
||
8 years ago
|
|
||
7 years ago
|
# Build from source
|
||
8 years ago
|
|
||
7 years ago
|
In the C++ world, there's no "standard" build system that would work for in all supported use cases and on all supported platforms.
|
||
|
Therefore, gRPC supports several major build systems, which should satisfy most users.
|
||
8 years ago
|
|
||
7 years ago
|
## make (on UNIX systems)
|
||
8 years ago
|
|
||
7 years ago
|
From the grpc repository root
|
||
|
```sh
|
||
|
$ make
|
||
|
```
|
||
7 years ago
|
|
||
7 years ago
|
## bazel
|
||
|
|
||
|
From the grpc repository root
|
||
8 years ago
|
```
|
||
7 years ago
|
bazel build :all
|
||
8 years ago
|
```
|
||
8 years ago
|
|
||
7 years ago
|
## cmake: Windows, Using Visual Studio 2015 or 2017 (can only build with OPENSSL_NO_ASM).
|
||
7 years ago
|
When using the "Visual Studio" generator,
|
||
|
cmake will generate a solution (`grpc.sln`) that contains a VS project for
|
||
|
every target defined in `CMakeLists.txt` (+ few extra convenience projects
|
||
|
added automatically by cmake). After opening the solution with Visual Studio
|
||
7 years ago
|
you will be able to browse and build the code.
|
||
8 years ago
|
```
|
||
7 years ago
|
> @rem Run from grpc directory after cloning the repo with --recursive or updating submodules.
|
||
8 years ago
|
> md .build
|
||
|
> cd .build
|
||
|
> cmake .. -G "Visual Studio 14 2015" -DCMAKE_BUILD_TYPE=Release
|
||
|
> cmake --build .
|
||
|
```
|
||
8 years ago
|
|
||
7 years ago
|
## cmake: Windows, Using Ninja (faster build, supports boringssl's assembly optimizations).
|
||
7 years ago
|
Please note that when using Ninja, you will still need Visual C++ (part of Visual Studio)
|
||
7 years ago
|
installed to be able to compile the C/C++ sources.
|
||
|
```
|
||
7 years ago
|
> @rem Run from grpc directory after cloning the repo with --recursive or updating submodules.
|
||
7 years ago
|
> md .build
|
||
|
> cd .build
|
||
|
> call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" x64
|
||
|
> cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release
|
||
|
> cmake --build .
|
||
|
```
|