Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Add CMake files and a CI build using them. #39

Merged
merged 4 commits into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ build:ubsan --linkopt=-fsanitize=undefined
build:ubsan --linkopt=-lubsan
build:ubsan --action_env=UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1

# TODO(...): this does not work unless libc++ (or libstdc++) are also compiled
# TODO(#41): this does not work unless libc++ (or libstdc++) are also compiled
# with -fsanitize=memory.
# --config tsan: Memory Sanitizer
# build:msan --strip=never
Expand Down
42 changes: 42 additions & 0 deletions .cmake-format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

tab_size = 4
separate_ctrl_name_with_space = True

additional_commands = {
"externalproject_add": {
"flags": [
],
"kwargs": {
"BUILD_COMMAND": "+",
"BUILD_BYPRODUCTS": "+",
"CMAKE_ARGS": "+",
"COMMAND": "+",
"CONFIGURE_COMMAND": "+",
"DEPENDS": "+",
"DOWNLOAD_COMMAND": "+",
"EXCLUDE_FROM_ALL": 1,
"INSTALL_COMMAND": "+",
"INSTALL_DIR": 1,
"LOG_BUILD": 1,
"LOG_CONFIGURE": 1,
"LOG_DOWNLOAD": 1,
"LOG_INSTALL": 1,
"PREFIX": 1,
"URL": 1,
"URL_HASH": 1,
}
}
}
44 changes: 44 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ~~~
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ~~~

cmake_minimum_required(VERSION 3.5)
project(google-cloud-cpp-spanner CXX C)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

# Set this variable to a true value for branches that are releases. That will
# remove the "+dev" suffix (technically "build metadata" according to
# semver.org) from all the build identifiers. We only want that suffix on
# development branches.
set(GOOGLE_CLOUD_CPP_SPANNER_CLIENT_IS_RELEASE "")

# This should be included from the top level CMakeLists file
set(SPANNER_CLIENT_VERSION_MAJOR 0)
set(SPANNER_CLIENT_VERSION_MINOR 1)
set(SPANNER_CLIENT_VERSION_PATCH 0)
string(CONCAT SPANNER_CLIENT_VERSION
"${SPANNER_CLIENT_VERSION_MAJOR}"
"."
"${SPANNER_CLIENT_VERSION_MINOR}"
"."
"${SPANNER_CLIENT_VERSION_PATCH}")

include(CTest)

add_subdirectory(google/cloud/spanner)
10 changes: 10 additions & 0 deletions ci/kokoro/cmake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# CMake Continuous Integration Support Files.

This directory contains the CI support files to test the Google Cloud Spanner
C++ client library when built using CMake.

There are two basic configurations:

<!-- TODO(#42) - create a super build based CI -->
- Install all the dependencies and the build the client library.
- Use a super build to compile the client library.
61 changes: 61 additions & 0 deletions ci/kokoro/cmake/installed-dependencies/Dockerfile.fedora
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

ARG DISTRO_VERSION=30
FROM fedora:${DISTRO_VERSION}

# Fedora includes packages for gRPC, libcurl, and OpenSSL that are recent enough
# for `google-cloud-cpp`. Install these packages and additional development
# tools to compile the dependencies:
RUN dnf makecache && \
dnf install -y cmake gcc-c++ git make openssl-devel pkgconfig zlib-devel \
grpc-devel grpc-plugins \
libcurl-devel protobuf-compiler tar wget zlib-devel

# There is no Fedora package for CRC32C, download and install from source.
WORKDIR /var/tmp/build
RUN wget -q https://github.com/google/crc32c/archive/1.0.6.tar.gz
RUN tar -xf 1.0.6.tar.gz
WORKDIR /var/tmp/build/crc32c-1.0.6
RUN cmake \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=yes \
-DCRC32C_BUILD_TESTS=OFF \
-DCRC32C_BUILD_BENCHMARKS=OFF \
-DCRC32C_USE_GLOG=OFF \
-H. -Bcmake-out/crc32c
RUN cmake --build cmake-out/crc32c --target install -- -j $(nproc)
RUN ldconfig

# Download and compile google-cloud-cpp from source too:
WORKDIR /var/tmp/build
RUN wget -q https://github.com/googleapis/google-cloud-cpp/archive/v0.9.0.tar.gz
RUN tar -xf v0.9.0.tar.gz
WORKDIR /var/tmp/build/google-cloud-cpp-0.9.0
# Compile without the tests because we are testing spanner, not the base
# libraries
RUN cmake -H. -Bcmake-out \
-DGOOGLE_CLOUD_CPP_DEPENDENCY_PROVIDER=package \
-DBUILD_TESTING=OFF
RUN cmake --build cmake-out -- -j $(nproc)
RUN cmake --build cmake-out --target install

# Download and compile googletest, we need a recent version.
WORKDIR /var/tmp/build
RUN wget -q https://github.com/google/googletest/archive/b6cd405286ed8635ece71c72f118e659f4ade3fb.tar.gz
RUN tar -xf b6cd405286ed8635ece71c72f118e659f4ade3fb.tar.gz
WORKDIR /var/tmp/build/googletest-b6cd405286ed8635ece71c72f118e659f4ade3fb
RUN cmake \
-H. -Bcmake-out/gtest
RUN cmake --build cmake-out/gtest --target install -- -j $(nproc)
47 changes: 47 additions & 0 deletions ci/kokoro/cmake/installed-dependencies/build-in-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -eu

# This script is supposed to run inside a Docker container, see
# ci/kokoro/cmake/installed-dependencies/build.sh for the expected setup. The
# /v directory is a volume pointing to a (clean-ish) checkout of the project:
if [[ -z "${PROJECT_ROOT+x}" ]]; then
readonly PROJECT_ROOT="/v"
fi
source "${PROJECT_ROOT}/ci/kokoro/linux-config.sh"
source "${PROJECT_ROOT}/ci/colors.sh"

echo
echo "${COLOR_YELLOW}Starting docker build $(date) with $(nproc) cores${COLOR_RESET}"
echo

echo "================================================================"
echo "Compiling on $(date)"
echo "================================================================"
cd "${PROJECT_ROOT}"
cmake -H. -B"${BUILD_OUTPUT}"
cmake --build "${BUILD_OUTPUT}" -- -j "$(nproc)"

echo "================================================================"
echo "Running the unit tests $(date)"
echo "================================================================"
env -C "${BUILD_OUTPUT}" ctest --output-on-failure -j "$(nproc)"

echo "================================================================"
echo "Build finished at $(date)"
echo "================================================================"

exit 0
118 changes: 118 additions & 0 deletions ci/kokoro/cmake/installed-dependencies/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/usr/bin/env bash
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -eu

export CC=gcc
export CXX=g++
export DISTRO=fedora
export DISTRO_VERSION=30

if [[ "${BUILD_NAME+x}" != "x" ]]; then
echo "The BUILD_NAME is not defined or is empty. Fix the Kokoro .cfg file."
exit 1
elif [[ "${BUILD_NAME}" = "fedora" ]]; then
# This is the default build, nothing to configure.
/bin/true
else
echo "Unknown BUILD_NAME (${BUILD_NAME}). Fix the Kokoro .cfg file."
exit 1
fi

readonly CMDDIR="$(dirname "$0")"
if [[ -z "${PROJECT_ROOT+x}" ]]; then
readonly PROJECT_ROOT="$(cd "${CMDDIR}/../../../.."; pwd)"
fi
source "${PROJECT_ROOT}/ci/kokoro/linux-config.sh"
source "${PROJECT_ROOT}/ci/define-dump-log.sh"

echo "================================================================"
NCPU=$(nproc)
export NCPU
cd "${PROJECT_ROOT}"
echo "Building with ${NCPU} cores $(date) on ${PWD}."


echo "================================================================"
echo "Capture Docker version to troubleshoot problems $(date)."
sudo docker version
echo "================================================================"

echo "================================================================"
echo "Creating Docker image with all the development tools $(date)."
# We do not want to print the log unless there is an error. If we leave `-e`
# turned on we never get a chance to print the log, so disable it.
set +e
mkdir -p "${BUILD_OUTPUT}"
"${PROJECT_ROOT}/ci/install-retry.sh" \
"${CMDDIR}/create-docker-image.sh" \
>"${BUILD_OUTPUT}/create-build-docker-image.log" 2>&1 </dev/null
if [[ "$?" != 0 ]]; then
dump_log "${BUILD_OUTPUT}/create-build-docker-image.log"
exit 1
fi
set -e
echo "Docker image created $(date)."
sudo docker image ls
echo "================================================================"

echo "================================================================"
echo "Running the full build $(date)."
# Disable
set +e
# When running on Travis (or the command-line) the build gets a tty, and the
# build scripts can produce nicer output in that case, but on Kokoro the script
# does not get a tty, and Docker terminates the program if we pass the `-i`
# flag. Configure the right option depending on the environment.
interactive_flag="-t"
if [[ -t 0 ]]; then
interactive_flag="-it"
fi

# Make sure the user has a $HOME directory inside the Docker container.
mkdir -p "${BUILD_HOME}"

sudo docker run \
--cap-add SYS_PTRACE \
--env DISTRO="${DISTRO}" \
--env DISTRO_VERSION="${DISTRO_VERSION}" \
--env CXX="${CXX}" \
--env CC="${CC}" \
--env NCPU="${NCPU:-2}" \
--env CHECK_STYLE="${CHECK_STYLE:-}" \
--env BAZEL_CONFIG="${BAZEL_CONFIG:-}" \
--env RUN_INTEGRATION_TESTS="${RUN_INTEGRATION_TESTS:-}" \
--env TERM="${TERM:-dumb}" \
--env HOME="/v/${BUILD_HOME}" \
--env USER="${USER}" \
--user "${UID:-0}" \
--volume "${PWD}":/v \
--volume "${KOKORO_GFILE_DIR:-/dev/shm}":/c \
--workdir /v \
"${IMAGE}:tip" \
"/v/ci/kokoro/cmake/installed-dependencies/build-in-docker.sh"

exit_status=$?
echo "Build finished with ${exit_status} exit status $(date)."
echo "================================================================"

if [[ "${exit_status}" != 0 ]]; then
echo "================================================================"
echo "Build failed, printing out logs $(date)."
"${PROJECT_ROOT}/ci/kokoro/dump-logs.sh"
echo "================================================================"
fi

exit ${exit_status}
31 changes: 31 additions & 0 deletions ci/kokoro/cmake/installed-dependencies/create-docker-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -eu

# Create a Docker image with all the dependencies necessary to build the
# project using CMake.
readonly CMDDIR="$(dirname "$0")"
if [[ -z "${PROJECT_ROOT+x}" ]]; then
readonly PROJECT_ROOT="$(cd "${CMDDIR}/../../../.."; pwd)"
fi
source "${PROJECT_ROOT}/ci/kokoro/linux-config.sh"

# Build in the command-directory. That makes the upload to the Docker server
# faster, and guarantees the image does not depend on local files.
cd "${CMDDIR}"
sudo docker build -t "${IMAGE}:tip" \
--build-arg DISTRO_VERSION="${DISTRO_VERSION}" \
-f "Dockerfile.${DISTRO}" .
22 changes: 22 additions & 0 deletions ci/kokoro/cmake/installed-dependencies/fedora-presubmit.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Format: //devtools/kokoro/config/proto/build.proto
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

build_file: "google-cloud-cpp-spanner/ci/kokoro/cmake/installed-dependencies/build.sh"
timeout_mins: 120

env_vars {
key: "BUILD_NAME"
value: "fedora"
}
Loading