Skip to content

Commit aa63bb6

Browse files
authored
cleanup: prefer vcpkg to manage dependencies (#6191)
Use the (relatively new) vcpkg "manifest mode" to download and build dependencies for developers using CMake. We are keeping the superbuild files for now, though I am not sure we need to.
1 parent 19ff123 commit aa63bb6

3 files changed

Lines changed: 65 additions & 26 deletions

File tree

doc/contributor/howto-guide-setup-cmake-environment.md

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,50 +30,43 @@ git clone git@github:<github-username>/google-cloud-cpp.git
3030
cd google-cloud-cpp
3131
```
3232

33-
## Install the dependencies in `$HOME/local-cpp`.
33+
## Download and boostrap `vcpkg`
3434

35-
In this guide we will install the dependencies in `$HOME/local-cpp`, you can
36-
pick any directory where you have write permissions. We will then compile the
37-
project against these dependencies. The installation needs to be done every time
38-
the version of the dependencies is changed. Once installed you can use them for
39-
any build or from any other clone.
40-
41-
Configure the super-build to install in `$HOME/local-cpp`. We recommend that
42-
you use Ninja for this build because it is substantially faster than Make for
43-
these use-cases. Note that if Ninja is not installed in your workstation you may
44-
need to remove the `-GNinja` flag:
35+
[vcpkg] is a package manager for C++ that builds from source and installs any
36+
binary artifacts in `$HOME`. We recommend using `vcpkg` for local development.
37+
In these instructions, we will install `vcpkg` descriptions in `$HOME/vcpkg`,
38+
you can change the `vcpkg` location, just remember to adapt these instructions
39+
as you go along. Download the `vcpkg` package descriptions using `git`:
4540

4641
```shell
47-
cmake -Hsuper -Bcmake-out/si \
48-
-DGOOGLE_CLOUD_CPP_EXTERNAL_PREFIX=$HOME/local-cpp -GNinja
42+
git -C $HOME clone https://github.com/microsoft/vcpkg
4943
```
5044

51-
Install the dependencies:
52-
53-
> **Note:** Ninja will parallelize the build to use all the cores in your
54-
> workstation, if you are not using Ninja, or want to limit the number of cores
55-
> used by the build use the `-j` option.
45+
Then bootstrap the `vcpkg` tool:
5646

5747
```shell
58-
cmake --build cmake-out/si --target project-dependencies
48+
$HOME/vcpkg/bootstrap-vcpkg.sh
5949
```
6050

61-
## Building with the installed dependencies
51+
## Building `google-cloud-cpp` with vcpkg
6252

63-
Now you can use these dependencies from different builds. Configure your CMake
64-
builds with `-DCMAKE_PREFIX_PATH=$HOME/local-cpp` to build `google-cloud-cpp`:
53+
Now you can use `vcpkg` to compile `google-cloud-cpp`. Just add one option
54+
to the `cmake` configure step:
6555

6656
```shell
6757
cd $HOME/google-cloud-cpp
68-
cmake -H. -Bcmake-out/home -DCMAKE_PREFIX_PATH=$HOME/local-cpp
58+
cmake -H. -Bcmake-out/home -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake
6959
cmake --build cmake-out/home
7060
```
7161

72-
You can use these dependencies from other locations too:
62+
The first time you run this command it can take a significant time to download
63+
and compile all the dependencies (Abseil, gRPC, Protobuf, etc). Note that vcpkg
64+
caches binary artifacts (in `$HOME/.cache/vcpkg`) so a second build would be
65+
much faster:
7366

7467
```shell
7568
cd $HOME/another-google-cloud-cpp-clone
76-
cmake -H. -Bcmake-out/home -DCMAKE_PREFIX_PATH=$HOME/local-cpp
69+
cmake -H. -Bcmake-out/home -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake
7770
cmake --build cmake-out/home
7871
```
7972

@@ -104,13 +97,18 @@ installed, you can change the compiler using:
10497

10598
```shell
10699
CXX=clang++ CC=clang \
107-
cmake -H. -Bcmake-out/clang -DCMAKE_PREFIX_PATH=$HOME/local-cpp
100+
cmake -H. -Bcmake-out/home -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake
108101

109102
# Then compile and test normally:
110103
cmake --build cmake-out/clang
111104
(cd cmake-out/clang && ctest --output-on-failure -LE integration-test)
112105
```
113106

107+
`vcpkg` uses the compiler as part of its binary cache inputs, that is, changing
108+
the compiler will require rebuilding the dependencies from source. The good
109+
news is that `vcpkg` can hold multiple versions of a binary artifact in its
110+
cache.
111+
114112
### Changing the build type
115113

116114
By default, the system is compiled with optimizations on; if you want to compile

super/ExternalProjectHelper.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717
include(ExternalProject)
1818
include(GNUInstallDirs)
1919

20+
message(
21+
WARNING
22+
[==[
23+
Super builds are no longer recommended, and will be removed on 2022-05-01
24+
or shortly after. If you want to automatically download and build the
25+
`google-cloud-cpp` dependencies we recommend that you use `vcpkg` as
26+
described in /doc/contributor/howto-guide-setup-cmake-environment.md
27+
]==])
28+
2029
set(GOOGLE_CLOUD_CPP_EXTERNAL_PREFIX
2130
"${CMAKE_BINARY_DIR}/external"
2231
CACHE STRING "Configure where the external projects are installed.")

vcpkg.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "google-cloud-cpp",
3+
"version": "1.27.0",
4+
"description": "C++ Client Libraries for Google Cloud Platform APIs.",
5+
"homepage": "https://github.com/googleapis/google-cloud-cpp",
6+
"license": "Apache-2.0",
7+
"supports": "!uwp",
8+
"$TODO": "move `gtest` and `benchmark` to dev-dependencies",
9+
"dependencies": [
10+
"abseil",
11+
"crc32c",
12+
{
13+
"name": "curl",
14+
"features": [
15+
"ssl"
16+
]
17+
},
18+
{
19+
"name": "grpc",
20+
"host": true
21+
},
22+
{
23+
"name": "protobuf",
24+
"host": true
25+
},
26+
"grpc",
27+
"protobuf",
28+
"nlohmann-json",
29+
"benchmark",
30+
"gtest"
31+
]
32+
}

0 commit comments

Comments
 (0)