Skip to content

Commit 2c1c548

Browse files
authored
CXX-2284 Append platform data to handshake (#915)
* CXX-2284 add compiler ID and version to platform * note surprising behavior of mongoc_handshake_data_append * add C++ standard to metadata * prefer _MSVC_LANG on MSVC
1 parent 1f06052 commit 2c1c548

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/mongocxx/config/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ configure_file(
2424
${CMAKE_CURRENT_BINARY_DIR}/config.hpp
2525
)
2626

27+
if (DEFINED CMAKE_CXX_COMPILER_ID)
28+
set (MONGOCXX_COMPILER_ID "${CMAKE_CXX_COMPILER_ID}")
29+
else ()
30+
set (MONGOCXX_COMPILER_ID "Unknown")
31+
endif ()
32+
33+
if (DEFINED CMAKE_CXX_COMPILER_VERSION)
34+
set (MONGOCXX_COMPILER_VERSION "${CMAKE_CXX_COMPILER_VERSION}")
35+
else ()
36+
set (MONGOCXX_COMPILER_VERSION "Unknown")
37+
endif ()
38+
2739
configure_file(
2840
${CMAKE_CURRENT_SOURCE_DIR}/private/config.hh.in
2941
${CMAKE_CURRENT_BINARY_DIR}/private/config.hh

src/mongocxx/config/private/config.hh.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313
// limitations under the License.
1414

1515
#cmakedefine MONGOCXX_ENABLE_SSL
16+
#cmakedefine MONGOCXX_COMPILER_ID "${MONGOCXX_COMPILER_ID}"
17+
#cmakedefine MONGOCXX_COMPILER_VERSION "${MONGOCXX_COMPILER_VERSION}"

src/mongocxx/instance.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include <atomic>
16+
#include <sstream>
1617
#include <type_traits>
1718
#include <utility>
1819

@@ -90,7 +91,22 @@ class instance::impl {
9091
} else {
9192
libmongoc::log_set_handler(null_log_handler, nullptr);
9293
}
93-
libmongoc::handshake_data_append("mongocxx", MONGOCXX_VERSION_STRING, NULL);
94+
95+
// Despite the name, mongoc_handshake_data_append *prepends* the platform string.
96+
// mongoc_handshake_data_append does not add a delimitter, so include the " / " in the
97+
// argument for consistency with the driver_name, and driver_version.
98+
std::stringstream platform;
99+
long stdcxx = __cplusplus;
100+
#ifdef _MSVC_LANG
101+
// Prefer _MSVC_LANG to report the supported C++ standard with MSVC.
102+
// The __cplusplus macro may be incorrect. See:
103+
// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
104+
stdcxx = _MSVC_LANG;
105+
#endif
106+
platform << "CXX=" << MONGOCXX_COMPILER_ID << " " << MONGOCXX_COMPILER_VERSION << " "
107+
<< "stdcxx=" << stdcxx << " / ";
108+
libmongoc::handshake_data_append(
109+
"mongocxx", MONGOCXX_VERSION_STRING, platform.str().c_str());
94110
}
95111

96112
~impl() {

0 commit comments

Comments
 (0)