Skip to content

Commit 0596ba3

Browse files
authored
Breaking: Remove Cmake gRPC install when not found (googleforgames#3621)
Breaking: Remove Cmake gRPC install when not found gRPC upgrades with gRPC where very brittle, and attempts to upgrade dependencies and/or switch to a `FetchContent_Declare` type workflow were becoming increasingly time-consuming - and not resulting with a working solution. Speaking with the gRPC team, they recommended not installing dependencies within CMake (and how they do it admittedly an antipattern). So this change removes the ability for the CMakeLists.txt to install gRPC and makes finding the gRPC dependency a hard requirement, and updates the documentation accordingly. This change isn't onerous to the end user, as our SDK has only the one dependency - gRPC (which does install all its dependencies). At some point gRPC will have official support for vcpkg, at which point we should probably move with them - but in the meantime, the cpp-simple example has been updated with this change, and it's an extra ~4 lines. This update also include a lot of other fixes: * Upgrade from Debian Bullseye to Bookworm for all cpp related containers * Builds now actually happen in parallel, reducing build time to minutes not hours. * Bump to gRPC 1.57.1 * Fix bug with gRPC dependency utf8_range. * Move to C++17, because it's required for gRPC. Work on googleforgames#3570
1 parent eb42fa7 commit 0596ba3

File tree

15 files changed

+184
-367
lines changed

15 files changed

+184
-367
lines changed

.github/ISSUE_TEMPLATE/kubernetes_update.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ List of items to do for upgrading to {version_1} {version_2} {version_3}
3939
- [ ] `dev_minikube_example_cluster_version`, which is {version_2} with the supported patch version
4040
- [ ] If client-go pulled in a new version of gRPC, then also
4141
- [ ] Update the `grpc_release_tag` in the SDK [base image grpc version](https://github.com/googleforgames/agones/blob/main/build/includes/sdk.mk).
42-
- [ ] Update the gRPC version number in C++ CMake scripts, `AGONES_GRPC_VERSION` [here](https://github.com/googleforgames/agones/blob/main/sdks/cpp/CMakeLists.txt)
43-
and `gRPC_GIT_TAG` [here](https://github.com/googleforgames/agones/blob/main/sdks/cpp/cmake/prerequisites.cmake)
42+
- [ ] Update the gRPC version number in C++ gRPC Dependency documentation [here](https://github.com/googleforgames/agones/blob/main/site/content/en/docs/Guides/Client%20SDKs/cpp.md).
43+
- [ ] Update the gRPC version
44+
([Dockerfile](https://github.com/googleforgames/agones/blob/main/examples/cpp-simple/Dockerfile)) and
45+
increment the image tag
46+
([Makefile](https://github.com/googleforgames/agones/blob/main/examples/cpp-simple/Makefile)) in the C++
47+
`cpp-simple` example.
4448
- [ ] Regenerate all client sdks: [make gen-all-sdk-grpc](https://github.com/googleforgames/agones/blob/main/build/README.md#make-gen-all-sdk-grpc)
45-
This can take an hour or so, as the above changes force a rebuild. Plan your day accordingly 😃.
49+
This can take 20 minutes or so, as the above changes force a rebuild. Plan your day accordingly 😃.
4650
- [ ] Regenerate allocated API endpoints: [make gen-allocation-grpc](https://github.com/googleforgames/agones/blob/main/build/README.md#make-gen-allocation-grpc)
4751
- [ ] Confirm the update works as expected by running e2e tests
4852
- [ ] Add the new supported Kubernetes versions to the e2e clusters creation

build/build-sdk-images/cpp/build-sdk-test.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ then
2525
mkdir -p "$DIR"/sdk/.build
2626
cp -r /go/src/agones.dev/agones/sdks/cpp/* $DIR/sdk
2727
cd $DIR/sdk/.build
28-
cmake .. -DCMAKE_BUILD_TYPE=Release -DAGONES_SILENT_OUTPUT=OFF -DCMAKE_INSTALL_PREFIX=$DIR/sdk/.build -DAGONES_THIRDPARTY_INSTALL_PATH=$DIR/sdk/.build -G "Unix Makefiles" -Wno-dev
28+
cmake .. -DCMAKE_BUILD_TYPE=Release -DAGONES_SILENT_OUTPUT=OFF \
29+
-DCMAKE_INSTALL_PREFIX=$DIR/sdk/.build -G "Unix Makefiles" -Wno-dev
2930
else
3031
echo "Directory with cpp SDK third party dependencies \
3132
has already built - using cached version. \

build/build-sdk-images/restapi/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ RUN wget -q https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz && \
2828

2929
RUN echo '§' && apt-get -qy update
3030

31-
RUN apt-get install -qq -y openjdk-11-jre > /dev/null
31+
RUN apt-get install -qq -y openjdk-17-jre > /dev/null
3232

3333
ENV PATH /usr/local/go/bin:/go/bin:$PATH
3434

build/build-sdk-images/tool/base/Dockerfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,20 @@
1717
# Base images for SDKs Bump: 3
1818
#
1919

20-
FROM debian:bullseye
20+
FROM debian:bookworm
2121

2222
RUN apt-get update && apt-get install -y \
2323
build-essential autoconf libtool git pkg-config curl \
2424
automake libtool curl make g++ unzip moreutils cmake \
2525
&& apt-get clean
2626

2727
ARG GRPC_RELEASE_TAG
28-
# install protobuf first, then grpc
28+
# Install grpc locally for reuse across builds.
2929
RUN git clone --recurse-submodules -b $GRPC_RELEASE_TAG --depth 1 --shallow-submodules https://github.com/grpc/grpc /var/local/git/grpc && \
3030
cd /var/local/git/grpc && \
3131
mkdir -p cmake/build && \
3232
cd cmake/build && \
33+
export CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) && \
3334
cmake -DCMAKE_BUILD_TYPE=Release -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF ../.. && \
3435
make -j$(nproc) && make install
3536

build/includes/sdk.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# \__, |_| \_\_| \____| |_|\___/ \___/|_|_|_| |_|\__, |
2121
# |___/ |___/
2222

23-
grpc_release_tag = v1.57.0
23+
grpc_release_tag = v1.57.1
2424

2525
build_sdk_base_version = $(call sha,$(build_path)/build-sdk-images/tool/base/Dockerfile)_$(grpc_release_tag)
2626
build_sdk_base_tag = agones-build-sdk-base:$(build_sdk_base_version)

build/release/post_cloudbuild.yaml

+2-4
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ steps:
3939
id: cpp-sdk-build-restore-cache
4040
args:
4141
- --bucket=gs://$_CACHE_BUCKET
42-
- --key=$_CPP_SDK_BUILD_CACHE_KEY-$( checksum sdks/cpp/cmake/prerequisites.cmake
43-
)
42+
- --key=$_CPP_SDK_BUILD_CACHE_KEY-$( checksum sdks/cpp/CMakeLists.txt )
4443
- name: us-docker.pkg.dev/$PROJECT_ID/ci/restore_cache
4544
id: cpp-sdk-conformance-restore-cache
4645
args:
4746
- --bucket=gs://$_CACHE_BUCKET
48-
- --key=$_CPP_SDK_CONFORMANCE_CACHE_KEY-$( checksum sdks/cpp/cmake/prerequisites.cmake
49-
)
47+
- --key=$_CPP_SDK_CONFORMANCE_CACHE_KEY-$( checksum sdks/cpp/CMakeLists.txt )
5048
- name: us-docker.pkg.dev/$PROJECT_ID/ci/restore_cache
5149
id: rust-sdk-build-restore-cache
5250
args:

cloudbuild.yaml

+4-8
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,13 @@ steps:
4242
id: cpp-sdk-build-restore-cache
4343
args:
4444
- --bucket=gs://$_CACHE_BUCKET
45-
- --key=$_CPP_SDK_BUILD_CACHE_KEY-$( checksum sdks/cpp/cmake/prerequisites.cmake
46-
)
45+
- --key=$_CPP_SDK_BUILD_CACHE_KEY-$( checksum sdks/cpp/CMakeLists.txt )
4746
waitFor: ['-']
4847
- name: us-docker.pkg.dev/$PROJECT_ID/ci/restore_cache
4948
id: cpp-sdk-conformance-restore-cache
5049
args:
5150
- --bucket=gs://$_CACHE_BUCKET
52-
- --key=$_CPP_SDK_CONFORMANCE_CACHE_KEY-$( checksum sdks/cpp/cmake/prerequisites.cmake
53-
)
51+
- --key=$_CPP_SDK_CONFORMANCE_CACHE_KEY-$( checksum sdks/cpp/CMakeLists.txt )
5452
waitFor: ['-']
5553
- name: us-docker.pkg.dev/$PROJECT_ID/ci/restore_cache
5654
id: rust-sdk-build-restore-cache
@@ -187,8 +185,7 @@ steps:
187185
- name: us-docker.pkg.dev/$PROJECT_ID/ci/save_cache
188186
args:
189187
- --bucket=gs://$_CACHE_BUCKET
190-
- --key=$_CPP_SDK_BUILD_CACHE_KEY-$( checksum sdks/cpp/cmake/prerequisites.cmake
191-
)
188+
- --key=$_CPP_SDK_BUILD_CACHE_KEY-$( checksum sdks/cpp/CMakeLists.txt )
192189
- --path=sdks/cpp/.build
193190
id: cpp-sdk-build-save-cache
194191
waitFor:
@@ -350,8 +347,7 @@ steps:
350347
- name: us-docker.pkg.dev/$PROJECT_ID/ci/save_cache
351348
args:
352349
- --bucket=gs://$_CACHE_BUCKET
353-
- --key=$_CPP_SDK_CONFORMANCE_CACHE_KEY-$( checksum sdks/cpp/cmake/prerequisites.cmake
354-
)
350+
- --key=$_CPP_SDK_CONFORMANCE_CACHE_KEY-$( sdks/cpp/CMakeLists.txt )
355351
- --path=test/sdk/cpp/sdk
356352
id: cpp-sdk-conformance-save-cache
357353
waitFor:

examples/cpp-simple/CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
cmake_minimum_required (VERSION 3.13.0)
15+
cmake_minimum_required(VERSION 3.15)
1616

1717
project(cpp-simple CXX)
1818

1919
# Settings
20-
set(CMAKE_CXX_STANDARD 14)
20+
set(CMAKE_CXX_STANDARD 17)
2121
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
2222
set(CMAKE_CXX_EXTENSIONS OFF)
2323
set(CMAKE_INCLUDE_CURRENT_DIR ON)
@@ -38,7 +38,6 @@ elseif(UNIX AND NOT APPLE)
3838
# Linux
3939
endif()
4040

41-
4241
include_directories(${agones_INCLUDE_DIRS})
4342
set(SRC_FILES "server.cc")
4443

examples/cpp-simple/Dockerfile

+18-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM debian:bullseye as builder
15+
FROM debian:bookworm as builder
1616

1717
RUN apt-get update && apt-get install -y \
1818
build-essential autoconf libtool git pkg-config \
@@ -21,24 +21,39 @@ RUN apt-get update && apt-get install -y \
2121

2222
WORKDIR /project
2323

24+
# Install gRPC and dependencies
25+
RUN git clone --recurse-submodules -b v1.57.1 --depth 1 --shallow-submodules https://github.com/grpc/grpc /var/local/git/grpc && \
26+
cd /var/local/git/grpc && \
27+
mkdir -p cmake/build && \
28+
cd cmake/build && \
29+
export CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) && \
30+
cmake -DCMAKE_BUILD_TYPE=Release \
31+
-DgRPC_INSTALL=ON \
32+
-DgRPC_BUILD_TESTS=OFF ../.. && \
33+
make -j$(nproc) && make install
34+
35+
# Install Agones SDK
2436
COPY ./sdks/cpp sdk
2537
RUN cd sdk && \
2638
mkdir -p .build && \
2739
cd .build && \
40+
export CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) && \
2841
cmake .. -DCMAKE_BUILD_TYPE=Release -DAGONES_SILENT_OUTPUT=OFF -DCMAKE_INSTALL_PREFIX=/project/sdk/.build \
29-
-DAGONES_THIRDPARTY_INSTALL_PATH=/project/sdk/.build -G "Unix Makefiles" -Wno-dev && \
42+
-G "Unix Makefiles" -Wno-dev && \
3043
cmake --build . --target install -j$(nproc)
3144

45+
# Build sample application
3246
COPY ./examples/cpp-simple cpp-simple
3347
RUN cd cpp-simple && mkdir -p .build && cd .build && \
48+
export CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) && \
3449
cmake .. -G "Unix Makefiles" \
3550
-DCMAKE_BUILD_TYPE=Release \
3651
-DCMAKE_PREFIX_PATH=/project/sdk/.build \
3752
-Dagones_DIR=/project/sdk/.build/agones/cmake \
3853
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=.bin && \
3954
cmake --build . --target install -j$(nproc)
4055

41-
FROM debian:bullseye
56+
FROM debian:bookworm
4257
RUN useradd -u 1000 -m server
4358

4459
COPY --from=builder --chown=server:server /project/cpp-simple/.build/.bin/cpp-simple /home/server/cpp-simple

examples/cpp-simple/Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ PROD_REPO ?= us-docker.pkg.dev/agones-images/examples
3030
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
3131
project_path := $(dir $(mkfile_path))
3232
root_path = $(realpath $(project_path)/../..)
33+
version := 0.17
3334
ifeq ($(REPOSITORY),)
34-
server_tag := cpp-simple-server:0.16
35+
server_tag := cpp-simple-server:$(version)
3536
else
36-
server_tag := $(REPOSITORY)/cpp-simple-server:0.16
37+
server_tag := $(REPOSITORY)/cpp-simple-server:$(version)
3738
endif
3839

3940
# _____ _

sdks/cpp/CMakeLists.txt

+13-22
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
cmake_minimum_required (VERSION 3.5.0)
15+
cmake_minimum_required(VERSION 3.15)
1616

1717
# Silent cmake/build output (internal option)
1818
# Extra command line options
@@ -62,45 +62,36 @@ project(agones VERSION ${AGONES_VERSION} HOMEPAGE_URL https://github.com/googlef
6262

6363
# Options
6464
option(AGONES_FORCE_GRPC_VERSION "Build Agones C++ SDK only with supported gRPC version" ON)
65-
option(AGONES_BUILD_ONLY_PREREQUISITIES "Build only prerequisites of Agones" OFF)
66-
option(AGONES_ZLIB_STATIC "Use static version of ZLIB" ON)
67-
option(AGONES_BUILD_THIRDPARTY_DEBUG "Build debug version of thirdparty libraries (MSVC only)" OFF)
6865
option(AGONES_CLANG_FORMAT "Apply clang-format (if found) as a pre-build step" OFF)
69-
set(AGONES_THIRDPARTY_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}" CACHE STRING "Path for installing third-party OpenSSL and gRPC, if they are not found with find_package")
70-
set(AGONES_OPENSSL_CONFIG_STRING "VC-WIN64A" CACHE STRING "See https://github.com/openssl/openssl/blob/OpenSSL_1_1_1-stable/INSTALL for details")
7166

7267
# Prerequisities
7368
# [markmandel] - not 100% sure what include(CMakeFindDependencyMacro) does, but it solves the building issue.
7469
# https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#creating-a-package-configuration-file
7570
include(CMakeFindDependencyMacro)
76-
include(./cmake/prerequisites.cmake)
77-
find_package(Threads REQUIRED)
78-
find_package(ZLIB REQUIRED)
79-
find_package(Protobuf REQUIRED CONFIG)
80-
find_package(gRPC ${AGONES_GRPC_VERSION} ${AGONES_GRPC_VERSION_MATCH} REQUIRED CONFIG)
71+
include(ProcessorCount)
8172

82-
if (AGONES_BUILD_ONLY_PREREQUISITIES)
83-
return()
73+
ProcessorCount(CPU_COUNT)
74+
if (CPU_COUNT GREATER 0 AND NOT DEFINED CMAKE_BUILD_PARALLEL_LEVEL)
75+
set(ENV{CMAKE_BUILD_PARALLEL_LEVEL} "${CPU_COUNT}")
76+
message(STATUS "Setting CMAKE_BUILD_PARALLEL_LEVEL to $ENV{CMAKE_BUILD_PARALLEL_LEVEL}")
8477
endif()
8578

86-
# Currently we doesn't support build time generation of proto/gRPC files,
87-
# so gRPC version should be strict
88-
set(AGONES_FORCE_GRPC_VERSION ON)
89-
set(AGONES_GRPC_VERSION_MATCH "")
90-
if (AGONES_FORCE_GRPC_VERSION)
91-
set(AGONES_GRPC_VERSION_MATCH EXACT)
92-
endif()
79+
# gRPC
80+
find_package(Protobuf REQUIRED)
81+
find_package(gRPC CONFIG REQUIRED)
82+
find_package(Threads REQUIRED)
83+
84+
message(STATUS "gRPC version found: ${gRPC_VERSION}")
9385

9486
# Settings
9587
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
9688

97-
set(CMAKE_CXX_STANDARD 14)
89+
set(CMAKE_CXX_STANDARD 17)
9890
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
9991
set(CMAKE_CXX_EXTENSIONS OFF)
10092
set(CMAKE_INCLUDE_CURRENT_DIR ON)
10193
set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
10294
set(CMAKE_DEBUG_POSTFIX "d")
103-
set(AGONES_GRPC_VERSION "1.57.0")
10495

10596
# Platform specific stuff
10697
if (WIN32)

sdks/cpp/cmake/clang-verify.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
cmake_minimum_required (VERSION 3.5.0)
15+
cmake_minimum_required(VERSION 3.15)
1616

1717
option(AGONES_SILENT_OUTPUT "Show only warnings/error messages" OFF)
1818
if (AGONES_SILENT_OUTPUT)

0 commit comments

Comments
 (0)