[Doc] Added a window section to c++/quickstart (#1361)

* Added a windows section to cpp/quickstart

* Updated cmake version
This commit is contained in:
Esun Kim 2024-09-18 14:22:56 -07:00 committed by GitHub
parent 5ce2eb9679
commit 34c5cb1328
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 86 additions and 22 deletions

View File

@ -3,8 +3,8 @@ title: Quick start
description: This guide gets you started with gRPC in C++ with a simple working example.
weight: 10
spelling: cSpell:ignore autoconf automake cmake cout DCMAKE endl libtool mkdir popd pushd
cmake-min-version: 3.13
cmake-version: 3.19.6
cmake-min-version: 3.16
cmake-version: 3.30.3
---
In the C++ world, there's no universally accepted standard for managing project
@ -23,6 +23,8 @@ Choose a directory to hold locally installed packages. This page assumes that
the environment variable `MY_INSTALL_DIR` holds this directory path. For
example:
- Linux / macOS
```sh
$ export MY_INSTALL_DIR=$HOME/.local
```
@ -39,10 +41,28 @@ Add the local `bin` folder to your path variable, for example:
$ export PATH="$MY_INSTALL_DIR/bin:$PATH"
```
- Windows
```sh
> set MY_INSTALL_DIR=%USERPROFILE%\cmake
```
Ensure that the directory exists:
```
> mkdir %INSTALL_DIR%
```
Add the local `bin` folder to your path variable, for example:
```sh
> set PATH=%PATH%;$MY_INSTALL_DIR\bin
```
#### Install cmake
You need version {{< param cmake-min-version >}} or later of `cmake`. Install it by
following these instructions:
following these instructions if you don't have it:
- Linux
@ -56,6 +76,12 @@ following these instructions:
$ brew install cmake
```
- Windows:
```sh
$ choco install cmake
```
- For general `cmake` installation instructions, see [Installing CMake][].
Check the version of `cmake`:
@ -70,7 +96,7 @@ can install a more recent version into your local installation directory as
follows:
```sh
$ wget -q -O cmake-linux.sh https://github.com/Kitware/CMake/releases/download/v{{< param cmake-version >}}/cmake-{{< param cmake-version >}}-Linux-x86_64.sh
$ wget -q -O cmake-linux.sh https://github.com/Kitware/CMake/releases/download/v{{< param cmake-version >}}/cmake-{{< param cmake-version >}}-linux-x86_64.sh
$ sh cmake-linux.sh -- --skip-license --prefix=$MY_INSTALL_DIR
$ rm cmake-linux.sh
```
@ -106,18 +132,30 @@ for service definitions and data serialization, and the example code uses
The following commands build and locally install gRPC and Protocol Buffers:
```sh
$ cd grpc
$ mkdir -p cmake/build
$ pushd cmake/build
$ cmake -DgRPC_INSTALL=ON \
-DgRPC_BUILD_TESTS=OFF \
-DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR \
../..
$ make -j 4
$ make install
$ popd
```
- Linux & macOS
```sh
$ cd grpc
$ mkdir -p cmake/build
$ pushd cmake/build
$ cmake -DgRPC_INSTALL=ON \
-DgRPC_BUILD_TESTS=OFF \
-DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR \
../..
$ make -j 4
$ make install
$ popd
```
- Windows
```sh
> mkdir "cmake\build"
> pushd "cmake\build"
> cmake -DgRPC_INSTALL=ON -DCMAKE_INSTALL_PREFIX=%MY_INSTALL_DIR% -DgRPC_BUILD_TESTS=OFF ..\..
> cmake --build . --config Release --target install -j 4
> popd
```
{{% alert title="Important" color="warning" %}}
We **strongly** encourage you to install gRPC _locally_ &mdash; using an
@ -145,12 +183,24 @@ the steps of the previous section.
2. Build the example using `cmake`:
```sh
$ mkdir -p cmake/build
$ pushd cmake/build
$ cmake -DCMAKE_PREFIX_PATH=$MY_INSTALL_DIR ../..
$ make -j 4
```
- Linux & macOS
```sh
$ mkdir -p cmake/build
$ pushd cmake/build
$ cmake -DCMAKE_PREFIX_PATH=$MY_INSTALL_DIR ../..
$ make -j 4
```
- Windows
```sh
> mkdir "cmake\build"
> pushd "cmake\build"
> cmake -DCMAKE_INSTALL_PREFIX=%MY_INSTALL_DIR% ..\..
> cmake --build . --config Release -j 4
> popd
```
{{% alert title="Note" color="info" %}}
**Getting build failures?** Most issues, at this point, are the result of a
@ -239,10 +289,18 @@ proto file.
From the example **build** directory `examples/cpp/helloworld/cmake/build`, run:
- Linux & macOS
```sh
$ make -j 4
```
- Windows
```sh
> cmake --build . --config Release -j 4
```
This regenerates `helloworld.pb.{h,cc}` and `helloworld.grpc.pb.{h,cc}`, which
contains the generated client and server classes, as well as classes for
populating, serializing, and retrieving our request and response types.
@ -329,10 +387,16 @@ from the example **build** directory `examples/cpp/helloworld/cmake/build`:
1. Build the client and server after having made changes:
- Linux & macOS
```sh
$ make -j 4
```
- Windows
```sh
> cmake --build . --config Release -j 4
```
2. Run the server:
```sh