diff --git a/.mci.yml b/.mci.yml index fac46e1e60..3512c9f7fd 100644 --- a/.mci.yml +++ b/.mci.yml @@ -283,6 +283,18 @@ functions: add_expansions_to_env: true script: mongo-cxx-driver/.evergreen/install_c_driver.sh + # fetch_c_driver_source may be used to fetch the C driver source without installing the C driver. + # This can be used when only CI scripts are needed. + "fetch_c_driver_source": + - command: shell.exec + params: + shell: bash + working_dir: "." + script: | + set -o errexit + set -o pipefail + git clone --depth 1 https://github.com/mongodb/mongo-c-driver mongoc + "lint": - command: shell.exec params: @@ -832,7 +844,7 @@ tasks: - name: clang-tidy commands: - func: "setup" - - func: "install_c_driver" + - func: "fetch_c_driver_source" - func: "compile" - func: "clang-tidy" @@ -840,37 +852,41 @@ tasks: commands: - func: "setup" - func: "start_mongod" - - func: "install_c_driver" + - func: "fetch_c_driver_source" - func: "compile" vars: RUN_DISTCHECK: 1 - func: "clone_drivers-evergreen-tools" - func: "run_kms_servers" + # Call "install_c_driver" before "test" to build static C driver libraries. Example projects require static C driver libraries. + - func: "install_c_driver" - func: "test" - name: compile_and_test_with_shared_libs_extra_alignment commands: - func: "setup" - func: "start_mongod" - - func: "install_c_driver" + - func: "fetch_c_driver_source" vars: BSON_EXTRA_ALIGNMENT: 1 - func: "compile" - func: "clone_drivers-evergreen-tools" - func: "run_kms_servers" + - func: "install_c_driver" - func: "test" - name: compile_and_test_with_shared_libs_cxx20 commands: - func: "setup" - func: "start_mongod" - - func: "install_c_driver" + - func: "fetch_c_driver_source" - func: "compile" vars: RUN_DISTCHECK: 1 REQUIRED_CXX_STANDARD: 20 - func: "clone_drivers-evergreen-tools" - func: "run_kms_servers" + - func: "install_c_driver" - func: "test" vars: REQUIRED_CXX_STANDARD: 20 @@ -880,7 +896,7 @@ tasks: commands: - func: "setup" - func: "start_mongod" - - func: "install_c_driver" + - func: "fetch_c_driver_source" vars: BSON_EXTRA_ALIGNMENT: 1 - func: "compile" @@ -888,6 +904,7 @@ tasks: REQUIRED_CXX_STANDARD: 20 - func: "clone_drivers-evergreen-tools" - func: "run_kms_servers" + - func: "install_c_driver" - func: "test" vars: REQUIRED_CXX_STANDARD: 20 @@ -897,13 +914,13 @@ tasks: commands: - func: "setup" - func: "start_mongod" - - func: "install_c_driver" + - func: "fetch_c_driver_source" - func: "compile" - name: compile_without_tests commands: - func: "setup" - - func: "install_c_driver" + - func: "fetch_c_driver_source" - func: "compile" vars: ENABLE_TESTS: OFF @@ -914,7 +931,7 @@ tasks: - func: "start_mongod" vars: AUTH: auth - - func: "install_c_driver" + - func: "fetch_c_driver_source" - func: "compile" - func: "test auth" - func: "test atlas connectivity" @@ -923,13 +940,14 @@ tasks: commands: - func: "setup" - func: "start_mongod" - - func: "install_c_driver" + - func: "fetch_c_driver_source" - func: "compile" vars: USE_STATIC_LIBS: 1 RUN_DISTCHECK: 1 - func: "clone_drivers-evergreen-tools" - func: "run_kms_servers" + - func: "install_c_driver" - func: "test" vars: USE_STATIC_LIBS: 1 @@ -938,7 +956,7 @@ tasks: commands: - func: "setup" - func: "start_mongod" - - func: "install_c_driver" + - func: "fetch_c_driver_source" vars: BSON_EXTRA_ALIGNMENT: 1 - func: "compile" @@ -946,11 +964,31 @@ tasks: USE_STATIC_LIBS: 1 - func: "clone_drivers-evergreen-tools" - func: "run_kms_servers" + - func: "install_c_driver" - func: "test" vars: USE_STATIC_LIBS: 1 - name: compile_and_test_with_shared_libs_replica_set + commands: + - func: "setup" + - func: "start_mongod" + vars: + TOPOLOGY: "replica_set" + - func: "fetch_c_driver_source" + - func: "compile" + vars: + RUN_DISTCHECK: 1 + - func: "clone_drivers-evergreen-tools" + - func: "run_kms_servers" + - func: "install_c_driver" + - func: "test" + + # Auto downloading the C driver in the C++ build does not currently include + # support for libmongocrypt, therefore it is not configured with + # -DENABLE_CLIENT_SIDE_ENCRYPTION=ON. For now, CSFLE tests will need to have + # a manually configured C driver, hence the need to seperate this task. + - name: compile_and_test_with_shared_libs_replica_set_with_libmongocrypt commands: - func: "setup" - func: "start_mongod" @@ -967,7 +1005,7 @@ tasks: - name: uninstall_check commands: - func: "setup" - - func: "install_c_driver" + - func: "fetch_c_driver_source" - func: "compile" - command: expansions.update params: @@ -987,7 +1025,7 @@ tasks: - name: uninstall_check_windows commands: - func: "setup" - - func: "install_c_driver" + - func: "fetch_c_driver_source" - func: "compile" - command: expansions.update params: @@ -1023,7 +1061,7 @@ tasks: export CMAKE="$(find_cmake_latest)" cd build $CMAKE .. - $CMAKE --build . -- -j 8 + $CMAKE --build . -- -j $(nproc) ./hello_mongocxx - name: debian-package-build @@ -1098,7 +1136,7 @@ tasks: - name: test_mongohouse commands: - func: "setup" - - func: "install_c_driver" + - func: "fetch_c_driver_source" - func: "compile" - func: "build_mongohouse" - func: "run_mongohouse" @@ -1113,7 +1151,7 @@ tasks: # Authentication with versioned API should already be tested # in the C driver. AUTH: noauth - - func: "install_c_driver" + - func: "fetch_c_driver_source" - func: "compile" - func: "clone_drivers-evergreen-tools" - func: "run_kms_servers" @@ -1128,7 +1166,7 @@ tasks: vars: ORCHESTRATION_FILE: versioned-api-testing.json AUTH: noauth - - func: "install_c_driver" + - func: "fetch_c_driver_source" - func: "compile" - func: "clone_drivers-evergreen-tools" - func: "run_kms_servers" @@ -1220,7 +1258,7 @@ buildvariants: matrix_spec: {os: "ubuntu-1804", mongodb_version: "*"} display_name: "${os} replica set (MongoDB ${mongodb_version})" tasks: - - name: compile_and_test_with_shared_libs_replica_set + - name: compile_and_test_with_shared_libs_replica_set_with_libmongocrypt - matrix_name: "auth" matrix_spec: {os: "*", mongodb_version: "latest"} @@ -1265,7 +1303,7 @@ buildvariants: - name: compile_and_test_with_shared_libs_extra_alignment_cxx20 - name: compile_and_test_with_static_libs - name: compile_and_test_with_static_libs_extra_alignment - - name: compile_and_test_with_shared_libs_replica_set + - name: compile_and_test_with_shared_libs_replica_set_with_libmongocrypt - name: build_example_with_add_subdirectory distros: - rhel90-large @@ -1288,7 +1326,7 @@ buildvariants: - name: compile_and_test_with_shared_libs_extra_alignment_cxx20 - name: compile_and_test_with_static_libs - name: compile_and_test_with_static_libs_extra_alignment - - name: compile_and_test_with_shared_libs_replica_set + - name: compile_and_test_with_shared_libs_replica_set_with_libmongocrypt - name: build_example_with_add_subdirectory distros: - rhel90-arm64-large @@ -1310,7 +1348,7 @@ buildvariants: - name: compile_and_test_with_shared_libs_extra_alignment_cxx20 - name: compile_and_test_with_static_libs - name: compile_and_test_with_static_libs_extra_alignment - - name: compile_and_test_with_shared_libs_replica_set + - name: compile_and_test_with_shared_libs_replica_set_with_libmongocrypt - name: build_example_with_add_subdirectory distros: - debian11-large @@ -1354,7 +1392,7 @@ buildvariants: - name: compile_and_test_with_shared_libs_extra_alignment - name: compile_and_test_with_static_libs - name: compile_and_test_with_static_libs_extra_alignment - - name: compile_and_test_with_shared_libs_replica_set + - name: compile_and_test_with_shared_libs_replica_set_with_libmongocrypt - name: build_example_with_add_subdirectory distros: - debian10-large @@ -1381,6 +1419,18 @@ buildvariants: - debian10-large - name: uninstall_check + # Add matrix for specification test requirement of mongocryptd: + # "Drivers MUST run all tests with mongocryptd on at least one platform for all tested server versions (4.2+)." + - matrix_name: "mongocryptd" + matrix_spec: + os: "ubuntu-1804" + mongodb_version: ["4.2", "4.4", "5.0", "latest"] + display_name: "${os} (MongoDB ${mongodb_version}) with mongocryptd" + tasks: + - name: compile_and_test_with_shared_libs_replica_set_with_libmongocrypt + expansions: + use_mongocryptd: true + - name: ubuntu2004-release-latest display_name: "Ubuntu 20.04 Release (MongoDB Latest)" expansions: @@ -1396,7 +1446,7 @@ buildvariants: - name: compile_and_test_with_shared_libs_extra_alignment - name: compile_and_test_with_static_libs - name: compile_and_test_with_static_libs_extra_alignment - - name: compile_and_test_with_shared_libs_replica_set + - name: compile_and_test_with_shared_libs_replica_set_with_libmongocrypt - name: build_example_with_add_subdirectory distros: - ubuntu2004-large @@ -1439,7 +1489,7 @@ buildvariants: - name: compile_and_test_with_shared_libs_extra_alignment - name: compile_and_test_with_static_libs - name: compile_and_test_with_static_libs_extra_alignment - - name: compile_and_test_with_shared_libs_replica_set + - name: compile_and_test_with_shared_libs_replica_set_with_libmongocrypt - name: build_example_with_add_subdirectory distros: - ubuntu1804-build diff --git a/CMakeLists.txt b/CMakeLists.txt index 20254facb8..0fbf2c4883 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,74 @@ else() message(WARNING "Unknown compiler... recklessly proceeding without a version check") endif() +set(LIBMONGOC_REQUIRED_VERSION 1.24.0) +set(LIBMONGOC_DOWNLOAD_VERSION ba5ab6de26a874d33b0abc3d2b46961a69380e7a) # TODO: update to 1.25.0 once C driver 1.25.0 is released. +set(LIBMONGOC_REQUIRED_ABI_VERSION 1.0) + +set(NEED_DOWNLOAD_C_DRIVER false) +if(TARGET mongoc_shared OR TARGET mongoc_static) + # If these targets exist, then libmongoc has already been included as a project + # sub-directory + message (STATUS "Found libmongoc targets declared in current build scope; version not checked") + + if(NOT MONGOCXX_LINK_WITH_STATIC_MONGOC) + set(libmongoc_target mongoc_shared) + else() + set(libmongoc_target mongoc_static) + endif() + + if(MONGOCXX_BUILD_STATIC) + set(mongocxx_pkg_dep "find_dependency(mongoc-1.0 REQUIRED)") + endif() +else() + find_package(mongoc-${LIBMONGOC_REQUIRED_ABI_VERSION} ${LIBMONGOC_REQUIRED_VERSION} QUIET) + if(mongoc-${LIBMONGOC_REQUIRED_ABI_VERSION}_FOUND) + message(STATUS "Found libmongoc ${mongoc-${LIBMONGOC_REQUIRED_ABI_VERSION}_VERSION}, don't need to download it.") + else() + set(NEED_DOWNLOAD_C_DRIVER true CACHE INTERNAL "") + endif() +endif() + +if(NEED_DOWNLOAD_C_DRIVER) + message(STATUS "No Mongo C Driver path provided via CMAKE_PREFIX_PATH, will download C driver version ${LIBMONGOC_DOWNLOAD_VERSION} from the internet.") + message(STATUS "Download and configure C driver version ${LIBMONGOC_DOWNLOAD_VERSION} ... begin") + include(FetchContent) + include(ExternalProject) + + # Declare mongo-c-driver as a dependency + FetchContent_Declare( + mongo-c-driver + GIT_REPOSITORY https://github.com/mongodb/mongo-c-driver.git + GIT_TAG ${LIBMONGOC_DOWNLOAD_VERSION} + ) + + FetchContent_GetProperties(mongo-c-driver) + if(NOT mongo-c-driver_POPULATED) + set(OLD_ENABLE_TESTS ${ENABLE_TESTS}) + set(OLD_BUILD_TESTING ${BUILD_TESTING}) + set(OLD_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) + set(OLD_CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) + + set(ENABLE_EXTRA_ALIGNMENT OFF) + + FetchContent_Populate(mongo-c-driver) + # Set ENABLE_TESTS to OFF to disable the test-libmongoc target in the C driver. + # This prevents the LoadTests.cmake script from attempting to execute test-libmongoc. + # test-libmongoc is not built with the "all" target. + # Attempting to execute test-libmongoc results in an error: "Unable to find executable: NOT_FOUND" + set(ENABLE_TESTS OFF) + set(BUILD_TESTING OFF) + string(REPLACE " -Werror" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REPLACE " -Werror" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + add_subdirectory(${mongo-c-driver_SOURCE_DIR} ${mongo-c-driver_BINARY_DIR}) + set(CMAKE_CXX_FLAGS ${OLD_CMAKE_CXX_FLAGS}) + set(CMAKE_C_FLAGS ${OLD_CMAKE_C_FLAGS}) + set(ENABLE_TESTS OLD_ENABLE_TESTS) + set(BUILD_TESTING OLD_BUILD_TESTING) + endif() + message(STATUS "Download and configure C driver version ${LIBMONGOC_DOWNLOAD_VERSION} ... end") +endif() + # All of our target compilers support the deprecated # attribute. Normally, we would just let the GenerateExportHeader # subsystem do this via configure check, but there appears to be a @@ -338,23 +406,20 @@ add_custom_command (OUTPUT ${DIST_FILE} ${ALL_DIST} ${dist_generated_depends} ) -if(NOT (TARGET bson_shared OR TARGET mongoc_shared)) - # If these targets exist, then libbson/libmongoc have already been included - # as a project sub-directory; the 'dist' and 'distcheck' targets here would - # collide with those declared in the mongo-c-driver project - add_custom_target (dist DEPENDS ${DIST_FILE}) - - add_custom_target (distcheck DEPENDS dist - COMMAND ${CMAKE_COMMAND} - -D CMAKE_MODULE_PATH=${PROJECT_SOURCE_DIR}/cmake/make_dist - -D CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} - -D PACKAGE_PREFIX=${PACKAGE_PREFIX} - -D CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} - -P ${PROJECT_SOURCE_DIR}/cmake/make_dist/MakeDistCheck.cmake - ) +if(NOT (TARGET dist OR TARGET distcheck)) + add_custom_target (dist DEPENDS ${DIST_FILE}) + + add_custom_target (distcheck DEPENDS dist + COMMAND ${CMAKE_COMMAND} + -D CMAKE_MODULE_PATH=${PROJECT_SOURCE_DIR}/cmake/make_dist + -D CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} + -D PACKAGE_PREFIX=${PACKAGE_PREFIX} + -D CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} + -P ${PROJECT_SOURCE_DIR}/cmake/make_dist/MakeDistCheck.cmake + ) endif() -if(ENABLE_UNINSTALL AND NOT (TARGET bson_shared OR TARGET mongoc_shared)) +if(ENABLE_UNINSTALL) if(WIN32) set(UNINSTALL_PROG "uninstall.cmd") else() diff --git a/docs/content/mongocxx-v3/installation/advanced.md b/docs/content/mongocxx-v3/installation/advanced.md index 5e287fa0fd..ad4b73d985 100644 --- a/docs/content/mongocxx-v3/installation/advanced.md +++ b/docs/content/mongocxx-v3/installation/advanced.md @@ -19,6 +19,37 @@ cmake .. \ The above command would produce libraries named `libcustom_bsoncxx.so` and `libcustom_mongocxx.so` (or with the extension appropriate for the build platform). Those libraries could be placed in a standard system directory or in an alternate location and could be linked to by specifying something like `-lcustom_mongocxx -lcustom_bsoncxx` on the linker command line (possibly adjusting the specific flags to those required by your linker). +## Installing the MongoDB C driver. + +The mongocxx driver builds on top of the [MongoDB C driver](https://www.mongodb.com/docs/drivers/c/). + +The build of mongocxx-3.8.0 automatically downloads and installs the C driver if the C driver is not detected. +To use an existing install of the C driver, set `CMAKE_PREFIX_PATH` to the directory containing the C driver install. + +* For mongocxx-3.8.x, libmongoc 1.24.0 or later is required. +* For mongocxx-3.7.x, libmongoc 1.22.1 or later is required. +* For mongocxx-3.6.x, libmongoc 1.17.0 or later is required. +* For mongocxx-3.5.x, libmongoc 1.15.0 or later is required. +* For mongocxx-3.4.x, libmongoc 1.13.0 or later is required. +* For mongocxx-3.3.x, libmongoc 1.10.1 or later is required. +* For mongocxx-3.2.x, libmongoc 1.9.2 or later is required. +* For mongocxx-3.1.4+, libmongoc 1.7.0 or later is required. +* For mongocxx-3.1.[0-3], libmongoc 1.5.0 or later is required. +* For mongocxx-3.0.x, we recommend the last 1.4.x version of libmongoc + +Unless you know that your package manager offers a sufficiently recent version, you +will need to download and build from the source code. Get a tarball from +the [C Driver releases](https://github.com/mongodb/mongo-c-driver/releases) +page. + +Follow the instructions for building from a tarball at +[Installing libmongoc](http://mongoc.org/libmongoc/current/installing.html). + +Industry best practices and some regulations require the use of TLS 1.1 +or newer. The MongoDB C Driver supports TLS 1.1 on Linux if OpenSSL is +at least version 1.0.1. On macOS and Windows, the C Driver uses native +TLS implementations that support TLS 1.1. + ## Advanced configuration (static configurations) The following sub-sections detail advanced options for configuring the C++ driver and/or its diff --git a/docs/content/mongocxx-v3/installation/linux.md b/docs/content/mongocxx-v3/installation/linux.md index e794b662bf..ecc8acbb3a 100644 --- a/docs/content/mongocxx-v3/installation/linux.md +++ b/docs/content/mongocxx-v3/installation/linux.md @@ -7,35 +7,7 @@ title = "Linux" weight = 33 +++ -### Step 1: Install the latest version of the MongoDB C driver. - -The mongocxx driver builds on top of the MongoDB C driver. - -* For mongocxx-3.8.x, libmongoc 1.24.0 or later is required. -* For mongocxx-3.7.x, libmongoc 1.22.1 or later is required. -* For mongocxx-3.6.x, libmongoc 1.17.0 or later is required. -* For mongocxx-3.5.x, libmongoc 1.15.0 or later is required. -* For mongocxx-3.4.x, libmongoc 1.13.0 or later is required. -* For mongocxx-3.3.x, libmongoc 1.10.1 or later is required. -* For mongocxx-3.2.x, libmongoc 1.9.2 or later is required. -* For mongocxx-3.1.4+, libmongoc 1.7.0 or later is required. -* For mongocxx-3.1.[0-3], libmongoc 1.5.0 or later is required. -* For mongocxx-3.0.x, we recommend the last 1.4.x version of libmongoc - -Unless you know that your package manager offers a high enough version, you -will need to download and build from the source code. Get a tarball from -the [C Driver releases](https://github.com/mongodb/mongo-c-driver/releases) -page. - -Follow the instructions for building from a tarball at -[Installing libmongoc](http://mongoc.org/libmongoc/current/installing.html). - -Industry best practices and some regulations require the use of TLS 1.1 -or newer. The MongoDB C Driver supports TLS 1.1 on Linux if OpenSSL is -at least version 1.0.1. On macOS and Windows, the C Driver uses native -TLS implementations that support TLS 1.1. - -### Step 2: Choose a C++17 polyfill +### Step 1: Choose a C++17 polyfill The mongocxx driver uses the C++17 features `std::optional` and `std::string_view`. To compile the mongocxx driver for pre-C++17, you @@ -71,7 +43,7 @@ against the same library. **DO NOT** change your project's polyfill if you need to create a stable binary interface. -### Step 3: Download the latest version of the mongocxx driver. +### Step 2: Download the latest version of the mongocxx driver. The most reliable starting point for building the mongocxx driver is the latest release tarball. @@ -89,9 +61,9 @@ cd mongo-cxx-driver-r3.8.0/build Make sure you change to the `build` directory of whatever source tree you obtain. -### Step 4: Configure the driver +### Step 3: Configure the driver -On Unix systems, `libmongoc` installs into `/usr/local` by default. Without additional +Without additional configuration, `mongocxx` installs into its local build directory as a courtesy to those who build from source. To configure `mongocxx` for installation into `/usr/local` as well, use the following `cmake` command: @@ -111,7 +83,7 @@ cmake .. \ -DCMAKE_INSTALL_PREFIX=/usr/local ``` -### Step 5: Build and install the driver +### Step 4: Build and install the driver If you are using the default MNMLSTC polyfill and are installing to a directory requiring root permissions, you should install the polyfill with diff --git a/docs/content/mongocxx-v3/installation/macos.md b/docs/content/mongocxx-v3/installation/macos.md index 8584b31f7d..54514fe58a 100644 --- a/docs/content/mongocxx-v3/installation/macos.md +++ b/docs/content/mongocxx-v3/installation/macos.md @@ -7,35 +7,7 @@ title = "macOS" weight = 32 +++ -### Step 1: Install the latest version of the MongoDB C driver. - -The mongocxx driver builds on top of the MongoDB C driver. - -* For mongocxx-3.8.x, libmongoc 1.24.0 or later is required. -* For mongocxx-3.7.x, libmongoc 1.22.1 or later is required. -* For mongocxx-3.6.x, libmongoc 1.17.0 or later is required. -* For mongocxx-3.5.x, libmongoc 1.15.0 or later is required. -* For mongocxx-3.4.x, libmongoc 1.13.0 or later is required. -* For mongocxx-3.3.x, libmongoc 1.10.1 or later is required. -* For mongocxx-3.2.x, libmongoc 1.9.2 or later is required. -* For mongocxx-3.1.4+, libmongoc 1.7.0 or later is required. -* For mongocxx-3.1.[0-3], libmongoc 1.5.0 or later is required. -* For mongocxx-3.0.x, we recommend the last 1.4.x version of libmongoc - -Unless you know that your package manager offers a high enough version, you -will need to download and build from the source code. Get a tarball from -the [C Driver releases](https://github.com/mongodb/mongo-c-driver/releases) -page. - -Follow the instructions for building from a tarball at -[Installing libmongoc](http://mongoc.org/libmongoc/current/installing.html). - -Industry best practices and some regulations require the use of TLS 1.1 -or newer. The MongoDB C Driver supports TLS 1.1 on Linux if OpenSSL is -at least version 1.0.1. On macOS and Windows, the C Driver uses native -TLS implementations that support TLS 1.1. - -### Step 2: Choose a C++17 polyfill +### Step 1: Choose a C++17 polyfill The mongocxx driver uses the C++17 features `std::optional` and `std::string_view`. To compile the mongocxx driver for pre-C++17, you @@ -71,7 +43,7 @@ against the same library. **DO NOT** change your project's polyfill if you need to create a stable binary interface. -### Step 3: Download the latest version of the mongocxx driver. +### Step 2: Download the latest version of the mongocxx driver. The most reliable starting point for building the mongocxx driver is the latest release tarball. @@ -89,9 +61,9 @@ cd mongo-cxx-driver-r3.8.0/build Make sure you change to the `build` directory of whatever source tree you obtain. -### Step 4: Configure the driver +### Step 3: Configure the driver -On Unix systems, `libmongoc` installs into `/usr/local` by default. Without additional +Without additional configuration, `mongocxx` installs into its local build directory as a courtesy to those who build from source. To configure `mongocxx` for installation into `/usr/local` as well, use the following `cmake` command: @@ -111,7 +83,7 @@ cmake .. \ -DCMAKE_INSTALL_PREFIX=/usr/local ``` -### Step 5: Build and install the driver +### Step 4: Build and install the driver If you are using the default MNMLSTC polyfill and are installing to a directory requiring root permissions, you should install the polyfill with diff --git a/docs/content/mongocxx-v3/installation/windows.md b/docs/content/mongocxx-v3/installation/windows.md index c61121b9e1..765d3f32d3 100644 --- a/docs/content/mongocxx-v3/installation/windows.md +++ b/docs/content/mongocxx-v3/installation/windows.md @@ -7,38 +7,7 @@ title = "Windows" weight = 31 +++ -### Step 1: Install the latest version of the MongoDB C driver. - -The mongocxx driver builds on top of the MongoDB C driver. - -* For mongocxx-3.8.x, libmongoc 1.24.0 or later is required. -* For mongocxx-3.7.x, libmongoc 1.22.1 or later is required. -* For mongocxx-3.6.x, libmongoc 1.17.0 or later is required. -* For mongocxx-3.5.x, libmongoc 1.15.0 or later is required. -* For mongocxx-3.4.x, libmongoc 1.13.0 or later is required. -* For mongocxx-3.3.x, libmongoc 1.10.1 or later is required. -* For mongocxx-3.2.x, libmongoc 1.9.2 or later is required. -* For mongocxx-3.1.4+, libmongoc 1.7.0 or later is required. -* For mongocxx-3.1.[0-3], libmongoc 1.5.0 or later is required. -* For mongocxx-3.0.x, we recommend the last 1.4.x version of libmongoc - -Unless you know that your package manager offers a high enough version, you -will need to download and build from the source code. Get a tarball from -the [C Driver releases](https://github.com/mongodb/mongo-c-driver/releases) -page. - -Follow the instructions for building from a tarball at -[Installing libmongoc](http://mongoc.org/libmongoc/current/installing.html). - -Industry best practices and some regulations require the use of TLS 1.1 -or newer. The MongoDB C Driver supports TLS 1.1 on Linux if OpenSSL is -at least version 1.0.1. On macOS and Windows, the C Driver uses native -TLS implementations that support TLS 1.1. - -If you are compiling on Windows, you should disable extra alignment with -`-DENABLE_EXTRA_ALIGNMENT=0` when configuring the C driver. - -### Step 2: Choose a C++17 polyfill +### Step 1: Choose a C++17 polyfill The mongocxx driver uses the C++17 features `std::optional` and `std::string_view`. To compile the mongocxx driver for pre-C++17, you @@ -74,7 +43,7 @@ against the same library. **DO NOT** change your project's polyfill if you need to create a stable binary interface. -### Step 3: Download the latest version of the mongocxx driver. +### Step 2: Download the latest version of the mongocxx driver. The most reliable starting point for building the mongocxx driver is the latest release tarball. @@ -92,7 +61,7 @@ cd mongo-cxx-driver-r3.8.0/build Make sure you change to the `build` directory of whatever source tree you obtain. -### Step 4: Configure the driver +### Step 3: Configure the driver On Windows, the C++ driver is configured as follows (adjusting the path of the CMake executable as appropriate to your system): @@ -100,14 +69,12 @@ On Windows, the C++ driver is configured as follows (adjusting the path of the C 'C:\Program Files (x86)\CMake\bin\cmake.exe' .. \ -G "Visual Studio 14 2015 Win64" \ -DBOOST_ROOT=C:\local\boost_1_60_0 \ - -DCMAKE_PREFIX_PATH=C:\mongo-c-driver \ -DCMAKE_INSTALL_PREFIX=C:\mongo-cxx-driver ``` The example above assumes: * Boost is found in `C:\local\boost_1_60_0`. -* `libmongoc` is found in `C:\mongo-c-driver`. * `mongocxx` is to be installed into `C:\mongo-cxx-driver`. To build with Visual Studio 2017 without a C++17 polyfill, configure as follows: @@ -116,13 +83,9 @@ To build with Visual Studio 2017 without a C++17 polyfill, configure as follows: 'C:\Program Files (x86)\CMake\bin\cmake.exe' .. \ -G "Visual Studio 15 2017 Win64" \ -DCMAKE_CXX_STANDARD=17 \ - -DCMAKE_PREFIX_PATH=C:\mongo-c-driver \ -DCMAKE_INSTALL_PREFIX=C:\mongo-cxx-driver \ ``` -For details on how to install libmongoc for Windows, see the -[mongoc Windows installation instructions](http://mongoc.org/libmongoc/current/installing.html#building-windows). - #### Configuring with `mongocxx` 3.7.0 and older To build versions 3.7.0 and older without a C++17 polyfill, it is necessary to configure with additional options: @@ -134,24 +97,19 @@ To build versions 3.7.0 and older without a C++17 polyfill, it is necessary to c -G "Visual Studio 15 2017 Win64" \ -DCMAKE_CXX_STANDARD=17 \ -DCMAKE_CXX_FLAGS="/Zc:__cplusplus /EHsc" \ - -DCMAKE_PREFIX_PATH=C:\mongo-c-driver \ -DCMAKE_INSTALL_PREFIX=C:\mongo-cxx-driver \ ``` #### Configuring with `mongocxx` 3.1.x or 3.0.x -Instead of the `-DCMAKE_PREFIX_PATH` option, users must specify the `libmongoc` installation -directory by using the `-DLIBMONGOC_DIR` and `-DLIBBSON_DIR` options: - ```sh cmake .. \ -DCMAKE_BUILD_TYPE=Release \ -DLIBMONGOC_DIR=C:\mongo-c-driver \ - -DLIBBSON_DIR=C:\mongo-c-driver \ -DCMAKE_INSTALL_PREFIX=C:\mongo-cxx-driver ``` -### Step 5: Build and install the driver +### Step 4: Build and install the driver Build and install the driver: diff --git a/etc/make_release.py b/etc/make_release.py index 66deb747fa..f454625677 100755 --- a/etc/make_release.py +++ b/etc/make_release.py @@ -124,6 +124,8 @@ def release(jira_creds_file, Perform the steps associated with the release. """ + check_libmongoc_version() + # Read Jira credentials and GitHub token first, to check that # user has proper credentials before embarking on lengthy builds. jira_options = {'server': 'https://jira.mongodb.org'} @@ -221,6 +223,43 @@ def release(jira_creds_file, create_github_release_draft(gh_repo, release_tag, is_pre_release, dist_file, release_notes_text, output_file, quiet) + +def check_libmongoc_version(): + got_LIBMONGOC_REQUIRED_VERSION = None + got_LIBMONGOC_DOWNLOAD_VERSION = None + with open("CMakeLists.txt", "r") as cmakelists: + for line in cmakelists: + match = re.match( + r"set\(LIBMONGOC_REQUIRED_VERSION\s+(.*?)\)", line) + if match: + if 'TODO' in line: + click.echo( + 'Found TODO on LIBMONGOC_REQUIRED_VERSION line in CMakeLists.txt: {}'.format(line)) + sys.exit(1) + got_LIBMONGOC_REQUIRED_VERSION = match.group(1) + continue + match = re.match( + r"set\(LIBMONGOC_DOWNLOAD_VERSION\s+(.*?)\)", line) + if match: + if 'TODO' in line: + click.echo( + 'Found TODO on LIBMONGOC_DOWNLOAD_VERSION line in CMakeLists.txt: {}'.format(line)) + sys.exit(1) + got_LIBMONGOC_DOWNLOAD_VERSION = match.group(1) + continue + assert got_LIBMONGOC_DOWNLOAD_VERSION + assert got_LIBMONGOC_REQUIRED_VERSION + libmongoc_version_pattern = r'[0-9]+\.[0-9]+\.[0-9]+' + if not re.match (libmongoc_version_pattern, got_LIBMONGOC_DOWNLOAD_VERSION): + click.echo("Expected LIBMONGOC_DOWNLOAD_VERSION to match: {}, got: {}".format( + libmongoc_version_pattern, got_LIBMONGOC_DOWNLOAD_VERSION)) + sys.exit(1) + if not re.match (libmongoc_version_pattern, got_LIBMONGOC_REQUIRED_VERSION): + click.echo("Expected LIBMONGOC_REQUIRED_VERSION to match: {}, got: {}".format( + libmongoc_version_pattern, got_LIBMONGOC_REQUIRED_VERSION)) + sys.exit(1) + + # pylint: enable=too-many-arguments,too-many-locals,too-many-branches,too-many-statements def is_valid_remote(remote): """ diff --git a/etc/releasing.md b/etc/releasing.md index 9cfa8f37b9..aadb671f3a 100644 --- a/etc/releasing.md +++ b/etc/releasing.md @@ -205,6 +205,14 @@ pushed. - Checkout the master branch. Push the commit containing changes to `etc/` and `docs/`. This may require pushing the commit to a fork of the C++ Driver repository and creating a pull request. +- Edit the `Installing the MongoDB C driver` section of + `docs/content/mongocxx-v3/installation/advanced.md` to reflect libmongoc + requirements. +- Edit `docs/content/mongocxx-v3/installation/linux.md`, + `docs/content/mongocxx-v3/installation/macos.md` and + `docs/content/mongocxx-v3/installation/windows.md`. + If the release was not a release candidate, update `Step 2` to reflect the + new latest stable version to download. ## Homebrew This requires a macOS machine. diff --git a/src/mongocxx/CMakeLists.txt b/src/mongocxx/CMakeLists.txt index eb328587e6..45f6bfc1d0 100644 --- a/src/mongocxx/CMakeLists.txt +++ b/src/mongocxx/CMakeLists.txt @@ -29,9 +29,6 @@ message ("mongocxx version: ${MONGOCXX_VERSION}") set(MONGOCXX_INLINE_NAMESPACE "v${MONGOCXX_ABI_VERSION}") set(MONGOCXX_HEADER_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}/mongocxx/${MONGOCXX_INLINE_NAMESPACE}" CACHE INTERNAL "") -set(LIBMONGOC_REQUIRED_VERSION 1.24.0) -set(LIBMONGOC_REQUIRED_ABI_VERSION 1.0) - set(mongocxx_pkg_dep "") if(TARGET mongoc_shared OR TARGET mongoc_static) @@ -69,7 +66,6 @@ else() find_package(libmongoc-${LIBMONGOC_REQUIRED_ABI_VERSION} ${LIBMONGOC_REQUIRED_VERSION} REQUIRED) message ("found libmongoc version ${MONGOC_VERSION}") set(libmongoc_target ${MONGOC_LIBRARIES}) - set(libmongoc_include_directories ${MONGOC_INCLUDE_DIRS}) set(libmongoc_definitions ${MONGOC_DEFINITIONS}) if(MONGOCXX_BUILD_STATIC) set(mongocxx_pkg_dep "find_dependency(libmongoc-1.0 REQUIRED)") @@ -78,7 +74,6 @@ else() find_package(libmongoc-static-${LIBMONGOC_REQUIRED_ABI_VERSION} ${LIBMONGOC_REQUIRED_VERSION} REQUIRED) message ("found libmongoc version ${MONGOC_STATIC_VERSION}") set(libmongoc_target ${MONGOC_STATIC_LIBRARIES}) - set(libmongoc_include_directories ${MONGOC_STATIC_INCLUDE_DIRS}) set(libmongoc_definitions ${MONGOC_STATIC_DEFINITIONS}) if(MONGOCXX_BUILD_STATIC) set(mongocxx_pkg_dep "find_dependency(libmongoc-static-1.0 REQUIRED)")