Skip to content

Commit 5592cf7

Browse files
lidavidmkou
authored andcommitted
ARROW-15066: [C++] Enable use of non-bundled OpenTelemetry
This is intended to make usage a little easier by enabling you to use a pre-built package instead of having to compile it from source. Changes: - Factor nlohmann_json out so that it can also be found in the environment instead of having to be built - Call find_curl since OpenTelemetry's CMake files do not do so Closes #11963 from lidavidm/arrow-15066 Authored-by: David Li <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
1 parent dc2e0b2 commit 5592cf7

8 files changed

Lines changed: 49 additions & 33 deletions

‎ci/docker/debian-10-cpp.dockerfile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ RUN apt-get update -y -q && \
6262
llvm-${llvm}-dev \
6363
make \
6464
ninja-build \
65+
nlohmann-json3-dev \
6566
pkg-config \
6667
protobuf-compiler \
6768
python3-pip \

‎ci/docker/debian-11-cpp.dockerfile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ RUN apt-get update -y -q && \
6161
llvm-${llvm}-dev \
6262
make \
6363
ninja-build \
64+
nlohmann-json3-dev \
6465
pkg-config \
6566
protobuf-compiler-grpc \
6667
python3-pip \

‎ci/docker/fedora-33-cpp.dockerfile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ RUN dnf update -y && \
4444
gtest-devel \
4545
java-latest-openjdk-devel \
4646
java-latest-openjdk-headless \
47+
json-devel \
4748
libzstd-devel \
4849
llvm-devel \
4950
llvm-static \

‎ci/docker/ubuntu-20.04-cpp.dockerfile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ RUN apt-get update -y -q && \
9393
libzstd-dev \
9494
make \
9595
ninja-build \
96+
nlohmann-json3-dev \
9697
pkg-config \
9798
protobuf-compiler \
9899
python3-pip \

‎ci/docker/ubuntu-20.04-verify-rc.dockerfile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ RUN apt-get update -y -q && \
3434
llvm-dev \
3535
maven \
3636
ninja-build \
37+
nlohmann-json3-dev \
3738
openjdk-11-jdk \
3839
pkg-config \
3940
python3-dev \

‎ci/docker/ubuntu-21.04-cpp.dockerfile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ RUN apt-get update -y -q && \
9292
libzstd-dev \
9393
make \
9494
ninja-build \
95+
nlohmann-json3-dev \
9596
pkg-config \
9697
protobuf-compiler \
9798
protobuf-compiler-grpc \

‎ci/scripts/msys2_setup.sh‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ case "${target}" in
4141
packages+=(${MINGW_PACKAGE_PREFIX}-make)
4242
packages+=(${MINGW_PACKAGE_PREFIX}-mlir)
4343
packages+=(${MINGW_PACKAGE_PREFIX}-ninja)
44+
packages+=(${MINGW_PACKAGE_PREFIX}-nlohmann-json)
4445
packages+=(${MINGW_PACKAGE_PREFIX}-polly)
4546
packages+=(${MINGW_PACKAGE_PREFIX}-protobuf)
4647
packages+=(${MINGW_PACKAGE_PREFIX}-python3-numpy)
@@ -67,7 +68,7 @@ case "${target}" in
6768
packages+=(${MINGW_PACKAGE_PREFIX}-gcc)
6869
packages+=(${MINGW_PACKAGE_PREFIX}-go)
6970
packages+=(${MINGW_PACKAGE_PREFIX}-toolchain)
70-
packages+=(base-devel)
71+
packages+=(base-devel)
7172
;;
7273
esac
7374

‎cpp/cmake_modules/ThirdpartyToolchain.cmake‎

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ set(ARROW_THIRDPARTY_DEPENDENCIES
6363
GTest
6464
LLVM
6565
Lz4
66+
nlohmann_json
6667
opentelemetry-cpp
6768
ORC
6869
re2
@@ -162,6 +163,8 @@ macro(build_dependency DEPENDENCY_NAME)
162163
build_gtest()
163164
elseif("${DEPENDENCY_NAME}" STREQUAL "Lz4")
164165
build_lz4()
166+
elseif("${DEPENDENCY_NAME}" STREQUAL "nlohmann_json")
167+
build_nlohmann_json()
165168
elseif("${DEPENDENCY_NAME}" STREQUAL "opentelemetry-cpp")
166169
build_opentelemetry()
167170
elseif("${DEPENDENCY_NAME}" STREQUAL "ORC")
@@ -276,6 +279,7 @@ if(PARQUET_REQUIRE_ENCRYPTION)
276279
endif()
277280

278281
if(ARROW_WITH_OPENTELEMETRY)
282+
set(ARROW_WITH_NLOHMANN_JSON ON)
279283
set(ARROW_WITH_PROTOBUF ON)
280284
endif()
281285

@@ -304,6 +308,7 @@ endif()
304308

305309
if(ARROW_GCS)
306310
set(ARROW_WITH_GOOGLE_CLOUD_CPP ON)
311+
set(ARROW_WITH_NLOHMANN_JSON ON)
307312
endif()
308313

309314
if(ARROW_JSON)
@@ -3772,36 +3777,41 @@ macro(build_crc32c_once)
37723777
endif()
37733778
endmacro()
37743779

3775-
macro(build_nlohmann_json_once)
3776-
if(NOT TARGET nlohmann_json_ep)
3777-
message(STATUS "Building nlohmann-json from source")
3778-
# "Build" nlohmann-json
3779-
set(NLOHMANN_JSON_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/nlohmann_json_ep-install")
3780-
set(NLOHMANN_JSON_INCLUDE_DIR "${NLOHMANN_JSON_PREFIX}/include")
3781-
set(NLOHMANN_JSON_CMAKE_ARGS
3782-
${EP_COMMON_CMAKE_ARGS} "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
3783-
-DBUILD_TESTING=OFF -DJSON_BuildTests=OFF)
3780+
macro(build_nlohmann_json)
3781+
message(STATUS "Building nlohmann-json from source")
3782+
# "Build" nlohmann-json
3783+
set(NLOHMANN_JSON_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/nlohmann_json_ep-install")
3784+
set(NLOHMANN_JSON_INCLUDE_DIR "${NLOHMANN_JSON_PREFIX}/include")
3785+
set(NLOHMANN_JSON_CMAKE_ARGS
3786+
${EP_COMMON_CMAKE_ARGS} "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>" -DBUILD_TESTING=OFF
3787+
-DJSON_BuildTests=OFF)
37843788

3785-
set(NLOHMANN_JSON_BUILD_BYPRODUCTS ${NLOHMANN_JSON_PREFIX}/include/nlohmann/json.hpp)
3789+
set(NLOHMANN_JSON_BUILD_BYPRODUCTS ${NLOHMANN_JSON_PREFIX}/include/nlohmann/json.hpp)
37863790

3787-
externalproject_add(nlohmann_json_ep
3788-
${EP_LOG_OPTIONS}
3789-
INSTALL_DIR ${NLOHMANN_JSON_PREFIX}
3790-
URL ${NLOHMANN_JSON_SOURCE_URL}
3791-
URL_HASH "SHA256=${ARROW_NLOHMANN_JSON_BUILD_SHA256_CHECKSUM}"
3792-
CMAKE_ARGS ${NLOHMANN_JSON_CMAKE_ARGS}
3793-
BUILD_BYPRODUCTS ${NLOHMANN_JSON_BUILD_BYPRODUCTS})
3791+
externalproject_add(nlohmann_json_ep
3792+
${EP_LOG_OPTIONS}
3793+
INSTALL_DIR ${NLOHMANN_JSON_PREFIX}
3794+
URL ${NLOHMANN_JSON_SOURCE_URL}
3795+
URL_HASH "SHA256=${ARROW_NLOHMANN_JSON_BUILD_SHA256_CHECKSUM}"
3796+
CMAKE_ARGS ${NLOHMANN_JSON_CMAKE_ARGS}
3797+
BUILD_BYPRODUCTS ${NLOHMANN_JSON_BUILD_BYPRODUCTS})
37943798

3795-
# Work around https://gitlab.kitware.com/cmake/cmake/issues/15052
3796-
file(MAKE_DIRECTORY ${NLOHMANN_JSON_INCLUDE_DIR})
3799+
# Work around https://gitlab.kitware.com/cmake/cmake/issues/15052
3800+
file(MAKE_DIRECTORY ${NLOHMANN_JSON_INCLUDE_DIR})
37973801

3798-
add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED)
3799-
set_target_properties(nlohmann_json::nlohmann_json
3800-
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
3801-
"${NLOHMANN_JSON_INCLUDE_DIR}")
3802-
add_dependencies(nlohmann_json::nlohmann_json nlohmann_json_ep)
3803-
endif()
3802+
add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED)
3803+
set_target_properties(nlohmann_json::nlohmann_json
3804+
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
3805+
"${NLOHMANN_JSON_INCLUDE_DIR}")
3806+
add_dependencies(nlohmann_json::nlohmann_json nlohmann_json_ep)
38043807
endmacro()
3808+
if(ARROW_WITH_NLOHMANN_JSON)
3809+
resolve_dependency(nlohmann_json)
3810+
get_target_property(nlohmann_json_INCLUDE_DIR nlohmann_json::nlohmann_json
3811+
INTERFACE_INCLUDE_DIRECTORIES)
3812+
include_directories(SYSTEM ${nlohmann_json_INCLUDE_DIR})
3813+
message(STATUS "Found nlohmann_json headers: ${nlohmann_json_INCLUDE_DIR}")
3814+
endif()
38053815

38063816
macro(build_google_cloud_cpp_storage)
38073817
message(STATUS "Building google-cloud-cpp from source")
@@ -3810,7 +3820,6 @@ macro(build_google_cloud_cpp_storage)
38103820
# List of dependencies taken from https://github.com/googleapis/google-cloud-cpp/blob/master/doc/packaging.md
38113821
build_absl_once()
38123822
build_crc32c_once()
3813-
build_nlohmann_json_once()
38143823

38153824
# Curl is required on all platforms, but building it internally might also trip over S3's copy.
38163825
# For now, force its inclusion from the underlying system or fail.
@@ -3850,7 +3859,7 @@ macro(build_google_cloud_cpp_storage)
38503859

38513860
add_dependencies(google_cloud_cpp_dependencies absl_ep)
38523861
add_dependencies(google_cloud_cpp_dependencies crc32c_ep)
3853-
add_dependencies(google_cloud_cpp_dependencies nlohmann_json_ep)
3862+
add_dependencies(google_cloud_cpp_dependencies nlohmann_json::nlohmann_json)
38543863

38553864
set(GOOGLE_CLOUD_CPP_STATIC_LIBRARY_STORAGE
38563865
"${GOOGLE_CLOUD_CPP_INSTALL_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}google_cloud_cpp_storage${CMAKE_STATIC_LIBRARY_SUFFIX}"
@@ -4043,9 +4052,6 @@ endif()
40434052
macro(build_opentelemetry)
40444053
message(STATUS "Building OpenTelemetry from source")
40454054

4046-
build_nlohmann_json_once()
4047-
find_curl()
4048-
40494055
set(OPENTELEMETRY_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/opentelemetry_ep-install")
40504056
set(OPENTELEMETRY_INCLUDE_DIR "${OPENTELEMETRY_PREFIX}/include")
40514057
set(OPENTELEMETRY_STATIC_LIB
@@ -4153,8 +4159,8 @@ macro(build_opentelemetry)
41534159
INSTALL_COMMAND ""
41544160
EXCLUDE_FROM_ALL OFF)
41554161

4156-
add_dependencies(opentelemetry_dependencies nlohmann_json_ep opentelemetry_proto_ep
4157-
${ARROW_PROTOBUF_LIBPROTOBUF})
4162+
add_dependencies(opentelemetry_dependencies nlohmann_json::nlohmann_json
4163+
opentelemetry_proto_ep ${ARROW_PROTOBUF_LIBPROTOBUF})
41584164

41594165
set(OPENTELEMETRY_PREFIX_PATH_LIST_SEP_CHAR "|")
41604166
# JOIN is CMake >=3.12 only
@@ -4245,6 +4251,9 @@ macro(build_opentelemetry)
42454251
endmacro()
42464252

42474253
if(ARROW_WITH_OPENTELEMETRY)
4254+
# cURL is required whether we build from source or use an existing installation
4255+
# (OTel's cmake files do not call find_curl for you)
4256+
find_curl()
42484257
set(opentelemetry-cpp_SOURCE "AUTO")
42494258
resolve_dependency(opentelemetry-cpp)
42504259
get_target_property(OPENTELEMETRY_INCLUDE_DIR opentelemetry-cpp::api

0 commit comments

Comments
 (0)