Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

importing gsl::span if std::span is not available #1167

Conversation

esigo
Copy link
Member

@esigo esigo commented Jan 3, 2022

Fixes #813 (issue)

Changes

If the WITH_STL cmake option is enabled, the build will use std::span if available (for C++20), and fall back to nostd::span instead of gsl::span (or perhaps fail the build). Uses gsl::span only if explicitly specified the WITH_GSL build option.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@codecov
Copy link

codecov bot commented Jan 3, 2022

Codecov Report

Merging #1167 (7350a45) into main (2a821fd) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1167   +/-   ##
=======================================
  Coverage   93.29%   93.29%           
=======================================
  Files         174      174           
  Lines        6404     6404           
=======================================
  Hits         5974     5974           
  Misses        430      430           
Impacted Files Coverage Δ
...k/instrumentationlibrary/instrumentation_library.h 100.00% <ø> (ø)

@esigo esigo marked this pull request as ready for review January 11, 2022 18:46
@esigo esigo requested a review from a team January 11, 2022 18:46
@@ -11,7 +11,7 @@
#if defined __has_include
# if __has_include(<version>) // Check for __cpp_{feature}
# include <version>
# if defined(__cpp_lib_span)
# if defined(__cpp_lib_span) && __cplusplus > 201703L
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this check required?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because __cpp_lib_span is defined for C++17 on g++-10:g++-10 (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0.
I use these CMake options for build:
-DCMAKE_CXX_COMPILER=g++-10 -DCMAKE_CXX_STANDARD=17

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which should be ok right? If the HAVE_CPP_STDLIB option is specified, and the standard library provides the implementation ( stable or experimental) it should get selected. What is the behavior now with these changes on g++-10/C++17 - compilation failure as std::span is not available?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior for g++-10/C++17 is that nostd::span will be picked if the WITH_GSL option was not used. I think we shouldn't use std::span if the user explicitly asks for C++17.
Shall I enable std::span if C++17 was used and std::span is available?

@@ -165,6 +155,20 @@ if(WITH_STL)
endif()
endif()

if(WITH_GSL)
add_definitions(-DHAVE_GSL)
Copy link
Member

@lalitb lalitb Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify- with this PR, GSL library will only be used if the WITH_GSL flag is enabled?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it is enabled only when the user explicitly asks for it.

Copy link
Member

@lalitb lalitb Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I was thinking about this part in cmake:

if(WITH_STL)
message("Building with standard library types...")
target_compile_definitions(opentelemetry_api INTERFACE HAVE_CPP_STDLIB
HAVE_GSL)

As it looks we are enabling HAVE_GSL macro with WITH_STL option, which would mean try using gsl::span from submodule if STL doesn't have std::span implementation.

Copy link
Member Author

@esigo esigo Jan 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is covered in

# if !__has_include(<gsl/gsl>)
# undef HAVE_GSL
# endif
as the header is not available when the WITH_GSL is off.
We shouldn't define it though, I cleaned it from the CMake file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks for the clarification.

Copy link
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a minor suggestion.

@lalitb lalitb merged commit a605fd9 into open-telemetry:main Jan 25, 2022
@esigo esigo deleted the importing-gsl--span-if-std--span-is-not-available-and-WITH_GSL-is-on branch February 22, 2022 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WITH_STL shouldn't try importing gsl::span if std::span is not available.
2 participants