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

If nlohmann_json is missing in customer's build system, then install it from submodule #870

Merged
merged 11 commits into from
Jun 22, 2021

Conversation

maxgolov
Copy link
Contributor

@maxgolov maxgolov commented Jun 21, 2021

Fixes #843

Problem Description

Previous fix ( #865 ) works well for Linux and Mac. But missed one important detail for Windows: nlohmann::json package is unconditionally required by ETW exporter on Windows, because json.hpp header is included in public ETW exporter headers. And because it is added as INTERFACE package. When it is added as INTERFACE (not PRIVATE), means it must to be installed on customer machine into CMake cache. Otherwise CMake won't let the build to proceed. Actually the same is true for zPages, but for zPages we just did not enforce it via target_link_libraries ... INTERFACE nlohmann_json - so it was "passing" without a hard-check.

There are at least two workarounds available:

  • use vcpkg install nlohmann_json to install the package before the buiild ; OR
  • pass -DJSON_Install=ON to CMake when compiling for Windows. That'll install the nlohmann_json before building the rest of code.

With the fix, the workaround of passing -DJSON_Install=ON is no longer needed.

Changes

If nlohmann::json is not installed on customer system, then we use our instance of it from our submodule. And we install it. Because it is unconditionally required by ETW exporter, zPages, both part of default build. I also improved the logic to check that submodule directory exists. We discussed it in a previous related PR. If submodule does not exist and the package is not installed from elsewhere, then the build fails with a recommendation / instructions how to fix it by recursively cloning with submodules :

image

Customer reporting the issue confirmed that the fix / idea behind the fix is working well:

image

UPDATE: also when we package the source tarball, allow the API-only build to avoid including nlohmann_jsonhpp library.

@maxgolov maxgolov requested a review from a team June 21, 2021 17:42
@codecov
Copy link

codecov bot commented Jun 21, 2021

Codecov Report

Merging #870 (8c8c960) into main (c0b459e) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #870   +/-   ##
=======================================
  Coverage   95.50%   95.50%           
=======================================
  Files         156      156           
  Lines        6620     6620           
=======================================
  Hits         6322     6322           
  Misses        298      298           

CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
${PROJECT_SOURCE_DIR}/third_party/nlohmann-json/single_include)
else()
message("Using external nlohmann::json")
if(NOT WITH_API_ONLY)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lidavidm - I hope that should fix the build for API-only build.

Copy link
Contributor

Choose a reason for hiding this comment

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

I can confirm this fixes the API-only build, thanks!

It would be nice if we could still build the rest of the library that doesn't require json without this dependency, though (e.g. the SDK), though I can understand if that would get complicated.

Copy link
Contributor Author

@maxgolov maxgolov Jun 21, 2021

Choose a reason for hiding this comment

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

@lidavidm - it happens that in the majority of cases (80% scenarios I'd say), we do actually require nlohmann/json.hpp, e.g. for ETW on Windows, for zPages (internal monitor of SDK statistics), for Zipkin exporter, as well as for OTLP-HTTP exporter. Plus for all tests, and generally for examples too.

Since we got you covered well - the case when the build is done only for API and nothing else, json is now optional for that scenario.. I think it's gonna be too much of a hassle to make json optional for the rest. As you noticed, it gets complicated - given that most components require it. And we give two alternatives - either consume json library from user-provided deps. Or use the one we cloned from recursive submodules, both options now work cross-plat.

We can probably consider further improvements in a follow-up PR? But as low priority. Since all immediate scenarios have been addressed.

Copy link
Member

Choose a reason for hiding this comment

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

I agree on having further cleanup in a follow-up PR. I think the most common usage scenario would be instrumentation libraries devs using otel-cpp api, and application developers using otel-gRPC exporter. And both these scenarios don't depend on JSON and so shouldn't fail. Though I do see the hassle involved here to work it cross-platform.

Thanks for fixing the API only build :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lalitb - My worry is that OTLP-HTTP exporter may also be common. This one does require JSON. Same as Zipkin. Also I think the zPages project is kinda common across all languages. The idea is we use zPages for debugging OpenTelemetry in-proc.. that build flavor of final SDK dll / shared object bit, with zPages in it, would require json.hpp

While I agree we may not need it for OTLP-gRPC only build without zPages, in most other configurations we end up needing json.hpp anyways.

Copy link
Contributor

Choose a reason for hiding this comment

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

I totally understand. I think the biggest thing is just that the release tarballs don't include the submodules, but that's a Github issue.

@lalitb lalitb merged commit 2fd7bd2 into main Jun 22, 2021
@lalitb lalitb deleted the maxgolov/json_win32_fix branch June 22, 2021 05:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants