Skip to content

Commit ffc2413

Browse files
authored
ci(gcb): add shared library build (#6257)
* ci(gcb): add shared library build Also fixed an issue where the pubsub protos were missing a needed dep. This PR refactors the logic to run the CMake and Makefile quickstart builds into a library, because it turns out that this is a useful way to verify that our installed artifacts work, and we end up calling this from a few places.
1 parent fb33e9b commit ffc2413

File tree

7 files changed

+135
-51
lines changed

7 files changed

+135
-51
lines changed

ci/cloudbuild/builds/cmake-install.sh

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set -eu
1818

1919
source "$(dirname "$0")/../../lib/init.sh"
2020
source module ci/cloudbuild/builds/lib/cmake.sh
21-
source module ci/etc/quickstart-config.sh
21+
source module ci/cloudbuild/builds/lib/quickstart.sh
2222
source module ci/lib/io.sh
2323

2424
export CC=clang
@@ -143,28 +143,7 @@ while IFS= read -r -d '' f; do
143143
fi
144144
done < <(find "${INSTALL_PREFIX}" -type f -print0)
145145

146-
# Verify that our installed artifacts are usable by compiling our quickstart
147-
# binaries against our installed artifacts.
148-
for lib in $(quickstart::libraries); do
149-
mapfile -t run_args < <(quickstart::arguments "${lib}")
150-
io::log_h2 "Building quickstart: ${lib}"
151-
if [[ "${PROJECT_ID:-}" != "cloud-cpp-testing-resources" ]]; then
152-
run_args=() # Empties these args so we don't execute quickstarts below
153-
io::log_yellow "Not executing quickstarts," \
154-
"which can only run in GCB project 'cloud-cpp-testing-resources'"
155-
fi
156-
157-
io::log "[ CMake ]"
158-
src_dir="${PROJECT_ROOT}/google/cloud/${lib}/quickstart"
159-
bin_dir="${PROJECT_ROOT}/cmake-out/quickstart-${lib}"
160-
cmake -H"${src_dir}" -B"${bin_dir}" "-DCMAKE_PREFIX_PATH=${INSTALL_PREFIX}"
161-
cmake --build "${bin_dir}"
162-
test "${#run_args[@]}" -ne 0 && "${bin_dir}/quickstart" "${run_args[@]}"
163-
164-
echo
165-
io::log "[ Make ]"
166-
make -C "${src_dir}"
167-
test "${#run_args[@]}" -ne 0 && "${src_dir}/quickstart" "${run_args[@]}"
168-
done
146+
# Tests the installed artifacts by building and running the quickstarts.
147+
quickstart::run_cmake_and_make "${INSTALL_PREFIX}"
169148

170149
exit "${exit_code}"

ci/cloudbuild/builds/demo-install.sh

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ set -eu
2525

2626
source "$(dirname "$0")/../../lib/init.sh"
2727
source module ci/cloudbuild/builds/lib/cmake.sh
28-
source module ci/etc/quickstart-config.sh
28+
source module ci/cloudbuild/builds/lib/quickstart.sh
2929
source module ci/lib/io.sh
3030

3131
## [START packaging.md]
@@ -38,28 +38,5 @@ cmake --build cmake-out --target install
3838

3939
## [END packaging.md]
4040

41-
# Tells pkg-config where the artifacts are, so the Makefile builds work.
42-
export PKG_CONFIG_PATH="${PREFIX}/lib64/pkgconfig:${PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH:-}"
43-
44-
# Verify that the installed artifacts are usable by running the quickstarts.
45-
for lib in $(quickstart::libraries); do
46-
mapfile -t run_args < <(quickstart::arguments "${lib}")
47-
io::log_h2 "Building quickstart: ${lib}"
48-
if [[ "${PROJECT_ID:-}" != "cloud-cpp-testing-resources" ]]; then
49-
run_args=() # Empties these args so we don't execute quickstarts below
50-
io::log_yellow "Not executing quickstarts," \
51-
"which can only run in GCB project 'cloud-cpp-testing-resources'"
52-
fi
53-
54-
io::log "[ CMake ]"
55-
src_dir="${PROJECT_ROOT}/google/cloud/${lib}/quickstart"
56-
bin_dir="${PROJECT_ROOT}/cmake-out/quickstart-${lib}"
57-
cmake -H"${src_dir}" -B"${bin_dir}" "-DCMAKE_PREFIX_PATH=${PREFIX}"
58-
cmake --build "${bin_dir}"
59-
test "${#run_args[@]}" -eq 0 || "${bin_dir}/quickstart" "${run_args[@]}"
60-
61-
echo
62-
io::log "[ Make ]"
63-
make -C "${src_dir}"
64-
test "${#run_args[@]}" -eq 0 || "${src_dir}/quickstart" "${run_args[@]}"
65-
done
41+
# Tests the installed artifacts by building and running the quickstarts.
42+
quickstart::run_cmake_and_make "${PREFIX}"
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2021 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# This build script serves two main purposes:
18+
#
19+
# 1. It demonstrates to users how to install `google-cloud-cpp`. We will
20+
# extract part of this script into user-facing markdown documentation.
21+
# 2. It verifies that the installed artifacts work by compiling and running the
22+
# quickstart programs against the installed artifacts.
23+
24+
# Make our include guard clean against set -o nounset.
25+
test -n "${CI_CLOUDBUILD_BUILDS_LIB_QUICKSTART_SH__:-}" || declare -i CI_CLOUDBUILD_BUILDS_LIB_QUICKSTART_SH__=0
26+
if ((CI_CLOUDBUILD_BUILDS_LIB_QUICKSTART_SH__++ != 0)); then
27+
return 0
28+
fi # include guard
29+
30+
source module ci/cloudbuild/builds/lib/cmake.sh
31+
source module ci/etc/quickstart-config.sh
32+
source module ci/lib/io.sh
33+
34+
# Builds and runs the CMake and Makefile quickstart programs. This is a useful
35+
# way to test that the artifacts installed by `google-cloud-cpp` work. This
36+
# function requires a single argument specifying the directory where the
37+
# `google-cloud-cpp` library was installed.
38+
#
39+
# Example:
40+
#
41+
# quickstart::run_cmake_and_make "/usr/local"
42+
function quickstart::run_cmake_and_make() {
43+
local prefix="$1"
44+
for lib in $(quickstart::libraries); do
45+
mapfile -t run_args < <(quickstart::arguments "${lib}")
46+
io::log_h2 "Building quickstart: ${lib}"
47+
if [[ "${PROJECT_ID:-}" != "cloud-cpp-testing-resources" ]]; then
48+
run_args=() # Empties these args so we don't execute quickstarts below
49+
io::log_yellow "Not executing quickstarts," \
50+
"which can only run in GCB project 'cloud-cpp-testing-resources'"
51+
fi
52+
53+
io::log "[ CMake ]"
54+
src_dir="${PROJECT_ROOT}/google/cloud/${lib}/quickstart"
55+
bin_dir="${PROJECT_ROOT}/cmake-out/quickstart-${lib}"
56+
cmake -H"${src_dir}" -B"${bin_dir}" "-DCMAKE_PREFIX_PATH=${prefix}"
57+
cmake --build "${bin_dir}"
58+
test "${#run_args[@]}" -eq 0 || "${bin_dir}/quickstart" "${run_args[@]}"
59+
60+
echo
61+
io::log "[ Make ]"
62+
PKG_CONFIG_PATH="${prefix}/lib64/pkgconfig:${prefix}/lib/pkgconfig:${PKG_CONFIG_PATH:-}" \
63+
make -C "${src_dir}"
64+
test "${#run_args[@]}" -eq 0 || "${src_dir}/quickstart" "${run_args[@]}"
65+
done
66+
}

ci/cloudbuild/builds/shared.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2021 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -eu
18+
19+
source "$(dirname "$0")/../../lib/init.sh"
20+
source module ci/cloudbuild/builds/lib/cmake.sh
21+
source module ci/cloudbuild/builds/lib/quickstart.sh
22+
23+
export CC=gcc
24+
export CXX=g++
25+
26+
INSTALL_PREFIX="/var/tmp/google-cloud-cpp"
27+
cmake -GNinja \
28+
-DBUILD_SHARED_LIBS=ON \
29+
-DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" \
30+
-S . -B cmake-out
31+
cmake --build cmake-out
32+
env -C cmake-out ctest -LE "integration-test"
33+
cmake --build cmake-out --target install
34+
35+
# Tests the installed artifacts by building and running the quickstarts.
36+
quickstart::run_cmake_and_make "${INSTALL_PREFIX}"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
filename: ci/cloudbuild/cloudbuild.yaml
2+
github:
3+
name: google-cloud-cpp
4+
owner: googleapis
5+
push:
6+
branch: ^(master|main|v\d+\..*)$
7+
name: shared-ci
8+
substitutions:
9+
_BUILD_NAME: shared
10+
_DISTRO: fedora
11+
tags:
12+
- ci
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
filename: ci/cloudbuild/cloudbuild.yaml
2+
github:
3+
name: google-cloud-cpp
4+
owner: googleapis
5+
pullRequest:
6+
branch: ^(master|main|v\d+\..*)$
7+
commentControl: COMMENTS_ENABLED_FOR_EXTERNAL_CONTRIBUTORS_ONLY
8+
name: shared-pr
9+
substitutions:
10+
_BUILD_NAME: shared
11+
_DISTRO: fedora
12+
tags:
13+
- pr

external/googleapis/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,8 @@ target_link_libraries(
596596
PUBLIC google-cloud-cpp::api_annotations_protos
597597
google-cloud-cpp::api_client_protos
598598
google-cloud-cpp::api_field_behavior_protos
599-
google-cloud-cpp::api_resource_protos)
599+
google-cloud-cpp::api_resource_protos
600+
google-cloud-cpp::rpc_status_protos)
600601

601602
google_cloud_cpp_grpcpp_library(
602603
google_cloud_cpp_spanner_protos

0 commit comments

Comments
 (0)