Skip to content

Instantly share code, notes, and snippets.

@coryan
Created November 17, 2020 14:17
Show Gist options
  • Save coryan/68287ebacd632abb2a618b4252ff4d1b to your computer and use it in GitHub Desktop.
Save coryan/68287ebacd632abb2a618b4252ff4d1b to your computer and use it in GitHub Desktop.
Compile google-cloud-cpp without gRPC
# Copyright 2020 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=8
FROM centos:${DISTRO_VERSION} AS devtools
## [START packaging.md]
# Install the minimal development tools, libcurl, OpenSSL, and the c-ares
# library (required by gRPC):
# ```bash
RUN dnf makecache && \
dnf install -y epel-release && \
dnf makecache && \
dnf install -y ccache cmake gcc-c++ git make openssl-devel pkgconfig \
zlib-devel libcurl-devel c-ares-devel tar wget which
# ```
# The following steps will install libraries and tools in `/usr/local`. By
# default CentOS-8 does not search for shared libraries in these directories,
# there are multiple ways to solve this problem, the following steps are one
# solution:
# ```bash
RUN (echo "/usr/local/lib" ; echo "/usr/local/lib64") | \
tee /etc/ld.so.conf.d/usrlocal.conf
ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig
ENV PATH=/usr/local/bin:${PATH}
# ```
# #### Abseil
# We need a recent version of Abseil.
# ```bash
WORKDIR /var/tmp/build
RUN wget -q https://github.com/abseil/abseil-cpp/archive/20200225.2.tar.gz && \
tar -xf 20200225.2.tar.gz && \
cd abseil-cpp-20200225.2 && \
sed -i 's/^#define ABSL_OPTION_USE_\(.*\) 2/#define ABSL_OPTION_USE_\1 0/' "absl/base/options.h" && \
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTING=OFF \
-DBUILD_SHARED_LIBS=yes \
-DCMAKE_CXX_STANDARD=11 \
-H. -Bcmake-out && \
cmake --build cmake-out -- -j ${NCPU:-4} && \
cmake --build cmake-out --target install -- -j ${NCPU:-4} && \
ldconfig
# ```
# #### crc32c
# The project depends on the Crc32c library, we need to compile this from
# source:
# ```bash
WORKDIR /var/tmp/build
RUN wget -q https://github.com/google/crc32c/archive/1.1.0.tar.gz && \
tar -xf 1.1.0.tar.gz && \
cd crc32c-1.1.0 && \
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=yes \
-DCRC32C_BUILD_TESTS=OFF \
-DCRC32C_BUILD_BENCHMARKS=OFF \
-DCRC32C_USE_GLOG=OFF \
-H. -Bcmake-out && \
cmake --build cmake-out -- -j ${NCPU:-4} && \
cmake --build cmake-out --target install -- -j ${NCPU:-4} && \
ldconfig
# ```
# #### nlohmann_json library
# The project depends on the nlohmann_json library. We use CMake to
# install it as this installs the necessary CMake configuration files.
# Note that this is a header-only library, and often installed manually.
# This leaves your environment without support for CMake pkg-config.
# ```bash
WORKDIR /var/tmp/build
RUN wget -q https://github.com/nlohmann/json/archive/v3.9.0.tar.gz && \
tar -xzf v3.9.0.tar.gz && \
cd json-3.9.0 && \
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=yes \
-DBUILD_TESTING=OFF \
-H. -Bcmake-out/nlohmann/json && \
cmake --build cmake-out/nlohmann/json --target install -- -j ${NCPU} && \
ldconfig
# ```
FROM devtools AS install
ARG NCPU=4
ARG DISTRO="distro-name"
# #### Compile and install the main project
# We can now compile, test, and install `google-cloud-cpp`.
# ```bash
WORKDIR /var/tmp/build/google-cloud-cpp
RUN curl -sSL https://github.com/googleapis/google-cloud-cpp/archive/v1.20.0.tar.gz | \
tar -xzf - --strip-components=1
RUN cmake -DBUILD_TESTING=OFF \
-DGOOGLE_CLOUD_CPP_ENABLE_BIGQUERY=OFF \
-DGOOGLE_CLOUD_CPP_ENABLE_BIGTABLE=OFF \
-DGOOGLE_CLOUD_CPP_ENABLE_SPANNER=OFF \
-DGOOGLE_CLOUD_CPP_ENABLE_PUBSUB=OFF \
-DGOOGLE_CLOUD_CPP_ENABLE_GENERATOR=OFF \
-H. -Bcmake-out
RUN cmake --build cmake-out -- -j "${NCPU:-4}"
RUN cmake --build cmake-out --target install
# ```
## [END packaging.md]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment