Skip to content

Commit b54f80f

Browse files
committed
Keep the embedded server out of the ext package
Review feedback on #4327. http_server.h and socket_tools.h are an embedded HTTP server for tests and the http example, so drop them from the ext_common manifest rather than keeping the glob's behaviour for them. The http example includes them, so it cannot build against the install prefix once they stop shipping. Disable it in the install test. That also makes the ws2_32 link on the opentelemetry_ext interface wrong: the target no longer carries a header that calls Winsock, so a package consumer inherits a link it has no use for. Move it to the seven targets that compile the server, which is the full transitive closure of the two headers over the include graph. MSVC autolinks through the pragma in socket_tools.h, so this only shows up on MinGW and GCC for Windows. Bazel's //ext:headers still globs the whole include tree and so still exposes the server, and its linkopt stays for that reason. The file move itself is tracked in #4332.
1 parent f4f5c33 commit b54f80f

8 files changed

Lines changed: 40 additions & 28 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ Increment the:
1616
## [Unreleased]
1717

1818
* [BUILD] Install an explicit list of ext headers instead of the whole
19-
directory. The curl client and curl operation implementation headers and
20-
the internal default factory header are no longer installed
19+
directory. The curl client and curl operation implementation headers, the
20+
internal default factory header, and the embedded HTTP server headers
21+
(`http_server.h` and `socket_tools.h`) are no longer installed
2122
[#4327](https://github.com/open-telemetry/opentelemetry-cpp/pull/4327)
2223

2324
* [BUILD] Run the ext_http component install test on Windows

‎examples/http/CMakeLists.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ if(WITH_HTTP_CLIENT_CURL)
1414
http_server
1515
PRIVATE opentelemetry-cpp::trace opentelemetry-cpp::http_client_curl
1616
opentelemetry-cpp::ostream_span_exporter)
17+
if(WIN32)
18+
target_link_libraries(http_server PRIVATE ws2_32)
19+
endif()
1720
endif()

‎exporters/otlp/CMakeLists.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,9 @@ if(BUILD_TESTING)
10131013
nlohmann_json::nlohmann_json
10141014
protobuf::libprotobuf
10151015
opentelemetry_test_common)
1016+
if(WIN32)
1017+
target_link_libraries(otlp_http_exporter_test ws2_32)
1018+
endif()
10161019
gtest_add_tests(
10171020
TARGET otlp_http_exporter_test
10181021
TEST_PREFIX exporter.otlp.
@@ -1040,6 +1043,9 @@ if(BUILD_TESTING)
10401043
opentelemetry_http_client_nosend
10411044
nlohmann_json::nlohmann_json
10421045
opentelemetry_test_common)
1046+
if(WIN32)
1047+
target_link_libraries(otlp_http_log_record_exporter_test ws2_32)
1048+
endif()
10431049
gtest_add_tests(
10441050
TARGET otlp_http_log_record_exporter_test
10451051
TEST_PREFIX exporter.otlp.

‎exporters/zipkin/CMakeLists.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ if(BUILD_TESTING)
7474
opentelemetry_resources
7575
opentelemetry_http_client_nosend
7676
CURL::libcurl)
77+
if(WIN32)
78+
target_link_libraries(zipkin_exporter_test ws2_32)
79+
endif()
7780

7881
gtest_add_tests(
7982
TARGET zipkin_exporter_test

‎ext/CMakeLists.txt‎

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,16 @@ target_include_directories(
1010
set_target_properties(opentelemetry_ext PROPERTIES EXPORT_NAME "ext")
1111
target_link_libraries(opentelemetry_ext INTERFACE opentelemetry_api)
1212

13-
# The embedded HTTP server headers (socket_tools.h) call Winsock, so declare the
14-
# dependency on the interface target. MSVC also autolinks via #pragma
15-
# comment(lib), but MinGW/GCC ignore that, so consumers there would otherwise
16-
# fail to resolve inet_pton/WSAStartup.
17-
if(WIN32)
18-
target_link_libraries(opentelemetry_ext INTERFACE ws2_32)
19-
endif()
20-
21-
# The patterns below are the manifest of headers this component installs. They
22-
# replace a "*.h" glob over include/opentelemetry/ext, so a header reaches the
23-
# package only when it is named here, and one that exists for the build tree
24-
# alone stays out of it.
25-
#
26-
# Three headers the glob used to install are deliberately absent.
2713
# client/detail/default_factory.h is an internal helper included by exporter
2814
# sources rather than by any public header. client/curl/http_client_curl.h and
29-
# client/curl/http_operation_curl.h are the curl implementation, and a consumer
30-
# creates a curl client through http_client_factory_curl.h, which depends on the
31-
# abstract http_client_factory.h alone.
15+
# client/curl/http_operation_curl.h are the curl implementation, reached through
16+
# http_client_factory_curl.h, which depends on the abstract
17+
# http_client_factory.h alone. server/http_server.h and server/socket_tools.h
18+
# are the embedded server used by tests and the http example.
19+
#
20+
# TODO: the embedded server headers do not belong beside the user facing ones
21+
# under ext/include. Move them to an internal location such as test_common, see
22+
# #4332.
3223
otel_add_component(
3324
COMPONENT
3425
ext_common
@@ -46,11 +37,7 @@ otel_add_component(
4637
PATTERN
4738
"http_client_factory_curl.h"
4839
PATTERN
49-
"url_parser.h"
50-
PATTERN
51-
"http_server.h"
52-
PATTERN
53-
"socket_tools.h")
40+
"url_parser.h")
5441

5542
add_subdirectory(src)
5643

‎ext/test/http/CMakeLists.txt‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ if(WITH_HTTP_CLIENT_CURL)
88
${FILENAME}
99
PRIVATE ${GMOCK_LIB} ${GTEST_BOTH_LIBRARIES} opentelemetry_http_client_curl
1010
opentelemetry_common CURL::libcurl)
11+
if(WIN32)
12+
target_link_libraries(${FILENAME} PRIVATE ws2_32)
13+
endif()
1114
gtest_add_tests(
1215
TARGET ${FILENAME}
1316
TEST_PREFIX ext.http.curl.
@@ -18,9 +21,11 @@ set(SOCKET_TOOLS_FILENAME socket_tools_test)
1821
add_executable(${SOCKET_TOOLS_FILENAME} ${SOCKET_TOOLS_FILENAME}.cc)
1922
target_link_libraries(${SOCKET_TOOLS_FILENAME} opentelemetry_ext ${GMOCK_LIB}
2023
${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
21-
# ws2_32 is now an interface dependency of opentelemetry_ext, so it is inherited
22-
# here; the test thus verifies the public target's usage requirements rather
23-
# than papering over them locally.
24+
# socket_tools.h calls Winsock, and the ext interface target no longer carries
25+
# that link because it is only needed where the embedded server is compiled.
26+
if(WIN32)
27+
target_link_libraries(${SOCKET_TOOLS_FILENAME} ws2_32)
28+
endif()
2429
gtest_add_tests(
2530
TARGET ${SOCKET_TOOLS_FILENAME}
2631
TEST_PREFIX ext.http.sockettools.

‎ext/test/w3c_tracecontext_http_test_server/CMakeLists.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ if(WITH_HTTP_CLIENT_CURL)
88
PRIVATE ${CMAKE_THREAD_LIBS_INIT} opentelemetry_trace
99
opentelemetry_http_client_curl opentelemetry_exporter_ostream_span
1010
CURL::libcurl nlohmann_json::nlohmann_json)
11+
if(WIN32)
12+
target_link_libraries(w3c_tracecontext_http_test_server PRIVATE ws2_32)
13+
endif()
1114
endif()

‎install/test/cmake/examples_test/CMakeLists.txt‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ if("exporters_etw" IN_LIST OPENTELEMETRY_CPP_COMPONENTS_INSTALLED)
4747
endif()
4848

4949
if("ext_http_curl" IN_LIST OPENTELEMETRY_CPP_COMPONENTS_INSTALLED)
50-
set(WITH_EXAMPLES_HTTP ON)
5150
set(WITH_HTTP_CLIENT_CURL ON)
5251
endif()
5352

53+
# The http example uses the embedded server headers, which the package no longer
54+
# installs. The ext headers it does use are covered by
55+
# install/test/src/test_ext_*.cc.
56+
set(WITH_EXAMPLES_HTTP OFF)
57+
5458
if("configuration" IN_LIST OPENTELEMETRY_CPP_COMPONENTS_INSTALLED)
5559
set(WITH_CONFIGURATION ON)
5660
endif()

0 commit comments

Comments
 (0)