From f7dfa56b00f11e0bdba2032b9114d779f9a64318 Mon Sep 17 00:00:00 2001 From: owent Date: Fri, 9 Dec 2022 12:05:58 +0800 Subject: [PATCH] Using fallback version of span when `std::span` do not support `range`. Signed-off-by: owent --- .github/workflows/ci.yml | 13 ++++++-- CHANGELOG.md | 3 +- CMakeLists.txt | 1 - api/include/opentelemetry/nostd/span.h | 22 ++++++++++++- cmake/compiler-detection.cmake | 45 -------------------------- 5 files changed, 34 insertions(+), 50 deletions(-) delete mode 100644 cmake/compiler-detection.cmake diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1c9225ff82..0696178163 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -163,12 +163,18 @@ jobs: with: submodules: 'recursive' - name: setup + env: + CMAKE_VERSION: "3.20.6" run: | - sudo ./ci/setup_ci_environment.sh - sudo ./ci/setup_cmake.sh + sudo -E ./ci/setup_ci_environment.sh + sudo -E ./ci/setup_cmake.sh - name: run tests + env: + CMAKE_VERSION: "3.20.6" run: ./ci/do_ci.sh cmake.c++20.test - name: run tests (enable stl) + env: + CMAKE_VERSION: "3.20.6" run: ./ci/do_ci.sh cmake.c++20.stl.test cmake_test_cxx20_clang: @@ -183,6 +189,7 @@ jobs: CC: /usr/bin/clang CXX: /usr/bin/clang++ CXXFLAGS: "-stdlib=libc++" + CMAKE_VERSION: "3.20.6" run: | sudo -E ./ci/setup_ci_environment.sh sudo -E ./ci/setup_cmake.sh @@ -191,12 +198,14 @@ jobs: CC: /usr/bin/clang CXX: /usr/bin/clang++ CXXFLAGS: "-stdlib=libc++" + CMAKE_VERSION: "3.20.6" run: ./ci/do_ci.sh cmake.c++20.test - name: run tests (enable stl) env: CC: /usr/bin/clang CXX: /usr/bin/clang++ CXXFLAGS: "-stdlib=libc++" + CMAKE_VERSION: "3.20.6" run: ./ci/do_ci.sh cmake.c++20.stl.test cmake_otprotocol_test: diff --git a/CHANGELOG.md b/CHANGELOG.md index 78c505451b..921f886b18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,8 @@ Increment the: ## [Unreleased] -* [TESTS] Upgrade default version of googletest to 1.12.1 ([#1852](https://github.com/open-telemetry/opentelemetry-cpp/pull/1852)) +* [TESTS] Upgrade default version of googletest to 1.12.1, using cmake 3.20.6 +with C++20 [#1852](https://github.com/open-telemetry/opentelemetry-cpp/pull/1852) * [BUILD] Fix OTELCPP_MAINTAINER_MODE [#1844](https://github.com/open-telemetry/opentelemetry-cpp/pull/1844) ## [1.8.1] 2022-12-04 diff --git a/CMakeLists.txt b/CMakeLists.txt index 14622a97a6..f1a6d1cd17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -486,7 +486,6 @@ if(BUILD_TESTING) endif() endif() -include("${CMAKE_CURRENT_LIST_DIR}/cmake/compiler-detection.cmake") include(CMakePackageConfigHelpers) include_directories(api/include) diff --git a/api/include/opentelemetry/nostd/span.h b/api/include/opentelemetry/nostd/span.h index 6c24a380c6..3da7f36a84 100644 --- a/api/include/opentelemetry/nostd/span.h +++ b/api/include/opentelemetry/nostd/span.h @@ -5,7 +5,27 @@ // Try to use either `std::span` or `gsl::span` #ifdef HAVE_CPP_STDLIB -# include "opentelemetry/std/span.h" +# include +# include +# include +# include + +/** + * @brief Clang 14.0.0 with libc++ do not support implicitly construct a span for a range.We just + * use our fallback version. + * + */ +# if defined(_LIBCPP_VERSION) +# if _LIBCPP_VERSION <= 14000 +# define OPENTELEMETRY_OPTION_USE_STD_SPAN 0 +# endif +# endif +# ifndef OPENTELEMETRY_OPTION_USE_STD_SPAN +# define OPENTELEMETRY_OPTION_USE_STD_SPAN 1 +# endif +# if OPENTELEMETRY_OPTION_USE_STD_SPAN +# include "opentelemetry/std/span.h" +# endif #endif // Fallback to `nostd::span` if necessary diff --git a/cmake/compiler-detection.cmake b/cmake/compiler-detection.cmake deleted file mode 100644 index f7239cd424..0000000000 --- a/cmake/compiler-detection.cmake +++ /dev/null @@ -1,45 +0,0 @@ -function(print_cxx_environment) - - if(NOT CMAKE_CROSSCOMPILING) - file( - WRITE "${CMAKE_CURRENT_BINARY_DIR}/otel-cpp-compiler-detection.cc" - " -#include -#include -int main() { -#if defined(_MSVC_LANG) -# if _MSVC_LANG == __cplusplus - std::cout<< \"C++ standard: \"<< _MSVC_LANG<< \"(with /Zc:__cplusplus)\"<< std::endl; -# else - std::cout<< \"C++ standard: \"<< __cplusplus<< \"(without /Zc:__cplusplus)\"<< std::endl; -# endif -#else - std::cout<< \"C++ standard: \"<< __cplusplus<< std::endl; -#endif -#if defined(_LIBCPP_VERSION) - std::cout<< \"libc++: \"<< _LIBCPP_VERSION<< std::endl; -#elif defined(__GLIBCXX__) - std::cout<< \"libstdc++: \"<< __GLIBCXX__<< std::endl; -#elif defined(_MSVC_STL_VERSION) && defined(_MSVC_STL_UPDATE) - std::cout<< \"MSVC STL: \"<< _MSVC_STL_VERSION<< \".\"<< _MSVC_STL_UPDATE<< std::endl; -#endif - return 0; -} -") - - try_run( - COMPILER_CHECK_STDLIB_RUN_RESULT COMPILER_CHECK_STDLIB_COMPILE_RESULT - "${CMAKE_CURRENT_BINARY_DIR}" - "${CMAKE_CURRENT_BINARY_DIR}/otel-cpp-compiler-detection.cc" - COMPILE_OUTPUT_VARIABLE COMPILER_CHECK_STDLIB_COMPILE_OUTPUT - RUN_OUTPUT_VARIABLE COMPILER_CHECK_STDLIB_RUN_OUTPUT) - if(COMPILER_CHECK_STDLIB_RUN_OUTPUT) - message(STATUS "C++ settings: -${COMPILER_CHECK_STDLIB_RUN_OUTPUT}") - else() - message(WARNING "${COMPILER_CHECK_STDLIB_COMPILE_OUTPUT}") - endif() - endif() -endfunction() - -print_cxx_environment()