diff --git a/INSTALL.md b/INSTALL.md index 5015038ea7958..3bc95a7ebefbe 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -128,6 +128,7 @@ cc_binary( | libcurl | 7.47.0 | HTTP client library for the Google Cloud Storage client | | crc32c | 1.0.6 | Hardware-accelerated CRC32C implementation | | OpenSSL | 1.0.2 | Crypto functions for Google Cloud Storage authentication | +| nljson | 3.6.1 | JSON for Modern C++ | Note that these libraries may also depend on other libraries. The following instructions include steps to install these indirect dependencies too. @@ -165,7 +166,7 @@ tools to compile the dependencies: ```bash sudo dnf makecache && \ -sudo dnf install -y grpc-devel grpc-plugins \ +sudo dnf install -y grpc-devel grpc-plugins json-devel \ libcurl-devel protobuf-compiler tar wget zlib-devel ``` @@ -221,7 +222,8 @@ Platform proto files. ```bash sudo zypper refresh && \ -sudo zypper install -y grpc-devel gzip libcurl-devel pkg-config tar wget +sudo zypper install -y grpc-devel gzip libcurl-devel nlohmann_json \ + pkg-config tar wget ``` #### crc32c @@ -267,7 +269,8 @@ Install the minimal development tools: ```bash sudo zypper refresh && \ sudo zypper install --allow-downgrade -y cmake gcc gcc-c++ git gzip \ - libcurl-devel libopenssl-devel make tar wget + libcurl-devel libopenssl-devel make nlohmann_json \ + tar wget ``` #### crc32c @@ -383,7 +386,7 @@ Install the minimal development tools: sudo apt update && \ sudo apt install -y build-essential cmake git gcc g++ cmake \ libc-ares-dev libc-ares2 libcurl4-openssl-dev libssl-dev make \ - pkg-config tar wget zlib1g-dev + nlohmann-json-dev pkg-config tar wget zlib1g-dev ``` #### crc32c @@ -547,6 +550,21 @@ sudo make install sudo ldconfig ``` +#### nlohmann_json + +Ubuntu-16.04 does not provide a package for nlohmann_json. Manually install +this library: + +```bash +cd $HOME/Downloads +wget -q https://github.com/nlohmann/json/archive/v3.6.1.tar.gz +tar -xf json-3.6.1.tar.gz +cd $HOME/Downloads/json-3.6.1 +cmake H. -Bcmake-out +cmake --build cmake-out -- -j $(nproc) +sudo cmake --build cmake-out --target install +``` + #### google-cloud-cpp Finally we can install `google-cloud-cpp`. @@ -566,7 +584,6 @@ sudo cmake --build . --target install ### Ubuntu (14.04 - Trusty Tahr) Install the minimal development tools. - We use the `ubuntu-toolchain-r` PPA to get a modern version of CMake: ```bash @@ -699,6 +716,21 @@ make -j $(nproc) sudo make install ``` +#### nlohmann_json + +Ubuntu:trusty does not provide a package for nlohmann_json. Manually install +this library: + +```bash +cd $HOME/Downloads +wget -q https://github.com/nlohmann/json/archive/v3.6.1.tar.gz +tar -xf json-3.6.1.tar.gz +cd $HOME/Downloads/json-3.6.1 +cmake H. -Bcmake-out +cmake --build cmake-out -- -j $(nproc) +sudo cmake --build cmake-out --target install +``` + #### google-cloud-cpp We can now compile and install `google-cloud-cpp`. @@ -730,7 +762,7 @@ prevent you from compiling against openssl-1.1.0. ```bash sudo apt update && \ -sudo apt install -y build-essential cmake git gcc g++ cmake \ +sudo apt install -y build-essential cmake git gcc g++ json-devel cmake \ libc-ares-dev libc-ares2 libcurl4-openssl-dev libssl1.0-dev make \ pkg-config tar wget zlib1g-dev ``` @@ -820,7 +852,7 @@ sudo yum install -y centos-release-scl sudo yum-config-manager --enable rhel-server-rhscl-7-rpms sudo yum makecache && \ sudo yum install -y automake cmake3 curl-devel gcc gcc-c++ git libtool \ - make openssl-devel pkgconfig tar wget which zlib-devel + make json-devel openssl-devel pkgconfig tar wget which zlib-devel ln -sf /usr/bin/cmake3 /usr/bin/cmake && ln -sf /usr/bin/ctest3 /usr/bin/ctest ``` diff --git a/README.md b/README.md index 96573aaf3e612..0b2a7f5cefa5a 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ of these tools we test with are: #### Libraries -The libraries also depend on gRPC, libcurl, and the dependencies of those +The libraries also depend on gRPC, libcurl, nlohmann-json and the dependencies of those libraries. The Google Cloud C++ Client libraries are tested with the following versions of these dependencies: @@ -130,6 +130,7 @@ versions of these dependencies: | ------- | --------------- | | gRPC | v1.16.x | | libcurl | 7.47.0 | +| nljson | 3.6.1 | #### Tests @@ -156,7 +157,7 @@ sudo yum install -y centos-release-scl sudo yum-config-manager --enable rhel-server-rhscl-7-rpms sudo yum makecache && \ sudo yum install -y automake cmake3 curl-devel gcc gcc-c++ git libtool \ - make openssl-devel pkgconfig tar wget which zlib-devel + make json-devel openssl-devel pkgconfig tar wget which zlib-devel ln -sf /usr/bin/cmake3 /usr/bin/cmake && ln -sf /usr/bin/ctest3 /usr/bin/ctest ``` @@ -179,7 +180,7 @@ prevent you from compiling against openssl-1.1.0. sudo apt update && \ sudo apt install -y build-essential cmake git gcc g++ cmake \ libc-ares-dev libc-ares2 libcurl4-openssl-dev libssl1.0-dev make \ - pkg-config tar wget zlib1g-dev + nlohmann-json3 pkg-config tar wget zlib1g-dev ``` ### Fedora (30) @@ -192,7 +193,7 @@ sudo apt install -y build-essential cmake git gcc g++ cmake \ ```bash sudo dnf makecache && \ sudo dnf install -y cmake gcc-c++ git make openssl-devel pkgconfig \ - zlib-devel + json-devel zlib-devel ``` ### OpenSUSE (Tumbleweed) @@ -205,7 +206,8 @@ sudo dnf install -y cmake gcc-c++ git make openssl-devel pkgconfig \ ```bash sudo zypper refresh && \ sudo zypper install --allow-downgrade -y cmake gcc gcc-c++ git gzip \ - libcurl-devel libopenssl-devel make tar wget zlib-devel + libcurl-devel libopenssl-devel make nlohmann_json \ + tar wget zlib-devel ``` ### OpenSUSE (Leap) @@ -218,7 +220,7 @@ sudo zypper install --allow-downgrade -y cmake gcc gcc-c++ git gzip \ ```bash sudo zypper refresh && \ sudo zypper install --allow-downgrade -y cmake gcc gcc-c++ git gzip \ - libcurl-devel libopenssl-devel make tar wget + libcurl-devel libopenssl-devel make nlohmann_json tar wget ``` ### Ubuntu (18.04 - Bionic Beaver) @@ -232,7 +234,7 @@ sudo zypper install --allow-downgrade -y cmake gcc gcc-c++ git gzip \ sudo apt update && \ sudo apt install -y build-essential cmake git gcc g++ cmake \ libc-ares-dev libc-ares2 libcurl4-openssl-dev libssl-dev make \ - pkg-config tar wget zlib1g-dev + nlohmann-json-dev pkg-config tar wget zlib1g-dev ``` ### Ubuntu (16.04 - Xenial Xerus) @@ -249,6 +251,19 @@ sudo apt install -y build-essential cmake git gcc g++ cmake \ pkg-config tar wget zlib1g-dev ``` +Ubuntu-16.04 does not provide a package for nlohmann_json. Manually install +this library: + +```bash +cd $HOME/Downloads +wget -q https://github.com/nlohmann/json/archive/v3.6.1.tar.gz +tar -xf json-3.6.1.tar.gz +cd $HOME/Downloads/json-3.6.1 +cmake H. -Bcmake-out +cmake --build cmake-out -- -j $(nproc) +sudo cmake --build cmake-out --target install +``` + ### Ubuntu (14.04 - Trusty Tahr) [![Kokoro install ubuntu-trusty status][kokoro-install-ubuntu-trusty-shield]][kokoro-install-ubuntu-trusty-link] @@ -294,6 +309,19 @@ export OPENSSL_ROOT_DIR=/usr/local/ssl export PKG_CONFIG_PATH=/usr/local/ssl/lib/pkgconfig ``` +Ubuntu:trusty does not provide a package for nlohmann_json. Manually install +this library: + +```bash +cd $HOME/Downloads +wget -q https://github.com/nlohmann/json/archive/v3.6.1.tar.gz +tar -xf json-3.6.1.tar.gz +cd $HOME/Downloads/json-3.6.1 +cmake H. -Bcmake-out +cmake --build cmake-out -- -j $(nproc) +sudo cmake --build cmake-out --target install +``` + #### macOS (using brew) ```bash diff --git a/ci/benchmarks/Dockerfile b/ci/benchmarks/Dockerfile index 49d803392165c..8740a51ba6544 100644 --- a/ci/benchmarks/Dockerfile +++ b/ci/benchmarks/Dockerfile @@ -17,7 +17,7 @@ FROM ubuntu:bionic AS google-cloud-cpp-dependencies RUN apt update && \ apt install -y build-essential cmake git gcc g++ cmake \ libc-ares-dev libc-ares2 libcurl4-openssl-dev libssl-dev make \ - pkg-config tar wget zlib1g-dev + nlohmann-json-dev pkg-config tar wget zlib1g-dev # #### crc32c diff --git a/ci/kokoro/docker/Dockerfile.centos b/ci/kokoro/docker/Dockerfile.centos index 077030a0d5682..36ca2a6d7b4a9 100644 --- a/ci/kokoro/docker/Dockerfile.centos +++ b/ci/kokoro/docker/Dockerfile.centos @@ -29,6 +29,7 @@ RUN yum makecache && yum install -y \ gcc \ gcc-c++ \ git \ + json-devel \ make \ openssl-devel \ python \ diff --git a/ci/kokoro/docker/Dockerfile.fedora b/ci/kokoro/docker/Dockerfile.fedora index 4ea4fe2378521..cf0e6c1097cf2 100644 --- a/ci/kokoro/docker/Dockerfile.fedora +++ b/ci/kokoro/docker/Dockerfile.fedora @@ -28,6 +28,7 @@ RUN dnf makecache && dnf install -y \ doxygen \ gcc-c++ \ git \ + json-devel \ libcurl-devel \ libcxx-devel \ libcxxabi-devel \ diff --git a/ci/kokoro/docker/Dockerfile.fedora-install b/ci/kokoro/docker/Dockerfile.fedora-install index 5a7996ea00951..aad200d9f26cb 100644 --- a/ci/kokoro/docker/Dockerfile.fedora-install +++ b/ci/kokoro/docker/Dockerfile.fedora-install @@ -30,6 +30,7 @@ RUN dnf makecache && dnf install -y \ git \ grpc-devel \ grpc-plugins \ + json-devel \ libcurl-devel \ libcxx-devel \ libcxxabi-devel \ diff --git a/ci/kokoro/docker/Dockerfile.ubuntu b/ci/kokoro/docker/Dockerfile.ubuntu index 480a589645630..1a9ebac02230f 100644 --- a/ci/kokoro/docker/Dockerfile.ubuntu +++ b/ci/kokoro/docker/Dockerfile.ubuntu @@ -36,6 +36,7 @@ RUN apt update && \ libtool \ lsb-release \ make \ + nlohmann-json-dev \ pkg-config \ python-pip \ shellcheck \ diff --git a/ci/kokoro/docker/Dockerfile.ubuntu-install b/ci/kokoro/docker/Dockerfile.ubuntu-install index 9b1d297b224be..4247e2006789a 100644 --- a/ci/kokoro/docker/Dockerfile.ubuntu-install +++ b/ci/kokoro/docker/Dockerfile.ubuntu-install @@ -37,6 +37,7 @@ RUN apt update && \ libtool \ lsb-release \ make \ + nlohmann-json-dev \ pkg-config \ python-pip \ shellcheck \ diff --git a/ci/kokoro/docker/Dockerfile.ubuntu-trusty b/ci/kokoro/docker/Dockerfile.ubuntu-trusty index e954432be1eab..1d485818a1d6c 100644 --- a/ci/kokoro/docker/Dockerfile.ubuntu-trusty +++ b/ci/kokoro/docker/Dockerfile.ubuntu-trusty @@ -51,6 +51,16 @@ RUN apt update && apt install -y python-dev python-pip RUN pip install --upgrade pip RUN pip install flask httpbin gevent gunicorn crc32c +# Ubuntu:trusty does not provide a package for nlohmann_json. Manually install +# this library: +WORKDIR /var/tmp/build +RUN wget -q https://github.com/nlohmann/json/archive/v3.6.1.tar.gz +RUN tar -xf json-3.6.1.tar.gz +WORKDIR /var/tmp/build/json-3.6.1 +RUN cmake H. -Bcmake-out +RUN cmake --build cmake-out -- -j $(nproc) +RUN cmake --build cmake-out --target install + # Install the Cloud Bigtable emulator and the Cloud Bigtable command-line # client. They are used in the integration tests. COPY . /var/tmp/ci diff --git a/ci/kokoro/install/Dockerfile.centos b/ci/kokoro/install/Dockerfile.centos index 9add2f457e203..af43b09b39103 100644 --- a/ci/kokoro/install/Dockerfile.centos +++ b/ci/kokoro/install/Dockerfile.centos @@ -31,7 +31,7 @@ RUN yum install -y centos-release-scl RUN yum-config-manager --enable rhel-server-rhscl-7-rpms RUN yum makecache && \ yum install -y automake cmake3 curl-devel gcc gcc-c++ git libtool \ - make openssl-devel pkgconfig tar wget which zlib-devel + make json-devel openssl-devel pkgconfig tar wget which zlib-devel RUN ln -sf /usr/bin/cmake3 /usr/bin/cmake && ln -sf /usr/bin/ctest3 /usr/bin/ctest # ``` diff --git a/ci/kokoro/install/Dockerfile.debian b/ci/kokoro/install/Dockerfile.debian index 825848ed791ac..9e95e630ec77c 100644 --- a/ci/kokoro/install/Dockerfile.debian +++ b/ci/kokoro/install/Dockerfile.debian @@ -31,7 +31,7 @@ FROM debian:${DISTRO_VERSION} AS devtools # ```bash RUN apt update && \ - apt install -y build-essential cmake git gcc g++ cmake \ + apt install -y build-essential cmake git gcc g++ json-devel cmake \ libc-ares-dev libc-ares2 libcurl4-openssl-dev libssl1.0-dev make \ pkg-config tar wget zlib1g-dev # ``` diff --git a/ci/kokoro/install/Dockerfile.fedora b/ci/kokoro/install/Dockerfile.fedora index 038ce1eb2c21e..e524e0f211fb5 100644 --- a/ci/kokoro/install/Dockerfile.fedora +++ b/ci/kokoro/install/Dockerfile.fedora @@ -35,7 +35,7 @@ RUN dnf makecache && \ # ```bash RUN dnf makecache && \ - dnf install -y grpc-devel grpc-plugins \ + dnf install -y grpc-devel grpc-plugins json-devel \ libcurl-devel protobuf-compiler tar wget zlib-devel # ``` diff --git a/ci/kokoro/install/Dockerfile.opensuse b/ci/kokoro/install/Dockerfile.opensuse index d30d1f96c652a..c863f051feac4 100644 --- a/ci/kokoro/install/Dockerfile.opensuse +++ b/ci/kokoro/install/Dockerfile.opensuse @@ -31,7 +31,8 @@ RUN zypper refresh && \ # ```bash RUN zypper refresh && \ - zypper install -y grpc-devel gzip libcurl-devel pkg-config tar wget + zypper install -y grpc-devel gzip libcurl-devel nlohmann_json \ + pkg-config tar wget # ``` # #### crc32c diff --git a/ci/kokoro/install/Dockerfile.opensuse-leap b/ci/kokoro/install/Dockerfile.opensuse-leap index 180b0dd63bafb..5ca27d1c2b194 100644 --- a/ci/kokoro/install/Dockerfile.opensuse-leap +++ b/ci/kokoro/install/Dockerfile.opensuse-leap @@ -22,7 +22,8 @@ FROM opensuse/leap:${DISTRO_VERSION} AS devtools # ```bash RUN zypper refresh && \ zypper install --allow-downgrade -y cmake gcc gcc-c++ git gzip \ - libcurl-devel libopenssl-devel make tar wget + libcurl-devel libopenssl-devel make nlohmann_json \ + tar wget # ``` # #### crc32c diff --git a/ci/kokoro/install/Dockerfile.ubuntu b/ci/kokoro/install/Dockerfile.ubuntu index 477459ea2ebde..3195728bff288 100644 --- a/ci/kokoro/install/Dockerfile.ubuntu +++ b/ci/kokoro/install/Dockerfile.ubuntu @@ -26,7 +26,7 @@ FROM ubuntu:${DISTRO_VERSION} AS devtools RUN apt update && \ apt install -y build-essential cmake git gcc g++ cmake \ libc-ares-dev libc-ares2 libcurl4-openssl-dev libssl-dev make \ - pkg-config tar wget zlib1g-dev + nlohmann-json-dev pkg-config tar wget zlib1g-dev # ``` # #### crc32c diff --git a/ci/kokoro/install/Dockerfile.ubuntu-trusty b/ci/kokoro/install/Dockerfile.ubuntu-trusty index 9cabda81d4c5a..efaf04ba9db88 100644 --- a/ci/kokoro/install/Dockerfile.ubuntu-trusty +++ b/ci/kokoro/install/Dockerfile.ubuntu-trusty @@ -154,6 +154,21 @@ RUN make -j $(nproc) RUN make install # ``` +# #### nlohmann_json + +# Ubuntu:trusty does not provide a package for nlohmann_json. Manually install +# this library: + +# ```bash +WORKDIR /var/tmp/build +RUN wget -q https://github.com/nlohmann/json/archive/v3.6.1.tar.gz +RUN tar -xf json-3.6.1.tar.gz +WORKDIR /var/tmp/build/json-3.6.1 +RUN cmake H. -Bcmake-out +RUN cmake --build cmake-out -- -j $(nproc) +RUN cmake --build cmake-out --target install +# ``` + FROM devtools AS install # #### google-cloud-cpp diff --git a/ci/kokoro/install/Dockerfile.ubuntu-xenial b/ci/kokoro/install/Dockerfile.ubuntu-xenial index e1183ef5bee6d..a95cd845af652 100644 --- a/ci/kokoro/install/Dockerfile.ubuntu-xenial +++ b/ci/kokoro/install/Dockerfile.ubuntu-xenial @@ -108,6 +108,21 @@ RUN make install RUN ldconfig # ``` +# #### nlohmann_json + +# Ubuntu-16.04 does not provide a package for nlohmann_json. Manually install +# this library: + +# ```bash +WORKDIR /var/tmp/build +RUN wget -q https://github.com/nlohmann/json/archive/v3.6.1.tar.gz +RUN tar -xf json-3.6.1.tar.gz +WORKDIR /var/tmp/build/json-3.6.1 +RUN cmake H. -Bcmake-out +RUN cmake --build cmake-out -- -j $(nproc) +RUN cmake --build cmake-out --target install +# ``` + FROM devtools AS install # #### google-cloud-cpp diff --git a/ci/kokoro/readme/Dockerfile.centos b/ci/kokoro/readme/Dockerfile.centos index 22be0d8906afb..7ca4552e22cc2 100644 --- a/ci/kokoro/readme/Dockerfile.centos +++ b/ci/kokoro/readme/Dockerfile.centos @@ -34,7 +34,7 @@ RUN yum install -y centos-release-scl RUN yum-config-manager --enable rhel-server-rhscl-7-rpms RUN yum makecache && \ yum install -y automake cmake3 curl-devel gcc gcc-c++ git libtool \ - make openssl-devel pkgconfig tar wget which zlib-devel + make json-devel openssl-devel pkgconfig tar wget which zlib-devel RUN ln -sf /usr/bin/cmake3 /usr/bin/cmake && ln -sf /usr/bin/ctest3 /usr/bin/ctest # ``` diff --git a/ci/kokoro/readme/Dockerfile.debian b/ci/kokoro/readme/Dockerfile.debian index f96058f0d27c0..dfa748981c264 100644 --- a/ci/kokoro/readme/Dockerfile.debian +++ b/ci/kokoro/readme/Dockerfile.debian @@ -36,7 +36,7 @@ FROM debian:${DISTRO_VERSION} AS devtools RUN apt update && \ apt install -y build-essential cmake git gcc g++ cmake \ libc-ares-dev libc-ares2 libcurl4-openssl-dev libssl1.0-dev make \ - pkg-config tar wget zlib1g-dev + nlohmann-json3 pkg-config tar wget zlib1g-dev # ``` FROM devtools AS readme diff --git a/ci/kokoro/readme/Dockerfile.fedora b/ci/kokoro/readme/Dockerfile.fedora index 77684bfd86114..697fc4b960739 100644 --- a/ci/kokoro/readme/Dockerfile.fedora +++ b/ci/kokoro/readme/Dockerfile.fedora @@ -28,7 +28,7 @@ FROM fedora:${DISTRO_VERSION} AS devtools # ```bash RUN dnf makecache && \ dnf install -y cmake gcc-c++ git make openssl-devel pkgconfig \ - zlib-devel + json-devel zlib-devel # ``` FROM devtools AS readme diff --git a/ci/kokoro/readme/Dockerfile.opensuse b/ci/kokoro/readme/Dockerfile.opensuse index 0c85b0bc03998..d668ed209297e 100644 --- a/ci/kokoro/readme/Dockerfile.opensuse +++ b/ci/kokoro/readme/Dockerfile.opensuse @@ -24,7 +24,8 @@ FROM opensuse/tumbleweed:${DISTRO_VERSION} AS devtools # ```bash RUN zypper refresh && \ zypper install --allow-downgrade -y cmake gcc gcc-c++ git gzip \ - libcurl-devel libopenssl-devel make tar wget zlib-devel + libcurl-devel libopenssl-devel make nlohmann_json \ + tar wget zlib-devel # ``` FROM devtools AS README diff --git a/ci/kokoro/readme/Dockerfile.opensuse-leap b/ci/kokoro/readme/Dockerfile.opensuse-leap index 6c8bcd858fe71..3d465d0439f86 100644 --- a/ci/kokoro/readme/Dockerfile.opensuse-leap +++ b/ci/kokoro/readme/Dockerfile.opensuse-leap @@ -24,7 +24,7 @@ FROM opensuse/leap:${DISTRO_VERSION} AS devtools # ```bash RUN zypper refresh && \ zypper install --allow-downgrade -y cmake gcc gcc-c++ git gzip \ - libcurl-devel libopenssl-devel make tar wget + libcurl-devel libopenssl-devel make nlohmann_json tar wget # ``` FROM devtools AS readme diff --git a/ci/kokoro/readme/Dockerfile.ubuntu b/ci/kokoro/readme/Dockerfile.ubuntu index c4204bcd1f299..d16c536011c57 100644 --- a/ci/kokoro/readme/Dockerfile.ubuntu +++ b/ci/kokoro/readme/Dockerfile.ubuntu @@ -28,7 +28,7 @@ FROM ubuntu:${DISTRO_VERSION} AS devtools RUN apt update && \ apt install -y build-essential cmake git gcc g++ cmake \ libc-ares-dev libc-ares2 libcurl4-openssl-dev libssl-dev make \ - pkg-config tar wget zlib1g-dev + nlohmann-json-dev pkg-config tar wget zlib1g-dev # ``` FROM devtools AS readme diff --git a/ci/kokoro/readme/Dockerfile.ubuntu-trusty b/ci/kokoro/readme/Dockerfile.ubuntu-trusty index ee37653056409..1ada7cd9ebbc0 100644 --- a/ci/kokoro/readme/Dockerfile.ubuntu-trusty +++ b/ci/kokoro/readme/Dockerfile.ubuntu-trusty @@ -65,6 +65,19 @@ ENV OPENSSL_ROOT_DIR=/usr/local/ssl ENV PKG_CONFIG_PATH=/usr/local/ssl/lib/pkgconfig # ``` +# Ubuntu:trusty does not provide a package for nlohmann_json. Manually install +# this library: + +# ```bash +WORKDIR /var/tmp/build +RUN wget -q https://github.com/nlohmann/json/archive/v3.6.1.tar.gz +RUN tar -xf json-3.6.1.tar.gz +WORKDIR /var/tmp/build/json-3.6.1 +RUN cmake H. -Bcmake-out +RUN cmake --build cmake-out -- -j $(nproc) +RUN cmake --build cmake-out --target install +# ``` + FROM devtools AS readme ## [START IGNORED] diff --git a/ci/kokoro/readme/Dockerfile.ubuntu-xenial b/ci/kokoro/readme/Dockerfile.ubuntu-xenial index d6be86b356701..64668effef8b7 100644 --- a/ci/kokoro/readme/Dockerfile.ubuntu-xenial +++ b/ci/kokoro/readme/Dockerfile.ubuntu-xenial @@ -31,6 +31,20 @@ RUN apt update && \ pkg-config tar wget zlib1g-dev # ``` +# Ubuntu-16.04 does not provide a package for nlohmann_json. Manually install +# this library: + +# ```bash +WORKDIR /var/tmp/build +RUN wget -q https://github.com/nlohmann/json/archive/v3.6.1.tar.gz +RUN tar -xf json-3.6.1.tar.gz +WORKDIR /var/tmp/build/json-3.6.1 +RUN cmake H. -Bcmake-out +RUN cmake --build cmake-out -- -j $(nproc) +RUN cmake --build cmake-out --target install +# ``` + + FROM devtools AS readme ## [START IGNORED] diff --git a/cmake/DownloadNlohmannJson.cmake b/cmake/DownloadNlohmannJson.cmake deleted file mode 100644 index 1db953bedc2cd..0000000000000 --- a/cmake/DownloadNlohmannJson.cmake +++ /dev/null @@ -1,88 +0,0 @@ -# ~~~ -# 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. -# ~~~ - -# A helper file for IncludeNlohmannJson. We need to download the json.hpp file. -# With old versions of cmake there is no way to disable the untar step from all -# downloads, and we get failures. This is a custom cmake script to download -# that file. -set(JSON_URL - "https://github.com/nlohmann/json/releases/download/v3.4.0/json.hpp") -set( - JSON_SHA256 63da6d1f22b2a7bb9e4ff7d6b255cf691a161ff49532dcc45d398a53e295835f - ) - -# Use a function to avoid filling up the global namespace with local variables. -function (_download_json_hpp) - set(sleep_seconds 2) - foreach (attempt 1 2 3 4 5) - math(EXPR sleep_seconds "2 * ${sleep_seconds}") - if (NOT attempt EQUAL 1) - message( - STATUS - "Will retry after ${sleep_seconds} seconds (attempt #${attempt})." - ) - execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep - "${sleep_seconds}") - endif () - file(DOWNLOAD "${JSON_URL}" "${DEST}/json.hpp" STATUS download_status) - list(GET download_status 0 download_error_code) - if (download_error_code EQUAL 0) - break() - endif () - endforeach () - - if (NOT download_error_code EQUAL 0) - message( - FATAL_ERROR - "Could not download ${JSON_URL} after multiple attempts." - " status=${download_status}") - endif () - - file(SHA256 "${DEST}/json.hpp" actual_json_hpp_sha256) - if (NOT "${JSON_SHA256}" STREQUAL "${actual_json_hpp_sha256}") - message(FATAL_ERROR "Mismatch digest for downloaded json.hpp file." - "\n expected hash: [${JSON_SHA256}]" - "\n actual hash: [${actual_json_hpp_sha256}]") - endif () - # Remove the definitions of `operator""_json()` and - # `operator""_json_pointer`. I know it looks ugly to remove specific lines, - # but we know the contents of the file exactly (there is a SHA256 hash of it - # above). - file(READ "${DEST}/json.hpp" JSON_HPP_CONTENT) - string( - REPLACE - [==[ -inline nlohmann::json operator "" _json(const char* s, std::size_t n) -{ - return nlohmann::json::parse(s, s + n); -} -]==] - "" JSON_HPP_CONTENT "${JSON_HPP_CONTENT}") - string(REPLACE - [==[ -inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n) -{ - return nlohmann::json::json_pointer(std::string(s, n)); -} -]==] - "" - JSON_HPP_CONTENT - "${JSON_HPP_CONTENT}") - - file(WRITE "${DEST}/json.hpp" "${JSON_HPP_CONTENT}") -endfunction () - -_download_json_hpp() diff --git a/cmake/IncludeNlohmannJson.cmake b/cmake/IncludeNlohmannJson.cmake deleted file mode 100644 index 7ffafab171a7f..0000000000000 --- a/cmake/IncludeNlohmannJson.cmake +++ /dev/null @@ -1,47 +0,0 @@ -# ~~~ -# 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. -# ~~~ - -include(ExternalProject) -externalproject_add( - nlohmann_json_project - PREFIX "${CMAKE_BINARY_DIR}/external/nlohmann_json" - DOWNLOAD_COMMAND ${CMAKE_COMMAND} - -DDEST=/src - -P - ${PROJECT_SOURCE_DIR}/cmake/DownloadNlohmannJson.cmake - CONFIGURE_COMMAND "" # This is not great, we abuse the `build` step to - # create the target directory. Unfortunately there is - # no way to specify two commands in the install step. - BUILD_COMMAND ${CMAKE_COMMAND} - -E - make_directory - /include - INSTALL_COMMAND - ${CMAKE_COMMAND} - -E - copy - /src/json.hpp - /include/google/cloud/storage/internal/nlohmann_json.hpp - LOG_DOWNLOAD ON - LOG_INSTALL ON) - -add_library(nlohmann_json INTERFACE) -add_dependencies(nlohmann_json nlohmann_json_project) -target_include_directories( - nlohmann_json - INTERFACE - $ - $) diff --git a/google/cloud/storage/CMakeLists.txt b/google/cloud/storage/CMakeLists.txt index 2b1fda02bf47f..23a30acd1ca1d 100644 --- a/google/cloud/storage/CMakeLists.txt +++ b/google/cloud/storage/CMakeLists.txt @@ -44,7 +44,8 @@ if (TARGET storage-docs AND TARGET cloud-docs) add_dependencies(storage-docs cloud-docs) endif () -include(IncludeNlohmannJson) +find_package(nlohmann_json CONFIG REQUIRED) + include(IncludeCrc32c) # Generate the version information from the CMake values. @@ -223,7 +224,7 @@ add_library(storage_client well_known_parameters.h) target_link_libraries(storage_client PUBLIC google_cloud_cpp_common - nlohmann_json + nlohmann_json::nlohmann_json Crc32c::crc32c CURL::libcurl Threads::Threads @@ -282,7 +283,7 @@ if (BUILD_TESTING) testing/storage_integration_test.cc) target_link_libraries(storage_client_testing PUBLIC storage_client - nlohmann_json + nlohmann_json::nlohmann_json GTest::gmock_main GTest::gmock GTest::gtest @@ -335,8 +336,6 @@ if (BUILD_TESTING) internal/logging_client_test.cc internal/logging_resumable_upload_session_test.cc internal/metadata_parser_test.cc - internal/nljson_use_after_third_party_test.cc - internal/nljson_use_third_party_test.cc internal/notification_requests_test.cc internal/object_acl_requests_test.cc internal/object_requests_test.cc @@ -398,7 +397,7 @@ if (BUILD_TESTING) GTest::gtest CURL::libcurl storage_common_options - nlohmann_json) + nlohmann_json::nlohmann_json) if (MSVC) target_compile_options(${target} PRIVATE "/bigobj") endif () @@ -444,7 +443,7 @@ endif () if ("${GOOGLE_CLOUD_CPP_STORAGE_ENABLE_INSTALL}") # Install the libraries and headers in the locations determined by # GNUInstallDirs - install(TARGETS storage_common_options nlohmann_json + install(TARGETS storage_common_options nlohmann_json::nlohmann_json EXPORT storage-targets RUNTIME DESTINATION bin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} @@ -461,10 +460,6 @@ if ("${GOOGLE_CLOUD_CPP_STORAGE_ENABLE_INSTALL}") ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) google_cloud_cpp_install_headers( storage_client include/google/cloud/storage) - install( - FILES - ${CMAKE_BINARY_DIR}/external/nlohmann_json/include/google/cloud/storage/internal/nlohmann_json.hpp - DESTINATION include/google/cloud/storage/internal) # Setup global variables used in the following *.in files. set(GOOGLE_CLOUD_CPP_CONFIG_VERSION_MAJOR ${STORAGE_CLIENT_VERSION_MAJOR}) diff --git a/google/cloud/storage/internal/nljson.h b/google/cloud/storage/internal/nljson.h index d75810ea9db71..9cc91b325501d 100644 --- a/google/cloud/storage/internal/nljson.h +++ b/google/cloud/storage/internal/nljson.h @@ -16,44 +16,7 @@ #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_NLJSON_H_ #include "google/cloud/storage/version.h" - -/** - * @file - * - * Include the nlohmann/json headers but renaming the namespace. - * - * We use the excellent nlohmann/json library to parse JSON in this client. - * However, we do not want to create dependency conflicts where our version of - * the code clashes with a different version that the user may have included. - * We always include the library through this header, and rename its top-level - * namespace to avoid conflicts. Because nlohmann/json is a header-only library - * no further action is needed. - * - * @see https://github.com/nlohmann/json.git - */ - -// Remove the include guards because third-parties may have included their own -// version of nlohmann::json. This is safe because google/cloud/storage always -// includes the nlohmann::json through this header, so after the first time our -// own include guards are enough. -#undef NLOHMANN_JSON_HPP -#undef NLOHMANN_JSON_FWD_HPP - -#define nlohmann google_cloud_storage_internal_nlohmann_3_4_0 -#include "google/cloud/storage/internal/nlohmann_json.hpp" - -// Remove the include guards so third-parties can include their own version of -// nlohmann::json. This is safe because google/cloud/storage always includes -// the nlohmann::json through this header, so after the first time our own -// include guards are enough. -#undef NLOHMANN_BASIC_JSON_TPL -#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION -#undef NLOHMANN_JSON_HPP -#undef NLOHMANN_JSON_FWD_HPP -#undef NLOHMANN_JSON_SERIALIZE_ENUM -#undef NLOHMANN_JSON_VERSION_MAJOR -#undef NLOHMANN_JSON_VERSION_MINOR -#undef NLOHMANN_JSON_VERSION_PATCH +#include namespace nlohmann { // @@ -69,14 +32,13 @@ namespace nlohmann { /// Prints json objects to output streams from within Google Test. inline void PrintTo(json const& j, std::ostream* os) { *os << j.dump(); } } // namespace nlohmann -#undef nlohmann namespace google { namespace cloud { namespace storage { inline namespace STORAGE_CLIENT_NS { namespace internal { -namespace nl = ::google_cloud_storage_internal_nlohmann_3_4_0; +namespace nl = ::nlohmann; } // namespace internal } // namespace STORAGE_CLIENT_NS } // namespace storage diff --git a/google/cloud/storage/internal/nljson_use_after_third_party_test.cc b/google/cloud/storage/internal/nljson_use_after_third_party_test.cc deleted file mode 100644 index badf84ba3e7ad..0000000000000 --- a/google/cloud/storage/internal/nljson_use_after_third_party_test.cc +++ /dev/null @@ -1,38 +0,0 @@ -// 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. - -// Verify that we can #include the nljson.h header after a third-party has -// included json.hpp directly. We want to support both users that include -// nlohmann::json first (which is what this test file checks), and users that -// include our headers first (which nljson_use_third_party_test.cc checks). -// We simulate the nlohmann::json include by including nlohmann_json.hpp -#include "google/cloud/storage/internal/nlohmann_json.hpp" -// Create a separate include block to prevent clang-format from reordering. - -#include "google/cloud/storage/internal/nljson.h" -#include - -/// @test Verify that we can compile against the nlohmann::json library. -TEST(NlJsonTest, Simple) { - google::cloud::storage::internal::nl::json json = { - {"pi", 3.141}, - {"happy", true}, - {"nothing", nullptr}, - {"answer", {{"everything", 42}}}, - {"list", {1, 0, 2}}, - {"object", {{"currency", "USD"}, {"value", 42.99}}}}; - EXPECT_NEAR(3.141, json["pi"], 0.001); - EXPECT_EQ("USD", json["object"]["currency"]); - EXPECT_EQ(1, json["list"][0]); -} diff --git a/google/cloud/storage/internal/nljson_use_third_party_test.cc b/google/cloud/storage/internal/nljson_use_third_party_test.cc deleted file mode 100644 index fc3104206a89e..0000000000000 --- a/google/cloud/storage/internal/nljson_use_third_party_test.cc +++ /dev/null @@ -1,39 +0,0 @@ -// 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. - -#include "google/cloud/storage/internal/nljson.h" - -// Verify that we can #include the nljson.h header before a third-party includes -// json.hpp directly. We want to support both users that include nlohmann::json -// first (which is what nljson_use_after_third_party_test.cc checks), and users -// that include our headers first (which is what this program tests). -// We simulate the nlohmann::json include by including nlohmann_json.hpp -#include "google/cloud/storage/internal/nlohmann_json.hpp" -// Create a separate include block to prevent clang-format from reordering. - -#include - -/// @test Verify third-parties can include their own lohmann::json headers. -TEST(NlJsonUseThirdPartTest, Simple) { - ::nlohmann::json object = { - {"pi", 3.141}, - {"happy", true}, - {"nothing", nullptr}, - {"answer", {{"everything", 42}}}, - {"list", {1, 0, 2}}, - {"object", {{"currency", "USD"}, {"value", 42.99}}}}; - EXPECT_NEAR(3.141, object["pi"], 0.001); - EXPECT_EQ("USD", object["object"]["currency"]); - EXPECT_EQ(1, object["list"][0]); -} diff --git a/google/cloud/storage/storage_client_unit_tests.bzl b/google/cloud/storage/storage_client_unit_tests.bzl index 0afa25f199f07..d1574714e3655 100644 --- a/google/cloud/storage/storage_client_unit_tests.bzl +++ b/google/cloud/storage/storage_client_unit_tests.bzl @@ -54,8 +54,6 @@ storage_client_unit_tests = [ "internal/logging_client_test.cc", "internal/logging_resumable_upload_session_test.cc", "internal/metadata_parser_test.cc", - "internal/nljson_use_after_third_party_test.cc", - "internal/nljson_use_third_party_test.cc", "internal/notification_requests_test.cc", "internal/object_acl_requests_test.cc", "internal/object_requests_test.cc", diff --git a/google/cloud/storage/tests/CMakeLists.txt b/google/cloud/storage/tests/CMakeLists.txt index aa967084a0740..46e1969622390 100644 --- a/google/cloud/storage/tests/CMakeLists.txt +++ b/google/cloud/storage/tests/CMakeLists.txt @@ -57,7 +57,7 @@ foreach (fname ${storage_client_integration_tests}) GTest::gtest CURL::libcurl Threads::Threads - nlohmann_json + nlohmann_json::nlohmann_json storage_common_options) endforeach () diff --git a/google/cloud/storage/tests/write_deadlock_regression/CMakeLists.txt b/google/cloud/storage/tests/write_deadlock_regression/CMakeLists.txt index fa433de42c244..949edf133d40a 100644 --- a/google/cloud/storage/tests/write_deadlock_regression/CMakeLists.txt +++ b/google/cloud/storage/tests/write_deadlock_regression/CMakeLists.txt @@ -30,7 +30,7 @@ if ("${Backtrace_FOUND}") GTest::gtest CURL::libcurl Threads::Threads - nlohmann_json + nlohmann_json::nlohmann_json storage_common_options) target_include_directories(object_write_deadlock_regression_test PRIVATE "${Backtrace_INCLUDE_DIRS}")