From e648b5c0512c9e9257224c57a3d2d786ffd7f9ce Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Fri, 4 Nov 2022 16:49:40 +0100 Subject: [PATCH 01/13] WIP --- CMakeLists.txt | 52 +++++++++++++++++-- api/include/opentelemetry/nostd/shared_ptr.h | 2 +- api/include/opentelemetry/nostd/string_view.h | 2 +- api/include/opentelemetry/nostd/unique_ptr.h | 2 +- 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e7597fc87a..1d49ad6536 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,14 +107,60 @@ else() ) endif() -option(WITH_STL "Whether to use Standard Library for C++ latest features" OFF) +set(WITH_STL "OFF" CACHE STRING "Which version of the Standard Library for C++ to use") + option(WITH_GSL "Whether to use Guidelines Support Library for C++ latest features" OFF) option(WITH_ABSEIL "Whether to use Abseil for C++latest features" OFF) +if(WITH_STL STREQUAL "OFF") + if(NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 11) + endif() + # STL not used. +elseif(WITH_STL STREQUAL "CXX11") + add_definitions(-DOPENTELEMETRY_HAVE_CXX11) + if(NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 11) + endif() +elseif(WITH_STL STREQUAL "CXX14") + add_definitions(-DOPENTELEMETRY_HAVE_CXX11) + add_definitions(-DOPENTELEMETRY_HAVE_CXX14) + if(NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 14) + endif() +elseif(WITH_STL STREQUAL "CXX17") + add_definitions(-DOPENTELEMETRY_HAVE_CXX11) + add_definitions(-DOPENTELEMETRY_HAVE_CXX14) + add_definitions(-DOPENTELEMETRY_HAVE_CXX17) + if(NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) + endif() +elseif(WITH_STL STREQUAL "CXX20") + add_definitions(-DOPENTELEMETRY_HAVE_CXX11) + add_definitions(-DOPENTELEMETRY_HAVE_CXX14) + add_definitions(-DOPENTELEMETRY_HAVE_CXX17) + add_definitions(-DOPENTELEMETRY_HAVE_CXX20) + if(NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 20) + endif() +elseif(WITH_STL STREQUAL "ON") + # "ON" corresponds to "CXX20" at this time. + add_definitions(-DOPENTELEMETRY_HAVE_CXX11) + add_definitions(-DOPENTELEMETRY_HAVE_CXX14) + add_definitions(-DOPENTELEMETRY_HAVE_CXX17) + add_definitions(-DOPENTELEMETRY_HAVE_CXX20) + if(NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 20) + endif() +else() + message(FATAL_ERROR "WITH_STL must be ON, OFF, CXX11, CXX14, CXX17 or CXX20") +endif() + + if(NOT DEFINED CMAKE_CXX_STANDARD) - if(WITH_STL) + if(NOT WITH_STL STREQUAL "OFF") # Require at least C++17. C++20 is needed to avoid gsl::span if(CMAKE_VERSION VERSION_GREATER 3.11.999) # Ask for 20, may get anything below @@ -128,7 +174,7 @@ if(NOT DEFINED CMAKE_CXX_STANDARD) endif() endif() -if(WITH_STL) +if(NOT WITH_STL STREQUAL "OFF") # These definitions are needed for test projects that do not link against # opentelemetry-api library directly. We ensure that variant implementation # (absl::variant or std::variant) in variant unit test code is consistent with diff --git a/api/include/opentelemetry/nostd/shared_ptr.h b/api/include/opentelemetry/nostd/shared_ptr.h index e1eac61561..0d37924215 100644 --- a/api/include/opentelemetry/nostd/shared_ptr.h +++ b/api/include/opentelemetry/nostd/shared_ptr.h @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef HAVE_CPP_STDLIB +#ifdef OPENTELEMETRY_HAVE_CXX11 # include "opentelemetry/std/shared_ptr.h" #else # include diff --git a/api/include/opentelemetry/nostd/string_view.h b/api/include/opentelemetry/nostd/string_view.h index ac27c3dc79..1f203fb6a5 100644 --- a/api/include/opentelemetry/nostd/string_view.h +++ b/api/include/opentelemetry/nostd/string_view.h @@ -3,7 +3,7 @@ #pragma once -#ifdef HAVE_CPP_STDLIB +#ifdef OPENTELEMETRY_HAVE_CXX17 # include "opentelemetry/std/string_view.h" #else # include diff --git a/api/include/opentelemetry/nostd/unique_ptr.h b/api/include/opentelemetry/nostd/unique_ptr.h index a97111b9d0..23c12cd9db 100644 --- a/api/include/opentelemetry/nostd/unique_ptr.h +++ b/api/include/opentelemetry/nostd/unique_ptr.h @@ -3,7 +3,7 @@ #pragma once -#ifdef HAVE_CPP_STDLIB +#ifdef OPENTELEMETRY_HAVE_CXX11 # include "opentelemetry/std/unique_ptr.h" #else # include From 72ea66e4694256d4e5e412d480a3ad14df7dd406 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 7 Nov 2022 15:25:41 +0100 Subject: [PATCH 02/13] WIP --- CMakeLists.txt | 28 +++++++++---------- api/include/opentelemetry/nostd/shared_ptr.h | 2 +- api/include/opentelemetry/nostd/string_view.h | 2 +- api/include/opentelemetry/nostd/unique_ptr.h | 2 +- api/include/opentelemetry/nostd/utility.h | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d49ad6536..921680cac0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,37 +120,37 @@ if(WITH_STL STREQUAL "OFF") endif() # STL not used. elseif(WITH_STL STREQUAL "CXX11") - add_definitions(-DOPENTELEMETRY_HAVE_CXX11) + add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX11) if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 11) endif() elseif(WITH_STL STREQUAL "CXX14") - add_definitions(-DOPENTELEMETRY_HAVE_CXX11) - add_definitions(-DOPENTELEMETRY_HAVE_CXX14) + add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX11) + add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX14) if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 14) endif() elseif(WITH_STL STREQUAL "CXX17") - add_definitions(-DOPENTELEMETRY_HAVE_CXX11) - add_definitions(-DOPENTELEMETRY_HAVE_CXX14) - add_definitions(-DOPENTELEMETRY_HAVE_CXX17) + add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX11) + add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX14) + add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX17) if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) endif() elseif(WITH_STL STREQUAL "CXX20") - add_definitions(-DOPENTELEMETRY_HAVE_CXX11) - add_definitions(-DOPENTELEMETRY_HAVE_CXX14) - add_definitions(-DOPENTELEMETRY_HAVE_CXX17) - add_definitions(-DOPENTELEMETRY_HAVE_CXX20) + add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX11) + add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX14) + add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX17) + add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX20) if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 20) endif() elseif(WITH_STL STREQUAL "ON") # "ON" corresponds to "CXX20" at this time. - add_definitions(-DOPENTELEMETRY_HAVE_CXX11) - add_definitions(-DOPENTELEMETRY_HAVE_CXX14) - add_definitions(-DOPENTELEMETRY_HAVE_CXX17) - add_definitions(-DOPENTELEMETRY_HAVE_CXX20) + add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX11) + add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX14) + add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX17) + add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX20) if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 20) endif() diff --git a/api/include/opentelemetry/nostd/shared_ptr.h b/api/include/opentelemetry/nostd/shared_ptr.h index 0d37924215..4a7833fba1 100644 --- a/api/include/opentelemetry/nostd/shared_ptr.h +++ b/api/include/opentelemetry/nostd/shared_ptr.h @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef OPENTELEMETRY_HAVE_CXX11 +#ifdef OPENTELEMETRY_HAVE_STL_CXX11 # include "opentelemetry/std/shared_ptr.h" #else # include diff --git a/api/include/opentelemetry/nostd/string_view.h b/api/include/opentelemetry/nostd/string_view.h index 1f203fb6a5..3923563e33 100644 --- a/api/include/opentelemetry/nostd/string_view.h +++ b/api/include/opentelemetry/nostd/string_view.h @@ -3,7 +3,7 @@ #pragma once -#ifdef OPENTELEMETRY_HAVE_CXX17 +#ifdef OPENTELEMETRY_HAVE_STL_CXX17 # include "opentelemetry/std/string_view.h" #else # include diff --git a/api/include/opentelemetry/nostd/unique_ptr.h b/api/include/opentelemetry/nostd/unique_ptr.h index 23c12cd9db..7f930f65cc 100644 --- a/api/include/opentelemetry/nostd/unique_ptr.h +++ b/api/include/opentelemetry/nostd/unique_ptr.h @@ -3,7 +3,7 @@ #pragma once -#ifdef OPENTELEMETRY_HAVE_CXX11 +#ifdef OPENTELEMETRY_HAVE_STL_CXX11 # include "opentelemetry/std/unique_ptr.h" #else # include diff --git a/api/include/opentelemetry/nostd/utility.h b/api/include/opentelemetry/nostd/utility.h index bb350594ad..f333f6e283 100644 --- a/api/include/opentelemetry/nostd/utility.h +++ b/api/include/opentelemetry/nostd/utility.h @@ -3,7 +3,7 @@ #pragma once -#ifdef HAVE_CPP_STDLIB +#ifdef OPENTELEMETRY_HAVE_STL_CXX14 # include "opentelemetry/std/utility.h" #else From 294a766ddeee70d199623a49bc308ecec42d4e2c Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 8 Dec 2022 01:06:46 +0100 Subject: [PATCH 03/13] WIP --- CMakeLists.txt | 20 ++++++------------- api/include/opentelemetry/nostd/shared_ptr.h | 3 ++- api/include/opentelemetry/nostd/string_view.h | 2 +- api/include/opentelemetry/nostd/unique_ptr.h | 2 +- api/include/opentelemetry/nostd/utility.h | 2 +- 5 files changed, 11 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 921680cac0..a3a04957ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,42 +115,34 @@ option(WITH_GSL option(WITH_ABSEIL "Whether to use Abseil for C++latest features" OFF) if(WITH_STL STREQUAL "OFF") + add_definitions(-DOPENTELEMETRY_STL_VERSION=0) if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 11) endif() # STL not used. elseif(WITH_STL STREQUAL "CXX11") - add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX11) + add_definitions(-DOPENTELEMETRY_STL_VERSION=2011) if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 11) endif() elseif(WITH_STL STREQUAL "CXX14") - add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX11) - add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX14) + add_definitions(-DOPENTELEMETRY_STL_VERSION=2014) if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 14) endif() elseif(WITH_STL STREQUAL "CXX17") - add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX11) - add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX14) - add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX17) + add_definitions(-DOPENTELEMETRY_STL_VERSION=2017) if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) endif() elseif(WITH_STL STREQUAL "CXX20") - add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX11) - add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX14) - add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX17) - add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX20) + add_definitions(-DOPENTELEMETRY_STL_VERSION=2020) if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 20) endif() elseif(WITH_STL STREQUAL "ON") # "ON" corresponds to "CXX20" at this time. - add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX11) - add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX14) - add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX17) - add_definitions(-DOPENTELEMETRY_HAVE_STL_CXX20) + add_definitions(-DOPENTELEMETRY_STL_VERSION=2020) if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 20) endif() diff --git a/api/include/opentelemetry/nostd/shared_ptr.h b/api/include/opentelemetry/nostd/shared_ptr.h index 4a7833fba1..43a405cd4b 100644 --- a/api/include/opentelemetry/nostd/shared_ptr.h +++ b/api/include/opentelemetry/nostd/shared_ptr.h @@ -2,7 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef OPENTELEMETRY_HAVE_STL_CXX11 + +#if OPENTELEMETRY_STL_VERSION >= 2011 # include "opentelemetry/std/shared_ptr.h" #else # include diff --git a/api/include/opentelemetry/nostd/string_view.h b/api/include/opentelemetry/nostd/string_view.h index 3923563e33..a42a148522 100644 --- a/api/include/opentelemetry/nostd/string_view.h +++ b/api/include/opentelemetry/nostd/string_view.h @@ -3,7 +3,7 @@ #pragma once -#ifdef OPENTELEMETRY_HAVE_STL_CXX17 +#if OPENTELEMETRY_STL_VERSION >= 2017 # include "opentelemetry/std/string_view.h" #else # include diff --git a/api/include/opentelemetry/nostd/unique_ptr.h b/api/include/opentelemetry/nostd/unique_ptr.h index 7f930f65cc..1553f31e95 100644 --- a/api/include/opentelemetry/nostd/unique_ptr.h +++ b/api/include/opentelemetry/nostd/unique_ptr.h @@ -3,7 +3,7 @@ #pragma once -#ifdef OPENTELEMETRY_HAVE_STL_CXX11 +#if OPENTELEMETRY_STL_VERSION >= 2011 # include "opentelemetry/std/unique_ptr.h" #else # include diff --git a/api/include/opentelemetry/nostd/utility.h b/api/include/opentelemetry/nostd/utility.h index f333f6e283..599db26d39 100644 --- a/api/include/opentelemetry/nostd/utility.h +++ b/api/include/opentelemetry/nostd/utility.h @@ -3,7 +3,7 @@ #pragma once -#ifdef OPENTELEMETRY_HAVE_STL_CXX14 +#if OPENTELEMETRY_STL_VERSION >= 2014 # include "opentelemetry/std/utility.h" #else From 22537db7b8c850d0aa8f37d030cd121581cddf7f Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 31 Aug 2023 15:18:14 +0200 Subject: [PATCH 04/13] Fixes #1071 --- CMakeLists.txt | 51 ------------------- api/CMakeLists.txt | 24 +++++++-- api/include/opentelemetry/nostd/span.h | 4 +- api/include/opentelemetry/nostd/type_traits.h | 4 +- api/include/opentelemetry/nostd/variant.h | 2 +- api/test/nostd/span_test.cc | 15 ------ api/test/nostd/string_view_test.cc | 2 +- 7 files changed, 26 insertions(+), 76 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d9a4c5f668..664cc229ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,42 +122,6 @@ option(WITH_GSL option(WITH_ABSEIL "Whether to use Abseil for C++latest features" OFF) -if(WITH_STL STREQUAL "OFF") - add_definitions(-DOPENTELEMETRY_STL_VERSION=0) - if(NOT DEFINED CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 11) - endif() - # STL not used. -elseif(WITH_STL STREQUAL "CXX11") - add_definitions(-DOPENTELEMETRY_STL_VERSION=2011) - if(NOT DEFINED CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 11) - endif() -elseif(WITH_STL STREQUAL "CXX14") - add_definitions(-DOPENTELEMETRY_STL_VERSION=2014) - if(NOT DEFINED CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 14) - endif() -elseif(WITH_STL STREQUAL "CXX17") - add_definitions(-DOPENTELEMETRY_STL_VERSION=2017) - if(NOT DEFINED CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 17) - endif() -elseif(WITH_STL STREQUAL "CXX20") - add_definitions(-DOPENTELEMETRY_STL_VERSION=2020) - if(NOT DEFINED CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 20) - endif() -elseif(WITH_STL STREQUAL "ON") - # "ON" corresponds to "CXX20" at this time. - add_definitions(-DOPENTELEMETRY_STL_VERSION=2020) - if(NOT DEFINED CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 20) - endif() -else() - message(FATAL_ERROR "WITH_STL must be ON, OFF, CXX11, CXX14, CXX17 or CXX20") -endif() - set(OPENTELEMETRY_INSTALL_default ON) if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) set(OPENTELEMETRY_INSTALL_default OFF) @@ -167,21 +131,6 @@ option(OPENTELEMETRY_INSTALL "Whether to install opentelemetry targets" include("${PROJECT_SOURCE_DIR}/cmake/tools.cmake") -if(NOT DEFINED CMAKE_CXX_STANDARD) - if(NOT WITH_STL STREQUAL "OFF") - # Require at least C++17. C++20 is needed to avoid gsl::span - if(CMAKE_VERSION VERSION_GREATER 3.11.999) - # Ask for 20, may get anything below - set(CMAKE_CXX_STANDARD 20) - else() - # Ask for 17, may get anything below - set(CMAKE_CXX_STANDARD 17) - endif() - else() - set(CMAKE_CXX_STANDARD 11) - endif() -endif() - if(NOT WITH_STL STREQUAL "OFF") # These definitions are needed for test projects that do not link against # opentelemetry-api library directly. We ensure that variant implementation diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 41b6997980..de5fd09110 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -51,11 +51,27 @@ if(WITH_ABSEIL) "absl_bits" "absl_city") endif() -if(WITH_STL) - message("Building with standard library types...") - target_compile_definitions(opentelemetry_api INTERFACE HAVE_CPP_STDLIB) +if(WITH_STL STREQUAL "OFF") + message(STATUS "Building WITH_STL=OFF") + target_compile_definitions(opentelemetry_api INTERFACE OPENTELEMETRY_STL_VERSION=0) +elseif(WITH_STL STREQUAL "CXX11") + message(STATUS "Building WITH_STL=CXX1") + target_compile_definitions(opentelemetry_api INTERFACE OPENTELEMETRY_STL_VERSION=2011) +elseif(WITH_STL STREQUAL "CXX14") + message(STATUS "Building WITH_STL=CXX14") + target_compile_definitions(opentelemetry_api INTERFACE OPENTELEMETRY_STL_VERSION=2014) +elseif(WITH_STL STREQUAL "CXX17") + message(STATUS "Building WITH_STL=CXX17") + target_compile_definitions(opentelemetry_api INTERFACE OPENTELEMETRY_STL_VERSION=2017) +elseif(WITH_STL STREQUAL "CXX20") + message(STATUS "Building WITH_STL=CXX20") + target_compile_definitions(opentelemetry_api INTERFACE OPENTELEMETRY_STL_VERSION=2020) +elseif(WITH_STL STREQUAL "ON") + message(STATUS "Building WITH_STL=ON") + # "ON" corresponds to "CXX20" at this time. + target_compile_definitions(opentelemetry_api INTERFACE OPENTELEMETRY_STL_VERSION=2020) else() - message("Building with nostd types...") + message(FATAL_ERROR "WITH_STL must be ON, OFF, CXX11, CXX14, CXX17 or CXX20") endif() if(WITH_GSL) diff --git a/api/include/opentelemetry/nostd/span.h b/api/include/opentelemetry/nostd/span.h index 3022a913d9..389e26b178 100644 --- a/api/include/opentelemetry/nostd/span.h +++ b/api/include/opentelemetry/nostd/span.h @@ -4,7 +4,7 @@ #pragma once // Try to use either `std::span` or `gsl::span` -#ifdef HAVE_CPP_STDLIB +#if OPENTELEMETRY_STL_VERSION >= 2020 # include # include # include @@ -26,7 +26,7 @@ # if OPENTELEMETRY_OPTION_USE_STD_SPAN # include "opentelemetry/std/span.h" # endif -#endif +#endif /* OPENTELEMETRY_STL_VERSION >= 2020 */ // Fallback to `nostd::span` if necessary #if !defined(HAVE_SPAN) diff --git a/api/include/opentelemetry/nostd/type_traits.h b/api/include/opentelemetry/nostd/type_traits.h index 3d212ea3e2..709e2afb89 100644 --- a/api/include/opentelemetry/nostd/type_traits.h +++ b/api/include/opentelemetry/nostd/type_traits.h @@ -3,7 +3,7 @@ #pragma once -#ifdef HAVE_CPP_STDLIB +#if OPENTELEMETRY_STL_VERSION >= 2011 # include "opentelemetry/std/type_traits.h" #else # include @@ -154,4 +154,4 @@ struct is_trivially_move_assignable # endif } // namespace nostd OPENTELEMETRY_END_NAMESPACE -#endif +#endif /* OPENTELEMETRY_STL_VERSION >= 2011 */ diff --git a/api/include/opentelemetry/nostd/variant.h b/api/include/opentelemetry/nostd/variant.h index b6b2326998..536786bd05 100644 --- a/api/include/opentelemetry/nostd/variant.h +++ b/api/include/opentelemetry/nostd/variant.h @@ -5,7 +5,7 @@ #include "opentelemetry/version.h" -#ifdef HAVE_CPP_STDLIB +#if OPENTELEMETRY_STL_VERSION >= 2017 # include "opentelemetry/std/variant.h" #else diff --git a/api/test/nostd/span_test.cc b/api/test/nostd/span_test.cc index 98e825142d..5c13ee590e 100644 --- a/api/test/nostd/span_test.cc +++ b/api/test/nostd/span_test.cc @@ -60,11 +60,6 @@ TEST(SpanTest, PointerCountConstruction) span s2{array.data(), array.size()}; EXPECT_EQ(s2.data(), array.data()); EXPECT_EQ(s2.size(), array.size()); - -#ifndef HAVE_CPP_STDLIB - /* This test is not supposed to fail with STL. Why is this invalid construct? */ - EXPECT_DEATH((span{array.data(), array.size()}), ".*"); -#endif } TEST(SpanTest, RangeConstruction) @@ -78,11 +73,6 @@ TEST(SpanTest, RangeConstruction) span s2{std::begin(array), std::end(array)}; EXPECT_EQ(s2.data(), array); EXPECT_EQ(s2.size(), 3); - -#ifndef HAVE_CPP_STDLIB - /* This test is not supposed to fail with STL. Why is this invalid construct? */ - EXPECT_DEATH((span{std::begin(array), std::end(array)}), ".*"); -#endif } TEST(SpanTest, ArrayConstruction) @@ -122,11 +112,6 @@ TEST(SpanTest, ContainerConstruction) EXPECT_EQ(s2.data(), v.data()); EXPECT_EQ(s2.size(), v.size()); -#ifndef HAVE_CPP_STDLIB - /* This test is not supposed to fail with STL. Why is this invalid construct? */ - EXPECT_DEATH((span{v.data(), 3}), ".*"); -#endif - EXPECT_FALSE((std::is_constructible, std::vector>::value)); EXPECT_FALSE((std::is_constructible, std::list>::value)); } diff --git a/api/test/nostd/string_view_test.cc b/api/test/nostd/string_view_test.cc index fc580debc1..3db28096a7 100644 --- a/api/test/nostd/string_view_test.cc +++ b/api/test/nostd/string_view_test.cc @@ -71,7 +71,7 @@ TEST(StringViewTest, SubstrPortion) TEST(StringViewTest, SubstrOutOfRange) { string_view s = "abc123"; -#if __EXCEPTIONS || defined(HAVE_CPP_STDLIB) +#if __EXCEPTIONS || (OPENTELEMETRY_STL_VERSION >= 2020) EXPECT_THROW(s.substr(10), std::out_of_range); #else EXPECT_DEATH({ s.substr(10); }, ""); From 14bccb5b2ffabe66554b115196f129b92f426a9c Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 11 Sep 2023 17:42:04 +0200 Subject: [PATCH 05/13] build cleanup --- CMakeLists.txt | 4 +++- api/CMakeLists.txt | 18 ++++++++++++------ ext/test/http/CMakeLists.txt | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 719a7b2475..d388f30fac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,7 +115,9 @@ endif() option(WITH_NO_DEPRECATED_CODE "Do not include deprecated code" OFF) -set(WITH_STL "OFF" CACHE STRING "Which version of the Standard Library for C++ to use") +set(WITH_STL + "OFF" + CACHE STRING "Which version of the Standard Library for C++ to use") option(WITH_GSL "Whether to use Guidelines Support Library for C++ latest features" OFF) diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index de5fd09110..9e50bc51f0 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -53,23 +53,29 @@ endif() if(WITH_STL STREQUAL "OFF") message(STATUS "Building WITH_STL=OFF") - target_compile_definitions(opentelemetry_api INTERFACE OPENTELEMETRY_STL_VERSION=0) + target_compile_definitions(opentelemetry_api + INTERFACE OPENTELEMETRY_STL_VERSION=0) elseif(WITH_STL STREQUAL "CXX11") message(STATUS "Building WITH_STL=CXX1") - target_compile_definitions(opentelemetry_api INTERFACE OPENTELEMETRY_STL_VERSION=2011) + target_compile_definitions(opentelemetry_api + INTERFACE OPENTELEMETRY_STL_VERSION=2011) elseif(WITH_STL STREQUAL "CXX14") message(STATUS "Building WITH_STL=CXX14") - target_compile_definitions(opentelemetry_api INTERFACE OPENTELEMETRY_STL_VERSION=2014) + target_compile_definitions(opentelemetry_api + INTERFACE OPENTELEMETRY_STL_VERSION=2014) elseif(WITH_STL STREQUAL "CXX17") message(STATUS "Building WITH_STL=CXX17") - target_compile_definitions(opentelemetry_api INTERFACE OPENTELEMETRY_STL_VERSION=2017) + target_compile_definitions(opentelemetry_api + INTERFACE OPENTELEMETRY_STL_VERSION=2017) elseif(WITH_STL STREQUAL "CXX20") message(STATUS "Building WITH_STL=CXX20") - target_compile_definitions(opentelemetry_api INTERFACE OPENTELEMETRY_STL_VERSION=2020) + target_compile_definitions(opentelemetry_api + INTERFACE OPENTELEMETRY_STL_VERSION=2020) elseif(WITH_STL STREQUAL "ON") message(STATUS "Building WITH_STL=ON") # "ON" corresponds to "CXX20" at this time. - target_compile_definitions(opentelemetry_api INTERFACE OPENTELEMETRY_STL_VERSION=2020) + target_compile_definitions(opentelemetry_api + INTERFACE OPENTELEMETRY_STL_VERSION=2020) else() message(FATAL_ERROR "WITH_STL must be ON, OFF, CXX11, CXX14, CXX17 or CXX20") endif() diff --git a/ext/test/http/CMakeLists.txt b/ext/test/http/CMakeLists.txt index 3ce72b3b83..328f78638b 100644 --- a/ext/test/http/CMakeLists.txt +++ b/ext/test/http/CMakeLists.txt @@ -25,7 +25,7 @@ endif() set(URL_PARSER_FILENAME url_parser_test) add_executable(${URL_PARSER_FILENAME} ${URL_PARSER_FILENAME}.cc) target_link_libraries(${URL_PARSER_FILENAME} ${GTEST_BOTH_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT}) + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) gtest_add_tests( TARGET ${URL_PARSER_FILENAME} TEST_PREFIX ext.http.urlparser. From 85cb90de3a3c00abef2bc30e397f1600176453e4 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 12 Sep 2023 10:09:09 +0200 Subject: [PATCH 06/13] cleanup --- api/CMakeLists.txt | 2 -- api/include/opentelemetry/nostd/shared_ptr.h | 13 ++++--- api/include/opentelemetry/nostd/span.h | 36 ++++++++++--------- api/include/opentelemetry/nostd/string_view.h | 13 ++++--- api/include/opentelemetry/nostd/type_traits.h | 13 ++++--- api/include/opentelemetry/nostd/unique_ptr.h | 13 ++++--- api/include/opentelemetry/nostd/utility.h | 12 ++++--- api/include/opentelemetry/nostd/variant.h | 13 ++++--- api/include/opentelemetry/std/span.h | 16 ++++----- api/test/nostd/string_view_test.cc | 2 +- 10 files changed, 81 insertions(+), 52 deletions(-) diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 9e50bc51f0..208d9b4c26 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -53,8 +53,6 @@ endif() if(WITH_STL STREQUAL "OFF") message(STATUS "Building WITH_STL=OFF") - target_compile_definitions(opentelemetry_api - INTERFACE OPENTELEMETRY_STL_VERSION=0) elseif(WITH_STL STREQUAL "CXX11") message(STATUS "Building WITH_STL=CXX1") target_compile_definitions(opentelemetry_api diff --git a/api/include/opentelemetry/nostd/shared_ptr.h b/api/include/opentelemetry/nostd/shared_ptr.h index 1227df3c82..0222352030 100644 --- a/api/include/opentelemetry/nostd/shared_ptr.h +++ b/api/include/opentelemetry/nostd/shared_ptr.h @@ -3,9 +3,14 @@ #pragma once -#if OPENTELEMETRY_STL_VERSION >= 2011 -# include "opentelemetry/std/shared_ptr.h" -#else +#if defined(OPENTELEMETRY_STL_VERSION) +# if OPENTELEMETRY_STL_VERSION >= 2011 +# include "opentelemetry/std/shared_ptr.h" +# define OPENTELEMETRY_HAVE_STD_SHARED_PTR +# endif +#endif + +#if !defined(OPENTELEMETRY_HAVE_STD_SHARED_PTR) # include # include # include @@ -202,4 +207,4 @@ inline bool operator!=(std::nullptr_t, const shared_ptr &rhs) noexcept } } // namespace nostd OPENTELEMETRY_END_NAMESPACE -#endif +#endif /* OPENTELEMETRY_HAVE_STD_SHARED_PTR */ diff --git a/api/include/opentelemetry/nostd/span.h b/api/include/opentelemetry/nostd/span.h index 389e26b178..da0f385cf0 100644 --- a/api/include/opentelemetry/nostd/span.h +++ b/api/include/opentelemetry/nostd/span.h @@ -4,32 +4,34 @@ #pragma once // Try to use either `std::span` or `gsl::span` -#if OPENTELEMETRY_STL_VERSION >= 2020 -# include -# include -# include -# include +#if defined(OPENTELEMETRY_STL_VERSION) +# if OPENTELEMETRY_STL_VERSION >= 2020 +# 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(OPENTELEMETRY_OPTION_USE_STD_SPAN) && defined(_LIBCPP_VERSION) -# if _LIBCPP_VERSION <= 14000 -# define OPENTELEMETRY_OPTION_USE_STD_SPAN 0 +# if !defined(OPENTELEMETRY_OPTION_USE_STD_SPAN) && 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 -# 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 /* OPENTELEMETRY_STL_VERSION >= 2020 */ +# endif /* OPENTELEMETRY_STL_VERSION >= 2020 */ +#endif /* OPENTELEMETRY_STL_VERSION */ // Fallback to `nostd::span` if necessary -#if !defined(HAVE_SPAN) +#if !defined(OPENTELEMETRY_HAVE_SPAN) # include # include # include diff --git a/api/include/opentelemetry/nostd/string_view.h b/api/include/opentelemetry/nostd/string_view.h index 3adec00fa1..9f9fb42180 100644 --- a/api/include/opentelemetry/nostd/string_view.h +++ b/api/include/opentelemetry/nostd/string_view.h @@ -3,9 +3,14 @@ #pragma once -#if OPENTELEMETRY_STL_VERSION >= 2017 -# include "opentelemetry/std/string_view.h" -#else +#if defined(OPENTELEMETRY_STL_VERSION) +# if OPENTELEMETRY_STL_VERSION >= 2017 +# include "opentelemetry/std/string_view.h" +# define OPENTELEMETRY_HAVE_STD_STRING_VIEW +# endif +#endif + +#if !defined(OPENTELEMETRY_HAVE_STD_STRING_VIEW) # include # include # include @@ -216,4 +221,4 @@ struct hash } }; } // namespace std -#endif +#endif /* OPENTELEMETRY_HAVE_STD_STRING_VIEW */ diff --git a/api/include/opentelemetry/nostd/type_traits.h b/api/include/opentelemetry/nostd/type_traits.h index 709e2afb89..46d11c89cb 100644 --- a/api/include/opentelemetry/nostd/type_traits.h +++ b/api/include/opentelemetry/nostd/type_traits.h @@ -3,9 +3,14 @@ #pragma once -#if OPENTELEMETRY_STL_VERSION >= 2011 -# include "opentelemetry/std/type_traits.h" -#else +#if defined(OPENTELEMETRY_STL_VERSION) +# if OPENTELEMETRY_STL_VERSION >= 2011 +# include "opentelemetry/std/type_traits.h" +# define OPENTELEMETRY_HAVE_STD_TYPE_TRAITS +# endif +#endif + +#if !defined(OPENTELEMETRY_HAVE_STD_TYPE_TRAITS) # include # include @@ -154,4 +159,4 @@ struct is_trivially_move_assignable # endif } // namespace nostd OPENTELEMETRY_END_NAMESPACE -#endif /* OPENTELEMETRY_STL_VERSION >= 2011 */ +#endif /* OPENTELEMETRY_HAVE_STD_TYPE_TRAITS */ diff --git a/api/include/opentelemetry/nostd/unique_ptr.h b/api/include/opentelemetry/nostd/unique_ptr.h index 1553f31e95..f864eb4f04 100644 --- a/api/include/opentelemetry/nostd/unique_ptr.h +++ b/api/include/opentelemetry/nostd/unique_ptr.h @@ -3,9 +3,14 @@ #pragma once -#if OPENTELEMETRY_STL_VERSION >= 2011 -# include "opentelemetry/std/unique_ptr.h" -#else +#if defined(OPENTELEMETRY_STL_VERSION) +# if OPENTELEMETRY_STL_VERSION >= 2011 +# include "opentelemetry/std/unique_ptr.h" +# define OPENTELEMETRY_HAVE_STD_UNIQUE_PTR +# endif +#endif + +#if !defined(OPENTELEMETRY_HAVE_STD_UNIQUE_PTR) # include # include # include @@ -172,4 +177,4 @@ bool operator!=(std::nullptr_t, const unique_ptr &rhs) noexcept } } // namespace nostd OPENTELEMETRY_END_NAMESPACE -#endif +#endif /* OPENTELEMETRY_HAVE_STD_UNIQUE_PTR */ diff --git a/api/include/opentelemetry/nostd/utility.h b/api/include/opentelemetry/nostd/utility.h index 599db26d39..e7ad2d77f0 100644 --- a/api/include/opentelemetry/nostd/utility.h +++ b/api/include/opentelemetry/nostd/utility.h @@ -3,10 +3,14 @@ #pragma once -#if OPENTELEMETRY_STL_VERSION >= 2014 -# include "opentelemetry/std/utility.h" -#else +#if defined(OPENTELEMETRY_STL_VERSION) +# if OPENTELEMETRY_STL_VERSION >= 2014 +# include "opentelemetry/std/utility.h" +# define OPENTELEMETRY_HAVE_STD_UTILITY +# endif +#endif +#if !defined(OPENTELEMETRY_HAVE_STD_UTILITY) # include # include # include @@ -153,4 +157,4 @@ struct in_place_type_t }; } // namespace nostd OPENTELEMETRY_END_NAMESPACE -#endif +#endif /* OPENTELEMETRY_HAVE_STD_UTILITY */ diff --git a/api/include/opentelemetry/nostd/variant.h b/api/include/opentelemetry/nostd/variant.h index 536786bd05..d0b2d96001 100644 --- a/api/include/opentelemetry/nostd/variant.h +++ b/api/include/opentelemetry/nostd/variant.h @@ -5,9 +5,14 @@ #include "opentelemetry/version.h" -#if OPENTELEMETRY_STL_VERSION >= 2017 -# include "opentelemetry/std/variant.h" -#else +#if defined(OPENTELEMETRY_STL_VERSION) +# if OPENTELEMETRY_STL_VERSION >= 2017 +# include "opentelemetry/std/variant.h" +# define OPENTELEMETRY_HAVE_STD_VARIANT +# endif +#endif + +#if !defined(OPENTELEMETRY_HAVE_STD_VARIANT) # ifndef HAVE_ABSEIL // We use a LOCAL snapshot of Abseil that is known to compile with Visual Studio 2015. @@ -73,4 +78,4 @@ using absl::visit; } // namespace nostd OPENTELEMETRY_END_NAMESPACE -#endif +#endif /* OPENTELEMETRY_HAVE_STD_VARIANT */ diff --git a/api/include/opentelemetry/std/span.h b/api/include/opentelemetry/std/span.h index 5fdff57fd5..2a3dc12a84 100644 --- a/api/include/opentelemetry/std/span.h +++ b/api/include/opentelemetry/std/span.h @@ -12,18 +12,18 @@ # if __has_include() // Check for __cpp_{feature} # include # if defined(__cpp_lib_span) && __cplusplus > 201703L -# define HAVE_SPAN +# define OPENTELEMETRY_HAVE_SPAN # endif # endif -# if !defined(HAVE_SPAN) +# if !defined(OPENTELEMETRY_HAVE_SPAN) # // Check for Visual Studio span # if defined(_MSVC_LANG) && _HAS_CXX20 -# define HAVE_SPAN +# define OPENTELEMETRY_HAVE_SPAN # endif # // Check for other compiler span implementation # if !defined(_MSVC_LANG) && __has_include() && __cplusplus > 201703L // This works as long as compiler standard is set to C++20 -# define HAVE_SPAN +# define OPENTELEMETRY_HAVE_SPAN # endif # endif # if !__has_include() @@ -31,7 +31,7 @@ # endif #endif -#if !defined(HAVE_SPAN) +#if !defined(OPENTELEMETRY_HAVE_SPAN) # if defined(HAVE_GSL) # include // Guidelines Support Library provides an implementation of std::span @@ -44,12 +44,12 @@ template using span = gsl::span; } // namespace nostd OPENTELEMETRY_END_NAMESPACE -# define HAVE_SPAN +# define OPENTELEMETRY_HAVE_SPAN # else // No `gsl::span`, no `std::span`, fallback to `nostd::span` # endif -#else // HAVE_SPAN +#else // OPENTELEMETRY_HAVE_SPAN // Using std::span (https://wg21.link/P0122R7) from Standard Library available in C++20 : // - GCC libstdc++ 10+ // - Clang libc++ 7 @@ -66,4 +66,4 @@ template using span = std::span; } // namespace nostd OPENTELEMETRY_END_NAMESPACE -#endif // of HAVE_SPAN +#endif // if OPENTELEMETRY_HAVE_SPAN diff --git a/api/test/nostd/string_view_test.cc b/api/test/nostd/string_view_test.cc index 3db28096a7..52c72ea4d8 100644 --- a/api/test/nostd/string_view_test.cc +++ b/api/test/nostd/string_view_test.cc @@ -71,7 +71,7 @@ TEST(StringViewTest, SubstrPortion) TEST(StringViewTest, SubstrOutOfRange) { string_view s = "abc123"; -#if __EXCEPTIONS || (OPENTELEMETRY_STL_VERSION >= 2020) +#if __EXCEPTIONS || ((defined(OPENTELEMETRY_STL_VERSION) && (OPENTELEMETRY_STL_VERSION >= 2020))) EXPECT_THROW(s.substr(10), std::out_of_range); #else EXPECT_DEATH({ s.substr(10); }, ""); From 55777ddefdefaa71b98819be92a9800ea9349526 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 12 Sep 2023 15:17:52 +0200 Subject: [PATCH 07/13] Changelog --- CHANGELOG.md | 17 +++++++++++++++++ api/CMakeLists.txt | 10 +++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f09553ce70..28117c6241 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,23 @@ Increment the: * [DEPRECATION] Deprecate ZPAGES [#2291](https://github.com/open-telemetry/opentelemetry-cpp/pull/2291) +Breaking changes: + +* [BUILD] Need fine-grained HAVE_CPP_STDLIB + [#2304](https://github.com/open-telemetry/opentelemetry-cpp/pull/2304) + * In `CMAKE`, the boolean option `WITH_STL` as changed to an option + that accepts the values `OFF`, `ON`, `CXX11`, `CXX14`, `CXX17`, + `CXX20` and `CXX23`. + * Applications makefiles that did not set WITH_STL need to use + `WITH_STL=OFF` instead (this is the default). + * Applications makefiles that did set WITH_STL need to use + `WITH_STL=ON` instead, or may choose to pick a specific value. + * In the `API` header files, the preprocessor symbol `HAVE_CPP_STDLIB` + is no longer used. + * Applications that did set `HAVE_CPP_STDLIB` before, need to set + `OPENTELEMETRY_STL_VERSION=` instead, to build with a + specific STL version (2011, 2014, 2017, 2020, 2023). + ## [1.11.0] 2023-08-21 * [BUILD] Fix more cases for symbol name for 32-bit win32 DLL build diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 208d9b4c26..2b90011caf 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -69,13 +69,17 @@ elseif(WITH_STL STREQUAL "CXX20") message(STATUS "Building WITH_STL=CXX20") target_compile_definitions(opentelemetry_api INTERFACE OPENTELEMETRY_STL_VERSION=2020) +elseif(WITH_STL STREQUAL "CXX23") + message(STATUS "Building WITH_STL=CXX23") + target_compile_definitions(opentelemetry_api + INTERFACE OPENTELEMETRY_STL_VERSION=2023) elseif(WITH_STL STREQUAL "ON") message(STATUS "Building WITH_STL=ON") - # "ON" corresponds to "CXX20" at this time. + # "ON" corresponds to "CXX23" at this time. target_compile_definitions(opentelemetry_api - INTERFACE OPENTELEMETRY_STL_VERSION=2020) + INTERFACE OPENTELEMETRY_STL_VERSION=2023) else() - message(FATAL_ERROR "WITH_STL must be ON, OFF, CXX11, CXX14, CXX17 or CXX20") + message(FATAL_ERROR "WITH_STL must be ON, OFF, CXX11, CXX14, CXX17, CXX20 or CXX23") endif() if(WITH_GSL) From 6e829dae86e041c5dee48d2c8bf96e4cd895a9dd Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 12 Sep 2023 16:10:23 +0200 Subject: [PATCH 08/13] Added CI --- .github/workflows/ci.yml | 36 ++++++++++++++++++++++++++++++++++++ ci/do_ci.sh | 26 ++++++++++++++++++++++++++ docs/building-with-stdlib.md | 13 ++++++++++--- docs/dependencies.md | 2 +- exporters/etw/README.md | 2 +- 5 files changed, 74 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d8db91364..01ea48fb86 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -316,6 +316,42 @@ jobs: CXX: /usr/bin/g++-4.8 run: ./ci/do_ci.sh cmake.legacy.exporter.otprotocol.test + cmake_test_cxx14_gcc: + name: CMake C++14 test(GCC) + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: setup + env: + CMAKE_VERSION: 3.20.6 + run: | + sudo -E ./ci/setup_ci_environment.sh + sudo -E ./ci/setup_cmake.sh + - name: run tests (enable stl) + env: + CXX_STANDARD: '14' + run: ./ci/do_ci.sh cmake.c++14.stl.test + + cmake_test_cxx17_gcc: + name: CMake C++17 test(GCC) + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: setup + env: + CMAKE_VERSION: 3.20.6 + run: | + sudo -E ./ci/setup_ci_environment.sh + sudo -E ./ci/setup_cmake.sh + - name: run tests (enable stl) + env: + CXX_STANDARD: '17' + run: ./ci/do_ci.sh cmake.c++17.stl.test + cmake_test_cxx20_gcc: name: CMake C++20 test(GCC) runs-on: ubuntu-20.04 diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 6452faa451..04063eb6ba 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -221,6 +221,32 @@ elif [[ "$1" == "cmake.c++20.test" ]]; then eval "$MAKE_COMMAND" make test exit 0 +elif [[ "$1" == "cmake.c++14.stl.test" ]]; then + cd "${BUILD_DIR}" + rm -rf * + cmake ${CMAKE_OPTIONS[@]} \ + -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ + -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ + -DWITH_ASYNC_EXPORT_PREVIEW=ON \ + -DWITH_STL=CXX14 \ + ${IWYU} \ + "${SRC_DIR}" + eval "$MAKE_COMMAND" + make test + exit 0 +elif [[ "$1" == "cmake.c++17.stl.test" ]]; then + cd "${BUILD_DIR}" + rm -rf * + cmake ${CMAKE_OPTIONS[@]} \ + -DWITH_METRICS_EXEMPLAR_PREVIEW=ON \ + -DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \ + -DWITH_ASYNC_EXPORT_PREVIEW=ON \ + -DWITH_STL=CXX17 \ + ${IWYU} \ + "${SRC_DIR}" + eval "$MAKE_COMMAND" + make test + exit 0 elif [[ "$1" == "cmake.c++20.stl.test" ]]; then cd "${BUILD_DIR}" rm -rf * diff --git a/docs/building-with-stdlib.md b/docs/building-with-stdlib.md index a90a14a6ed..b52b58ff90 100644 --- a/docs/building-with-stdlib.md +++ b/docs/building-with-stdlib.md @@ -138,14 +138,21 @@ Visual Studio provides 1st class debug experience for the standard library. Supported build flavors: * `nostd` - OpenTelemetry backport of classes for C++11. Not using standard lib. -* `stdlib` - Standard Library. Full native experience with C++20 compiler. - C++17 works but with additional dependencies, e.g. either MS-GSL or Abseil for +* `stdlib` - Standard Library. Native experience with + C++11/C++14/C++17/C++20/C++23 compiler. + Depending on the stdlib level in effect, + C++ features are used from the standard library, + completed with `nostd` replacement implementations. + C++17 and below works but with additional dependencies, e.g. either MS-GSL or Abseil for `std::span` implementation (`gsl::span` or `absl::Span`). * `absl` - TODO: this should allow using Abseil C++ library only (no MS-GSL). Currently only `nostd` and `stdlib` configurations are implemented in CMake build. `absl` is reserved for future use. Build systems other than CMake need to -`#define HAVE_CPP_STDLIB` to enable the Standard Library classes. +`#define OPENTELEMETRY_STL_VERSION=` to enable the Standard Library classes. + +Valid values for `OPENTELEMETRY_STL_VERSION` are `2011`, `2014`, `2017`, `2020` and +`2023`. ### Build matrix diff --git a/docs/dependencies.md b/docs/dependencies.md index 62fbefc297..c8a2271ef5 100644 --- a/docs/dependencies.md +++ b/docs/dependencies.md @@ -24,7 +24,7 @@ Both these dependencies are listed here: [SDK](/sdk): - Uses Standard C++ library for latest features (std::string_view, std::variant, std::span, std::shared_ptr, std::unique_ptr) with C++14/17/20 - compiler if `WITH_STL` cmake option is enabled or `HAVE_CPP_STDLIB` macro is + compiler if cmake option `WITH_STL` is enabled or macro `OPENTELEMETRY_STL_VERSION` is defined. License: `GNU General Public License` - For C++11/14/17 compilers, fallback to gsl::span if [GSL C++ library](https://github.com/microsoft/GSL) is installed. License: `MIT diff --git a/exporters/etw/README.md b/exporters/etw/README.md index 29dc3de430..3339223fa6 100644 --- a/exporters/etw/README.md +++ b/exporters/etw/README.md @@ -121,7 +121,7 @@ compiled: | Name | Description | |---------------------|------------------------------------------------------------------------------------------------------------------------| -| HAVE_CPP_STDLIB | Use STL classes for API surface. This option requires at least C++17. C++20 is recommended. Some customers may benefit from STL library provided with the compiler instead of using custom OpenTelemetry `nostd::` implementation due to security and performance considerations. | +| OPENTELEMETRY_STL_VERSION | Use STL classes for API surface. C++20 is recommended. Some customers may benefit from STL library provided with the compiler instead of using custom OpenTelemetry `nostd::` implementation due to security and performance considerations. | | HAVE_GSL | Use [Microsoft GSL](https://github.com/microsoft/GSL) for `gsl::span` implementation. Library must be in include path. Microsoft GSL claims to be the most feature-complete implementation of `std::span`. It may be used instead of `nostd::span` implementation in projects that statically link OpenTelemetry SDK. | | HAVE_TLD | Use ETW/TraceLogging Dynamic protocol. This is the default implementation compatible with existing C# "listeners" / "decoders" of ETW events. This option requires an additional optional Microsoft MIT-licensed `TraceLoggingDynamic.h` header. | From dd3d4f1742caed0193bb8b6bebf701b984e8c6a8 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 12 Sep 2023 16:37:30 +0200 Subject: [PATCH 09/13] cleanup --- exporters/otlp/test/otlp_grpc_exporter_test.cc | 4 ++-- exporters/otlp/test/otlp_http_exporter_test.cc | 4 ++-- exporters/otlp/test/otlp_http_log_record_exporter_test.cc | 4 ++-- exporters/zipkin/test/zipkin_exporter_test.cc | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/exporters/otlp/test/otlp_grpc_exporter_test.cc b/exporters/otlp/test/otlp_grpc_exporter_test.cc index 3298e5390d..3be2bcc653 100644 --- a/exporters/otlp/test/otlp_grpc_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_exporter_test.cc @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifndef HAVE_CPP_STDLIB +#ifndef OPENTELEMETRY_STL_VERSION // Unfortunately as of 04/27/2021 the fix is NOT in the vcpkg snapshot of Google Test. // Remove above `#ifdef` once the GMock fix for C++20 is in the mainline. // @@ -284,4 +284,4 @@ TEST_F(OtlpGrpcExporterTestPeer, ConfigUnknownInsecureFromEnv) } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif +#endif /* OPENTELEMETRY_STL_VERSION */ diff --git a/exporters/otlp/test/otlp_http_exporter_test.cc b/exporters/otlp/test/otlp_http_exporter_test.cc index 2ac698b0de..42258d2b45 100644 --- a/exporters/otlp/test/otlp_http_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_test.cc @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifndef HAVE_CPP_STDLIB +#ifndef OPENTELEMETRY_STL_VERSION # include # include @@ -612,4 +612,4 @@ TEST_F(OtlpHttpExporterTestPeer, ConfigFromTracesEnv) } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif +#endif /* OPENTELEMETRY_STL_VERSION */ diff --git a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc index 4dc3b5829d..df89ca17fa 100644 --- a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifndef HAVE_CPP_STDLIB +#ifndef OPENTELEMETRY_STL_VERSION # include # include @@ -740,4 +740,4 @@ TEST_F(OtlpHttpLogRecordExporterTestPeer, DefaultEndpoint) } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif +#endif /* OPENTELEMETRY_STL_VERSION */ diff --git a/exporters/zipkin/test/zipkin_exporter_test.cc b/exporters/zipkin/test/zipkin_exporter_test.cc index fab19efb65..870ff427e9 100644 --- a/exporters/zipkin/test/zipkin_exporter_test.cc +++ b/exporters/zipkin/test/zipkin_exporter_test.cc @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#ifndef HAVE_CPP_STDLIB +#ifndef OPENTELEMETRY_STL_VERSION # include "opentelemetry/exporters/zipkin/zipkin_exporter.h" # include "opentelemetry/ext/http/client/curl/http_client_curl.h" @@ -246,4 +246,4 @@ TEST_F(ZipkinExporterTestPeer, ConfigFromEnv) } // namespace zipkin } // namespace exporter OPENTELEMETRY_END_NAMESPACE -#endif // HAVE_CPP_STDLIB +#endif /* OPENTELEMETRY_STL_VERSION */ From af8fd0f1a9e6a9a7344f89e9260747f06b63c314 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 12 Sep 2023 16:47:24 +0200 Subject: [PATCH 10/13] format --- api/CMakeLists.txt | 3 ++- docs/building-with-stdlib.md | 7 ++++--- docs/dependencies.md | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 2b90011caf..88f98591ca 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -79,7 +79,8 @@ elseif(WITH_STL STREQUAL "ON") target_compile_definitions(opentelemetry_api INTERFACE OPENTELEMETRY_STL_VERSION=2023) else() - message(FATAL_ERROR "WITH_STL must be ON, OFF, CXX11, CXX14, CXX17, CXX20 or CXX23") + message( + FATAL_ERROR "WITH_STL must be ON, OFF, CXX11, CXX14, CXX17, CXX20 or CXX23") endif() if(WITH_GSL) diff --git a/docs/building-with-stdlib.md b/docs/building-with-stdlib.md index b52b58ff90..d9c73073da 100644 --- a/docs/building-with-stdlib.md +++ b/docs/building-with-stdlib.md @@ -138,12 +138,13 @@ Visual Studio provides 1st class debug experience for the standard library. Supported build flavors: * `nostd` - OpenTelemetry backport of classes for C++11. Not using standard lib. -* `stdlib` - Standard Library. Native experience with - C++11/C++14/C++17/C++20/C++23 compiler. +* `stdlib` - Standard Library. + Native experience with C++11/C++14/C++17/C++20/C++23 compiler. Depending on the stdlib level in effect, C++ features are used from the standard library, completed with `nostd` replacement implementations. - C++17 and below works but with additional dependencies, e.g. either MS-GSL or Abseil for + C++17 and below works but with additional dependencies, + e.g. either MS-GSL or Abseil for `std::span` implementation (`gsl::span` or `absl::Span`). * `absl` - TODO: this should allow using Abseil C++ library only (no MS-GSL). diff --git a/docs/dependencies.md b/docs/dependencies.md index c8a2271ef5..d0dc09c54f 100644 --- a/docs/dependencies.md +++ b/docs/dependencies.md @@ -24,8 +24,9 @@ Both these dependencies are listed here: [SDK](/sdk): - Uses Standard C++ library for latest features (std::string_view, std::variant, std::span, std::shared_ptr, std::unique_ptr) with C++14/17/20 - compiler if cmake option `WITH_STL` is enabled or macro `OPENTELEMETRY_STL_VERSION` is - defined. License: `GNU General Public License` + compiler if cmake option `WITH_STL` is enabled + or macro `OPENTELEMETRY_STL_VERSION` is defined. + License: `GNU General Public License` - For C++11/14/17 compilers, fallback to gsl::span if [GSL C++ library](https://github.com/microsoft/GSL) is installed. License: `MIT License` From 7d03b8a6bb2adfa47645abc71d9a216a9b233525 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 12 Sep 2023 20:37:33 +0200 Subject: [PATCH 11/13] Improve changelog. --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28117c6241..5ff963b08e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,12 @@ Breaking changes: * Applications that did set `HAVE_CPP_STDLIB` before, need to set `OPENTELEMETRY_STL_VERSION=` instead, to build with a specific STL version (2011, 2014, 2017, 2020, 2023). + * The opentrelemetry-cpp makefile no longer sets + CMAKE_CXX_STANDARD by itself. + Instead, the CMAKE_CXX_STANDARD and/or compiler options -stdc++ used + by the caller are honored. + * Applications that set neither CMAKE_CXX_STANDARD nor -stdc++ + options may need to provide a C++ standard in their makefiles. ## [1.11.0] 2023-08-21 From 664a1ba2ae75f6f654e44e091f2241123e4f5c57 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 28 Sep 2023 08:59:28 +0200 Subject: [PATCH 12/13] Update api/CMakeLists.txt Co-authored-by: Lalit Kumar Bhasin --- api/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 5d3b3e18f2..dd1eda3c78 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -54,7 +54,7 @@ endif() if(WITH_STL STREQUAL "OFF") message(STATUS "Building WITH_STL=OFF") elseif(WITH_STL STREQUAL "CXX11") - message(STATUS "Building WITH_STL=CXX1") + message(STATUS "Building WITH_STL=CXX11") target_compile_definitions(opentelemetry_api INTERFACE OPENTELEMETRY_STL_VERSION=2011) elseif(WITH_STL STREQUAL "CXX14") From 037bc3141cc69820f0775a60d547f75e37065466 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 28 Sep 2023 08:59:40 +0200 Subject: [PATCH 13/13] Update CHANGELOG.md Co-authored-by: Lalit Kumar Bhasin --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 762b71904d..b349ba8ec7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,7 +40,7 @@ Breaking changes: * Applications that did set `HAVE_CPP_STDLIB` before, need to set `OPENTELEMETRY_STL_VERSION=` instead, to build with a specific STL version (2011, 2014, 2017, 2020, 2023). - * The opentrelemetry-cpp makefile no longer sets + * The opentelemetry-cpp makefile no longer sets CMAKE_CXX_STANDARD by itself. Instead, the CMAKE_CXX_STANDARD and/or compiler options -stdc++ used by the caller are honored.