From 67f5a79c245afaa499f3fcfb9a0a9123992e4773 Mon Sep 17 00:00:00 2001 From: Johannes Tax Date: Mon, 15 Jun 2020 12:06:51 -0700 Subject: [PATCH 1/5] Fix builds for C++20 --- .github/workflows/ci.yml | 11 +++++++++ CMakeLists.txt | 4 +++- ci/do_ci.sh | 10 ++++++++ .../sdk/common/atomic_shared_ptr.h | 24 +++---------------- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ddda0f986..88a3898d86 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,6 +19,17 @@ jobs: - name: run tests run: ./ci/do_ci.sh cmake.test + name: CMake C++20 test + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - name: setup + run: | + sudo ./ci/setup_ci_environment.sh + sudo ./ci/setup_cmake.sh + - name: run tests + run: ./ci/do_ci.sh cmake.c++20.test + plugin_test: name: Plugin -> CMake runs-on: ubuntu-latest diff --git a/CMakeLists.txt b/CMakeLists.txt index 264d58992d..c2ed2b6d80 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,9 @@ cmake_policy(SET CMP0057 NEW) project(opentelemetry-cpp) -set(CMAKE_CXX_STANDARD 11) +if(NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 11) +endif() option(WITH_OTPROTOCOL "Whether to include the OpenTelemetry Protocol in the SDK" OFF) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index f80ca7d749..cd41b0a6b4 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -20,6 +20,16 @@ if [[ "$1" == "cmake.test" ]]; then make make test exit 0 +elif [[ "$1" == "cmake.c++20.test" ]]; then + cd "${BUILD_DIR}" + rm -rf * + cmake -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_FLAGS="-Werror" \ + -DCMAKE_CXX_STANDARD=20 \ + "${SRC_DIR}" + make + make test + exit 0 elif [[ "$1" == "cmake.exporter.otprotocol.test" ]]; then cd "${BUILD_DIR}" rm -rf * diff --git a/sdk/include/opentelemetry/sdk/common/atomic_shared_ptr.h b/sdk/include/opentelemetry/sdk/common/atomic_shared_ptr.h index 968167aea8..f3630cce67 100644 --- a/sdk/include/opentelemetry/sdk/common/atomic_shared_ptr.h +++ b/sdk/include/opentelemetry/sdk/common/atomic_shared_ptr.h @@ -11,28 +11,10 @@ namespace sdk /** * A wrapper to provide atomic shared pointers. * - * This wrapper relies on std::atomic for C++20, a mutex for gcc 4.8, and - * specializations of std::atomic_store and std::atomic_load for all other - * instances. + * This wrapper relies on a mutex for gcc 4.8, and specializations of + * std::atomic_store and std::atomic_load for all other instances. */ -#if __cplusplus > 201703L -template -class AtomicSharedPtr -{ -public: - explicit AtomicSharedPtr(std::shared_ptr ptr) noexcept : ptr_{std::move(ptr)} {} - - void store(const std::shared_ptr &other) noexcept - { - ptr_.store(other, std::memory_order_release); - } - - std::shared_ptr load() const noexcept { return ptr_.load(std::memory_order_acquire); } - -private: - std::atomic> ptr_; -}; -#elif (__GNUC__ == 4 && (__GNUC_MINOR__ >= 8)) +#if (__GNUC__ == 4 && (__GNUC_MINOR__ >= 8)) template class AtomicSharedPtr { From 46d21c30697b8b41683ac9aa4191760eaa0f7db2 Mon Sep 17 00:00:00 2001 From: Johannes Tax Date: Mon, 15 Jun 2020 12:23:06 -0700 Subject: [PATCH 2/5] Fix yaml --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88a3898d86..036f062ef5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,6 +19,7 @@ jobs: - name: run tests run: ./ci/do_ci.sh cmake.test + cmake_test_cxx20: name: CMake C++20 test runs-on: ubuntu-20.04 steps: From 64d2a15e6a85a28ae5730e714191dfcaa5fb1c36 Mon Sep 17 00:00:00 2001 From: Johannes Tax Date: Mon, 15 Jun 2020 12:32:11 -0700 Subject: [PATCH 3/5] Adapt to different CMake behavior on Ubuntu 20 --- ci/setup_cmake.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/setup_cmake.sh b/ci/setup_cmake.sh index 1e22f39f81..0ab9be37fd 100755 --- a/ci/setup_cmake.sh +++ b/ci/setup_cmake.sh @@ -12,5 +12,5 @@ apt-get install --no-install-recommends --no-install-suggests -y \ pushd /usr/src/gtest cmake CMakeLists.txt make -cp *.a /usr/lib +cp *.a /usr/lib || cp lib/*.a /usr/lib popd From 1ae4c1127c539f1667c71e1086c298ee1734b49d Mon Sep 17 00:00:00 2001 From: Johannes Tax Date: Mon, 15 Jun 2020 20:56:43 -0700 Subject: [PATCH 4/5] Add README entry --- ci/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/README.md b/ci/README.md index f755d3f54a..5741684d9f 100644 --- a/ci/README.md +++ b/ci/README.md @@ -3,6 +3,7 @@ CI tests can be run on docker by invoking the script `./ci/run_docker.sh ./ci/do_ci.sh ` where the targets are: * `cmake.test`: build cmake targets and run tests. +* `cmake.c++20.test`: build cmake targets with the C++20 standard and run tests. * `cmake.test_example_plugin`: build and test an example OpenTelemetry plugin. * `cmake.exporter.otprotocol.test`: build and test the otprotocol exporter * `bazel.test`: build bazel targets and run tests. From da901a80d403af5887d7591eec88f3d24cabd32b Mon Sep 17 00:00:00 2001 From: Johannes Tax Date: Mon, 15 Jun 2020 21:33:56 -0700 Subject: [PATCH 5/5] Make random tests less flaky --- sdk/test/common/random_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/test/common/random_test.cc b/sdk/test/common/random_test.cc index b3768c5a79..850e289fff 100644 --- a/sdk/test/common/random_test.cc +++ b/sdk/test/common/random_test.cc @@ -20,7 +20,7 @@ TEST(RandomTest, GenerateRandomBuffer) EXPECT_FALSE(std::equal(std::begin(buf1), std::end(buf1), std::begin(buf2))); // Edge cases. - for (auto size : {1, 7, 8, 9, 16, 17}) + for (auto size : {7, 8, 9, 16, 17}) { std::vector buf1(size); std::vector buf2(size);