Skip to content

Commit

Permalink
Fix compatibility when using clang and libc++ (#1852)
Browse files Browse the repository at this point in the history
  • Loading branch information
owent authored Dec 13, 2022
1 parent 9f333ff commit dfff693
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 53 deletions.
144 changes: 109 additions & 35 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ jobs:
with:
submodules: 'recursive'
- name: setup
env:
CC: /usr/bin/gcc-10
CXX: /usr/bin/g++-10
run: |
sudo CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ./ci/setup_cmake.sh
sudo CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ./ci/setup_ci_environment.sh
sudo -E ./ci/setup_cmake.sh
sudo -E ./ci/setup_ci_environment.sh
- name: run cmake tests (without otlp-exporter)
env:
CC: /usr/bin/gcc-10
CXX: /usr/bin/g++-10
run: |
sudo CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ./ci/setup_thrift.sh
CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ./ci/do_ci.sh cmake.test
sudo -E ./ci/setup_thrift.sh
./ci/do_ci.sh cmake.test
cmake_gcc_maintainer_test:
name: CMake gcc 12 (maintainer mode)
Expand All @@ -31,13 +37,20 @@ jobs:
with:
submodules: 'recursive'
- name: setup
env:
CC: /usr/bin/gcc-12
CXX: /usr/bin/g++-12
GOOGLETEST_VERSION: 1.12.1
run: |
sudo CC=/usr/bin/gcc-12 CXX=/usr/bin/g++-12 GOOGLETEST_VERSION=1.12.1 ./ci/setup_cmake.sh
sudo CC=/usr/bin/gcc-12 CXX=/usr/bin/g++-12 ./ci/setup_ci_environment.sh
sudo -E ./ci/setup_cmake.sh
sudo -E ./ci/setup_ci_environment.sh
- name: run cmake gcc (maintainer mode)
env:
CC: /usr/bin/gcc-12
CXX: /usr/bin/g++-12
run: |
sudo CC=/usr/bin/gcc-12 CXX=/usr/bin/g++-12 ./ci/setup_thrift.sh
CC=/usr/bin/gcc-12 CXX=/usr/bin/g++-12 ./ci/do_ci.sh cmake.maintainer.test
sudo -E ./ci/setup_thrift.sh
./ci/do_ci.sh cmake.maintainer.test
cmake_clang_maintainer_test:
name: CMake clang 14 (maintainer mode)
Expand All @@ -47,13 +60,20 @@ jobs:
with:
submodules: 'recursive'
- name: setup
env:
CC: /usr/bin/clang-14
CXX: /usr/bin/clang++-14
GOOGLETEST_VERSION: 1.12.1
run: |
sudo CC=/usr/bin/clang-14 CXX=/usr/bin/clang++-14 GOOGLETEST_VERSION=1.12.1 ./ci/setup_cmake.sh
sudo CC=/usr/bin/clang-14 CXX=/usr/bin/clang++-14 ./ci/setup_ci_environment.sh
sudo -E ./ci/setup_cmake.sh
sudo -E ./ci/setup_ci_environment.sh
- name: run cmake clang (maintainer mode)
env:
CC: /usr/bin/clang-14
CXX: /usr/bin/clang++-14
run: |
sudo CC=/usr/bin/clang-14 CXX=/usr/bin/clang++-14 ./ci/setup_thrift.sh
CC=/usr/bin/clang-14 CXX=/usr/bin/clang++-14 ./ci/do_ci.sh cmake.maintainer.test
sudo -E ./ci/setup_thrift.sh
./ci/do_ci.sh cmake.maintainer.test
cmake_msvc_maintainer_test:
name: CMake msvc (maintainer mode)
Expand All @@ -77,13 +97,19 @@ jobs:
with:
submodules: 'recursive'
- name: setup
env:
CC: /usr/bin/gcc-10
CXX: /usr/bin/g++-10
run: |
sudo CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ./ci/setup_cmake.sh
sudo CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ./ci/setup_ci_environment.sh
sudo -E ./ci/setup_cmake.sh
sudo -E ./ci/setup_ci_environment.sh
- name: run cmake tests (without otlp-exporter)
env:
CC: /usr/bin/gcc-10
CXX: /usr/bin/g++-10
run: |
sudo CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ./ci/setup_thrift.sh
CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ./ci/do_ci.sh cmake.with_async_export.test
sudo -E ./ci/setup_thrift.sh
./ci/do_ci.sh cmake.with_async_export.test
cmake_absel_stl_test:
name: CMake test (with abseil)
Expand Down Expand Up @@ -113,13 +139,16 @@ jobs:
sudo ./ci/setup_ci_environment.sh
sudo ./ci/install_gcc48.sh
- name: setup cmake
run: |
sudo CC=/usr/bin/gcc-4.8 CXX=/usr/bin/g++-4.8 ./ci/setup_cmake.sh
env:
CC: /usr/bin/gcc-4.8
CXX: /usr/bin/g++-4.8
GOOGLETEST_VERSION: "1.10.0"
run: sudo -E ./ci/setup_cmake.sh
- name: run tests
run: ./ci/do_ci.sh cmake.legacy.test
env:
CC: /usr/bin/gcc-4.8
CXX: /usr/bin/g++-4.8
run: ./ci/do_ci.sh cmake.legacy.test

cmake_gcc_48_otlp_exporter_test:
name: CMake gcc 4.8 (with otlp exporter)
Expand All @@ -132,34 +161,67 @@ jobs:
run: |
sudo ./ci/setup_ci_environment.sh
sudo ./ci/install_gcc48.sh
- name: setup cmake
run: |
sudo CC=/usr/bin/gcc-4.8 CXX=/usr/bin/g++-4.8 ./ci/setup_cmake.sh
- name: setup grpc
- name: setup cmake and grpc
env:
CC: /usr/bin/gcc-4.8
CXX: /usr/bin/g++-4.8
GOOGLETEST_VERSION: "1.10.0"
run: |
sudo CC=/usr/bin/gcc-4.8 CXX=/usr/bin/g++-4.8 ./ci/setup_grpc.sh -v 4.8
sudo -E ./ci/setup_cmake.sh
sudo -E ./ci/setup_grpc.sh -v 4.8
- name: run tests
run: ./ci/do_ci.sh cmake.legacy.exporter.otprotocol.test
env:
CC: /usr/bin/gcc-4.8
CXX: /usr/bin/g++-4.8
run: ./ci/do_ci.sh cmake.legacy.exporter.otprotocol.test

cmake_test_cxx20:
name: CMake C++20 test
cmake_test_cxx20_gcc:
name: CMake C++20 test(GCC)
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
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
run: ./ci/do_ci.sh cmake.c++20.test
- name: run tests (enable stl)
run: ./ci/do_ci.sh cmake.c++20.stl.test

cmake_test_cxx20_clang:
name: CMake C++20 test(Clang with libc++)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: setup
env:
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
- name: run tests
env:
CC: /usr/bin/clang
CXX: /usr/bin/clang++
CXXFLAGS: "-stdlib=libc++"
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++"
run: ./ci/do_ci.sh cmake.c++20.stl.test

cmake_otprotocol_test:
name: CMake test (with otlp-exporter)
runs-on: ubuntu-20.04
Expand All @@ -184,11 +246,17 @@ jobs:
with:
submodules: 'recursive'
- name: setup
env:
CC: /usr/bin/gcc-10
CXX: /usr/bin/g++-10
run: |
sudo CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ./ci/setup_cmake.sh
sudo CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ./ci/setup_ci_environment.sh
sudo -E ./ci/setup_cmake.sh
sudo -E ./ci/setup_ci_environment.sh
- name: run tests
run: CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ./ci/do_ci.sh cmake.test_example_plugin
env:
CC: /usr/bin/gcc-10
CXX: /usr/bin/g++-10
run: ./ci/do_ci.sh cmake.test_example_plugin

bazel_test:
name: Bazel
Expand Down Expand Up @@ -492,11 +560,17 @@ jobs:
with:
submodules: 'recursive'
- name: setup
env:
CC: /usr/bin/gcc-10
CXX: /usr/bin/g++-10
run: |
sudo CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ./ci/setup_cmake.sh
sudo CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ./ci/setup_ci_environment.sh
sudo -E ./ci/setup_cmake.sh
sudo -E ./ci/setup_ci_environment.sh
- name: run tests and generate report
run: CC=/usr/bin/gcc-10 CXX=/usr/bin/g++-10 ./ci/do_ci.sh code.coverage
env:
CC: /usr/bin/gcc-10
CXX: /usr/bin/g++-10
run: ./ci/do_ci.sh code.coverage
- name: upload report
uses: codecov/codecov-action@v3
with:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Increment the:
## [Unreleased]

* [BUILD] Fix OTELCPP_MAINTAINER_MODE [#1844](https://github.com/open-telemetry/opentelemetry-cpp/pull/1844)
* [BUILD] Fix compatibility when using clang and libc++, upgrade GTest and
cmake when using C++20 [#1852](https://github.com/open-telemetry/opentelemetry-cpp/pull/1852)
* [SEMANTIC CONVENTIONS] Upgrade to version 1.16.0
[#1854](https://github.com/open-telemetry/opentelemetry-cpp/pull/1854)

Expand Down
22 changes: 21 additions & 1 deletion api/include/opentelemetry/nostd/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,27 @@

// Try to use either `std::span` or `gsl::span`
#ifdef HAVE_CPP_STDLIB
# include "opentelemetry/std/span.h"
# include <array>
# include <cstddef>
# include <iterator>
# include <type_traits>

/**
* @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
# 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
Expand Down
5 changes: 5 additions & 0 deletions api/test/common/spinlock_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ static void BM_ProcYieldSpinLockThrashing(benchmark::State &s)
// SpinLock thrashing with thread::yield().
static void BM_ThreadYieldSpinLockThrashing(benchmark::State &s)
{
#if defined(__cpp_lib_atomic_value_initialization) && \
__cpp_lib_atomic_value_initialization >= 201911L
std::atomic_flag mutex{};
#else
std::atomic_flag mutex = ATOMIC_FLAG_INIT;
#endif
SpinThrash<std::atomic_flag>(
s, mutex,
[](std::atomic_flag &l) {
Expand Down
20 changes: 9 additions & 11 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ if [[ "$1" == "cmake.test" ]]; then
-DWITH_ELASTICSEARCH=ON \
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON \
-DWITH_LOGS_PREVIEW=ON \
-DCMAKE_CXX_FLAGS="-Werror" \
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
"${SRC_DIR}"
make
make test
Expand Down Expand Up @@ -117,7 +117,7 @@ elif [[ "$1" == "cmake.with_async_export.test" ]]; then
-DWITH_ELASTICSEARCH=ON \
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON \
-DWITH_LOGS_PREVIEW=ON \
-DCMAKE_CXX_FLAGS="-Werror" \
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
"${SRC_DIR}"
make
Expand All @@ -129,7 +129,7 @@ elif [[ "$1" == "cmake.abseil.test" ]]; then
cmake -DCMAKE_BUILD_TYPE=Debug \
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON \
-DWITH_LOGS_PREVIEW=ON \
-DCMAKE_CXX_FLAGS="-Werror" \
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
-DWITH_ABSEIL=ON \
"${SRC_DIR}"
Expand All @@ -140,7 +140,7 @@ elif [[ "$1" == "cmake.c++20.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS="-Werror" \
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
-DCMAKE_CXX_STANDARD=20 \
"${SRC_DIR}"
Expand All @@ -153,7 +153,7 @@ elif [[ "$1" == "cmake.c++20.stl.test" ]]; then
cmake -DCMAKE_BUILD_TYPE=Debug \
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON \
-DWITH_LOGS_PREVIEW=ON \
-DCMAKE_CXX_FLAGS="-Werror" \
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
-DWITH_STL=ON \
"${SRC_DIR}"
Expand All @@ -164,10 +164,9 @@ elif [[ "$1" == "cmake.legacy.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
export BUILD_ROOT="${BUILD_DIR}"
${SRC_DIR}/tools/build-gtest.sh
${SRC_DIR}/tools/build-benchmark.sh
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS="-Werror" \
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
-DCMAKE_CXX_STANDARD=11 \
"${SRC_DIR}"
make
Expand All @@ -177,7 +176,6 @@ elif [[ "$1" == "cmake.legacy.exporter.otprotocol.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
export BUILD_ROOT="${BUILD_DIR}"
${SRC_DIR}/tools/build-gtest.sh
${SRC_DIR}/tools/build-benchmark.sh
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_STANDARD=11 \
Expand Down Expand Up @@ -237,7 +235,7 @@ EOF
-Wl,--version-script=${PWD}/export.map \
"
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS="-Werror" \
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
-DCMAKE_EXE_LINKER_FLAGS="$LINKER_FLAGS" \
-DCMAKE_SHARED_LINKER_FLAGS="$LINKER_FLAGS" \
"${SRC_DIR}"
Expand All @@ -248,7 +246,7 @@ EOF
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS="-Werror" \
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
"${SRC_DIR}"
make load_plugin_example
examples/plugin/load/load_plugin_example ${PLUGIN_DIR}/libexample_plugin.so /dev/null
Expand Down Expand Up @@ -331,7 +329,7 @@ elif [[ "$1" == "code.coverage" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS="-Werror --coverage" \
-DCMAKE_CXX_FLAGS="-Werror --coverage $CXXFLAGS" \
"${SRC_DIR}"
make
make test
Expand Down
2 changes: 1 addition & 1 deletion ci/setup_cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if [ "x$CMAKE_VERSION" = "x" ]; then
fi

if [ "x$GOOGLETEST_VERSION" = "x" ]; then
export GOOGLETEST_VERSION=1.10.0
export GOOGLETEST_VERSION=1.12.1
fi

cmake_install() {
Expand Down
Loading

0 comments on commit dfff693

Please sign in to comment.