Skip to content

Conversation

@maxgolov
Copy link
Contributor

@maxgolov maxgolov commented Feb 5, 2021

Fixes #314 . It does not yet add the build system for supporting vs2015 builds in CI, as it is quite involved (there is no GitHub Actions runner with preinstalled vs2015 and installing one may need some tweaking, and IS SLOW.. unless we cache some docker container image for that). Best we can do is deploy additional vs2015 community build tools. I'll cover CI for vs2015 in a separate PR. I verified the code locally with ETW exporter on Windows with Visual Studio 2015 - Update 2. It compiles and works well.

Changes

  • MPark variant that we use in the SDK is NOT compiling with Visual Studio 2015. Abseil Variant is compiling and working well with Visual Studio 2015 Update 2+. This visual studio version requirement is coming from Abseil itself, but it's a reasonable requirement. The solution is to add a build option HAVE_ABSEIL_VARIANT to compile with that one instead of MPark variant.

  • Visual Studio 2015 secure development practices does not like std::copy and breaks the build. The fix is to replace the std::copy with bounds-checked implementation that uses for-loop

  • Visual Studio 2015 does not like passing context by value. There is a build error related to alignment. Passing by const reference works.

I manually verified that the code compiles and works in Visual Studio 2015 with ETW exporter. I will cover full CI and other exporters (OTLP, Elastic, etc.) in a follow-up PR that would add Visual Studio 2015 to build loop.

@maxgolov maxgolov requested a review from a team February 5, 2021 21:39
@codecov
Copy link

codecov bot commented Feb 5, 2021

Codecov Report

Merging #565 (bb8b3f6) into main (25a7178) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #565      +/-   ##
==========================================
+ Coverage   94.39%   94.43%   +0.03%     
==========================================
  Files         200      200              
  Lines        9067     9068       +1     
==========================================
+ Hits         8559     8563       +4     
+ Misses        508      505       -3     
Impacted Files Coverage Δ
api/include/opentelemetry/context/context.h 100.00% <100.00%> (ø)
...pi/include/opentelemetry/context/runtime_context.h 97.46% <100.00%> (+0.03%) ⬆️
sdk/test/common/circular_buffer_test.cc 100.00% <0.00%> (+1.04%) ⬆️
sdk/src/logs/batch_log_processor.cc 95.06% <0.00%> (+1.23%) ⬆️
sdk/test/metrics/counter_aggregator_test.cc 100.00% <0.00%> (+1.78%) ⬆️

if (base_ != nullptr)
{
std::copy(base_, base_ + old_size, temp);
// vs2015 does not like this construct considering it unsafe:
Copy link
Contributor

Choose a reason for hiding this comment

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

Check Visual Studio 2015 compiler like via _MSC_VER to separate the workaround for it?

Copy link
Contributor Author

@maxgolov maxgolov Feb 9, 2021

Choose a reason for hiding this comment

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

Does std::copy itself perform a bounds checking? i.e. what if new temp size - new_capacity is less than the old capacity? Since it's a raw pointer, I think the old code had a problem: it was copying beyond the allocated buffer, buffer overflow.

Comment on lines +5 to +7
This code is required to compile OpenTelemetry code in vs2015 because MPark Variant implementation is not compatible with vs2015.

Build option `HAVE_ABSEIL_VARIANT` allows to enable the build with `absl::variant`, `absl::get` and `absl::visit` as defalt implementation for `nostd::` classes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we have to ship two variant implementations? If absl is needed for VS2015 (and we decide we want to support that), can't we just generally use the absl implementation (instead of the MPark one)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to take a two-staged approach. We should use Abseil everywhere, but I'd like to keep it under the build option right now until I fully test all existing exporters with it. Within the same OS class the ABI compatibility is retained irrespective of what implementation we take, e.g. Mpark works for Linux and Mac no problem. Whereas Abseil works for Windows. I want to send a follow-up PR that adds a build loop for Windows to switch over to Abseil for Variant. Then we can do this for Linux and Mac.

Copy link
Contributor Author

@maxgolov maxgolov Feb 9, 2021

Choose a reason for hiding this comment

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

I think long-term before v1.0 GA we should switch to Abseil for variant. That'd be great for another reason: we can get rid of Boost license in our list of licenses because only MPark variant is Boost-licensed, whereas Abseil is also Apache License v2.0 as the rest of code. But I'd like to do this switch in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#68

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#68

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. Can you add an additional issue for this (apart from the license one), otherwise this might be lost when just looking at issue titles.

I'd be fine with switching to absl as default, having MPark under a switch (then our CI pipeline would verify how it's working). However, I assume you expect changes to be necessary for it to work on Linux.

Copy link
Member

Choose a reason for hiding this comment

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

Have created an issue for this #572 , and assigned to @maxgolov . Feel free to update with relevant details on it.

Copy link
Contributor

@pyohannes pyohannes left a comment

Choose a reason for hiding this comment

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

Approved, provided we work toward getting rid of the MPark variant implementation.

@lalitb lalitb merged commit 18e8d9f into main Feb 10, 2021
@lalitb lalitb deleted the maxgolov/vs2015_support branch February 10, 2021 07:24
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.

context::ContextValue cannot be compiled with Visual Studio 2015

5 participants