Skip to content

CXX-2284 Append platform data to handshake #915

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

Merged
merged 4 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/mongocxx/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ configure_file(
${CMAKE_CURRENT_BINARY_DIR}/config.hpp
)

if (DEFINED CMAKE_CXX_COMPILER_ID)
set (MONGOCXX_COMPILER_ID "${CMAKE_CXX_COMPILER_ID}")
else ()
set (MONGOCXX_COMPILER_ID "Unknown")
endif ()

if (DEFINED CMAKE_CXX_COMPILER_VERSION)
set (MONGOCXX_COMPILER_VERSION "${CMAKE_CXX_COMPILER_VERSION}")
else ()
set (MONGOCXX_COMPILER_VERSION "Unknown")
endif ()

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/private/config.hh.in
${CMAKE_CURRENT_BINARY_DIR}/private/config.hh
Expand Down
2 changes: 2 additions & 0 deletions src/mongocxx/config/private/config.hh.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
// limitations under the License.

#cmakedefine MONGOCXX_ENABLE_SSL
#cmakedefine MONGOCXX_COMPILER_ID "${MONGOCXX_COMPILER_ID}"
#cmakedefine MONGOCXX_COMPILER_VERSION "${MONGOCXX_COMPILER_VERSION}"
18 changes: 17 additions & 1 deletion src/mongocxx/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include <atomic>
#include <sstream>
#include <type_traits>
#include <utility>

Expand Down Expand Up @@ -90,7 +91,22 @@ class instance::impl {
} else {
libmongoc::log_set_handler(null_log_handler, nullptr);
}
libmongoc::handshake_data_append("mongocxx", MONGOCXX_VERSION_STRING, NULL);

// Despite the name, mongoc_handshake_data_append *prepends* the platform string.
// mongoc_handshake_data_append does not add a delimitter, so include the " / " in the
// argument for consistency with the driver_name, and driver_version.
std::stringstream platform;
long stdcxx = __cplusplus;
#ifdef _MSVC_LANG
// Prefer _MSVC_LANG to report the supported C++ standard with MSVC.
// The __cplusplus macro may be incorrect. See:
// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
stdcxx = _MSVC_LANG;
#endif
platform << "CXX=" << MONGOCXX_COMPILER_ID << " " << MONGOCXX_COMPILER_VERSION << " "
<< "stdcxx=" << stdcxx << " / ";
libmongoc::handshake_data_append(
"mongocxx", MONGOCXX_VERSION_STRING, platform.str().c_str());
}

~impl() {
Expand Down