Skip to content

CXX-3103 bump minimum required C Driver version to 2.0.0 #1379

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 20 commits into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9e12c0d
CXX-3103 bump minimum required C Driver version to 2.0.0
eramongodb Apr 8, 2025
95c317d
Fix display name for CMake compatibility matrix
eramongodb Apr 8, 2025
9668d13
Remove aggressive FetchContent optimization
eramongodb Apr 8, 2025
291591e
Treat NEED_DOWNLOAD_C_DRIVER as an INTERNAL cache variable
eramongodb Apr 8, 2025
e68fe8f
Restore setting C++ standard in example project CMake configs
eramongodb Apr 8, 2025
461658c
Fix distcheck
eramongodb Apr 8, 2025
3d1026f
Merge remote-tracking branch 'upstream/master' into cxx-3103
eramongodb Apr 9, 2025
779d7aa
Merge remote-tracking branch 'upstream/master' into cxx-3103
eramongodb Apr 10, 2025
e392c8a
Use alias targets for *_target variables
eramongodb Apr 10, 2025
1063ba4
Remove CMake patch version number from requirements and coverage
eramongodb Apr 14, 2025
b7307ac
Restore patch number for CMake binary downloads
eramongodb Apr 14, 2025
6d78a87
Test find-cxx and add-cxx in the same task
eramongodb Apr 15, 2025
9cac0ab
Defer C++ standard coverage to compile-only matrix
eramongodb Apr 15, 2025
9a34dea
Update changelog entry
eramongodb Apr 15, 2025
46f020b
Update calc_release_version_selftest.sh for 4.0
eramongodb Apr 15, 2025
091319b
Guard patch version number comparisons on minor version number
eramongodb Apr 15, 2025
b40c68a
Merge remote-tracking branch 'upstream/master' into cxx-3103
eramongodb Apr 17, 2025
11dea97
Simplify bool -> int conversion
eramongodb Apr 18, 2025
c855dab
Remove redundant REQUIRED in find_dependency()
eramongodb Apr 18, 2025
ad9a5a8
Avoid redundant list concatenation
eramongodb Apr 18, 2025
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
99 changes: 99 additions & 0 deletions .evergreen/config_generator/components/cmake_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
from config_generator.components.funcs.fetch_c_driver_source import FetchCDriverSource
from config_generator.components.funcs.install_c_driver import InstallCDriver
from config_generator.components.funcs.install_uv import InstallUV
from config_generator.components.funcs.setup import Setup

from config_generator.etc.distros import find_small_distro
from config_generator.etc.function import Function
from config_generator.etc.utils import bash_exec

from shrub.v3.evg_build_variant import BuildVariant
from shrub.v3.evg_command import EvgCommandType
from shrub.v3.evg_task import EvgTask, EvgTaskRef

TAG = 'cmake-compat'

# pylint: disable=line-too-long
# fmt: off
MATRIX = [
("min", [3, 15, 4]),
("max-v3", [3, 31, 7]),
("max", [4, 0, 1]),
]
# fmt: on


class CMakeCompat(Function):
name = TAG
commands = [
bash_exec(
command_type=EvgCommandType.TEST,
working_dir='mongo-cxx-driver',
include_expansions_in_env=[
'CMAKE_MAJOR_VERSION',
'CMAKE_MINOR_VERSION',
'CMAKE_PATCH_VERSION',
'INSTALL_C_DRIVER',
],
script='.evergreen/scripts/cmake-compat.sh',
),
bash_exec(
command_type=EvgCommandType.TEST,
include_expansions_in_env=[
'CMAKE_MAJOR_VERSION',
'CMAKE_MINOR_VERSION',
'CMAKE_PATCH_VERSION',
'INSTALL_C_DRIVER',
],
script='mongo-cxx-driver/.evergreen/scripts/cmake-compat-check.sh',
),
]


def functions():
return CMakeCompat.defn()


def tasks():
distro_name = 'rhel80'
distro = find_small_distro(distro_name)

# Test importing C Driver libraries via both add_subdirectory() and find_package().
install_c_driver_modes = [False, True]

for name, version in MATRIX:
for install_c_driver in install_c_driver_modes:
commands = [
Setup.call(), InstallUV.call()
] + ([InstallCDriver.call() if install_c_driver else FetchCDriverSource.call()]) + [
CMakeCompat.call(
vars={
'CMAKE_MAJOR_VERSION': version[0],
'CMAKE_MINOR_VERSION': version[1],
'CMAKE_PATCH_VERSION': version[2],
'INSTALL_C_DRIVER': 1 if install_c_driver else 0,
},
),
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be simplified to?

Suggested change
commands = [
Setup.call(), InstallUV.call()
] + ([InstallCDriver.call() if install_c_driver else FetchCDriverSource.call()]) + [
CMakeCompat.call(
vars={
'CMAKE_MAJOR_VERSION': version[0],
'CMAKE_MINOR_VERSION': version[1],
'CMAKE_PATCH_VERSION': version[2],
'INSTALL_C_DRIVER': 1 if install_c_driver else 0,
},
),
]
commands = [
Setup.call(),
InstallUV.call(),
(InstallCDriver.call() if install_c_driver else FetchCDriverSource.call()),
CMakeCompat.call(
vars={
'CMAKE_MAJOR_VERSION': version[0],
'CMAKE_MINOR_VERSION': version[1],
'CMAKE_PATCH_VERSION': version[2],
'INSTALL_C_DRIVER': 1 if install_c_driver else 0,
},
),
]

You can also rewrite 1 if foo else 0 to int(foo) if foo is just a plain boolean.


if install_c_driver:
c_mode = 'find-c'
else:
c_mode = 'add-c'

yield EvgTask(
name=f'{TAG}-{name}-{c_mode}',
tags=[TAG, f'cmake-{name}', f'cmake-{c_mode}'],
run_on=distro.name,
commands=commands,
)


def variants():
return [
BuildVariant(
name=f'{TAG}-matrix',
display_name='CMake Compatibility Matrix',
tasks=[EvgTaskRef(name=f'.{TAG}')],
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@


# If updating mongoc_version_minimum, also update:
# - LIBBSON_REQUIRED_VERSION and LIBMONGOC_REQUIRED_VERSION in CMakeLists.txt
# - BSON_REQUIRED_VERSION and MONGOC_REQUIRED_VERSION in CMakeLists.txt
# - the version of pkg:github/mongodb/mongo-c-driver in etc/purls.txt
# - the default value of --c-driver-build-ref in etc/make_release.py
# Only LIBMONGOC_DOWNLOAD_VERSION needs to be updated when pinning to an unreleased commit.
# Only MONGOC_DOWNLOAD_VERSION needs to be updated when pinning to an unreleased commit.
# If pinning to an unreleased commit, create a "Blocked" JIRA ticket with
# a "depends on" link to the appropriate C Driver version release ticket.
MONGOC_VERSION_MINIMUM = 'f1e2b54090ea28b169b7d9949bd318615188d81d' # CXX-3103: bump to 2.0.0 once released.
MONGOC_VERSION_MINIMUM = '2.0.0'


class InstallCDriver(Function):
Expand Down
28 changes: 27 additions & 1 deletion .evergreen/generated_configs/functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,32 @@ functions:
args:
- -c
- etc/run-clang-tidy.sh
cmake-compat:
- command: subprocess.exec
type: test
params:
binary: bash
working_dir: mongo-cxx-driver
include_expansions_in_env:
- CMAKE_MAJOR_VERSION
- CMAKE_MINOR_VERSION
- CMAKE_PATCH_VERSION
- INSTALL_C_DRIVER
args:
- -c
- .evergreen/scripts/cmake-compat.sh
- command: subprocess.exec
type: test
params:
binary: bash
include_expansions_in_env:
- CMAKE_MAJOR_VERSION
- CMAKE_MINOR_VERSION
- CMAKE_PATCH_VERSION
- INSTALL_C_DRIVER
args:
- -c
- mongo-cxx-driver/.evergreen/scripts/cmake-compat-check.sh
compile:
command: subprocess.exec
type: test
Expand Down Expand Up @@ -397,7 +423,7 @@ functions:
type: setup
params:
updates:
- { key: mongoc_version_minimum, value: f1e2b54090ea28b169b7d9949bd318615188d81d }
- { key: mongoc_version_minimum, value: 2.0.0 }
- command: subprocess.exec
type: setup
params:
Expand Down
78 changes: 78 additions & 0 deletions .evergreen/generated_configs/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,84 @@ tasks:
vars:
cc_compiler: clang
cxx_compiler: clang++
- name: cmake-compat-max-add-c
run_on: rhel80-small
tags: [cmake-compat, cmake-max, cmake-add-c]
commands:
- func: setup
- func: install-uv
- func: fetch_c_driver_source
- func: cmake-compat
vars:
CMAKE_MAJOR_VERSION: 4
CMAKE_MINOR_VERSION: 0
CMAKE_PATCH_VERSION: 1
INSTALL_C_DRIVER: 0
- name: cmake-compat-max-find-c
run_on: rhel80-small
tags: [cmake-compat, cmake-max, cmake-find-c]
commands:
- func: setup
- func: install-uv
- func: install_c_driver
- func: cmake-compat
vars:
CMAKE_MAJOR_VERSION: 4
CMAKE_MINOR_VERSION: 0
CMAKE_PATCH_VERSION: 1
INSTALL_C_DRIVER: 1
- name: cmake-compat-max-v3-add-c
run_on: rhel80-small
tags: [cmake-compat, cmake-max-v3, cmake-add-c]
commands:
- func: setup
- func: install-uv
- func: fetch_c_driver_source
- func: cmake-compat
vars:
CMAKE_MAJOR_VERSION: 3
CMAKE_MINOR_VERSION: 31
CMAKE_PATCH_VERSION: 7
INSTALL_C_DRIVER: 0
- name: cmake-compat-max-v3-find-c
run_on: rhel80-small
tags: [cmake-compat, cmake-max-v3, cmake-find-c]
commands:
- func: setup
- func: install-uv
- func: install_c_driver
- func: cmake-compat
vars:
CMAKE_MAJOR_VERSION: 3
CMAKE_MINOR_VERSION: 31
CMAKE_PATCH_VERSION: 7
INSTALL_C_DRIVER: 1
- name: cmake-compat-min-add-c
run_on: rhel80-small
tags: [cmake-compat, cmake-min, cmake-add-c]
commands:
- func: setup
- func: install-uv
- func: fetch_c_driver_source
- func: cmake-compat
vars:
CMAKE_MAJOR_VERSION: 3
CMAKE_MINOR_VERSION: 15
CMAKE_PATCH_VERSION: 4
INSTALL_C_DRIVER: 0
- name: cmake-compat-min-find-c
run_on: rhel80-small
tags: [cmake-compat, cmake-min, cmake-find-c]
commands:
- func: setup
- func: install-uv
- func: install_c_driver
- func: cmake-compat
vars:
CMAKE_MAJOR_VERSION: 3
CMAKE_MINOR_VERSION: 15
CMAKE_PATCH_VERSION: 4
INSTALL_C_DRIVER: 1
- name: compile-only-macos-14-arm64-cxx11-debug-shared
run_on: macos-14-arm64
tags: [compile-only, macos-14-arm64, cxx11, debug, shared]
Expand Down
4 changes: 4 additions & 0 deletions .evergreen/generated_configs/variants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ buildvariants:
display_name: Clang Tidy
tasks:
- name: .clang-tidy
- name: cmake-compat-matrix
display_name: CMake Compatibility Matrix
tasks:
- name: .cmake-compat
- name: compile-only-matrix
display_name: compile-only-matrix
tasks:
Expand Down
121 changes: 121 additions & 0 deletions .evergreen/scripts/cmake-compat-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/usr/bin/env bash

set -o errexit
set -o pipefail

: "${CMAKE_MAJOR_VERSION:?}"
: "${CMAKE_MINOR_VERSION:?}"
: "${CMAKE_PATCH_VERSION:?}"
: "${INSTALL_C_DRIVER:?}"

[[ -d mongoc ]] || {
echo "missing mongoc directory"
exit 1
} >&2

[[ -d mongo-cxx-driver/install ]] || {
echo "missing mongo-cxx-driver install directory"
exit 1
} >&2

mongoc_prefix="$(pwd)/mongoc"
mongocxx_prefix="$(pwd)/mongo-cxx-driver/install"
if [[ "${OSTYPE:?}" =~ cygwin ]]; then
mongoc_prefix="$(cygpath -m "${mongoc_prefix:?}")"
mongocxx_prefix="$(cygpath -m "${mongocxx_prefix:?}")"
fi

# shellcheck source=/dev/null
. "${mongoc_prefix:?}/.evergreen/scripts/find-cmake-version.sh"
export cmake_binary
cmake_binary="$(find_cmake_version "${CMAKE_MAJOR_VERSION:?}" "${CMAKE_MINOR_VERSION:?}" "${CMAKE_PATCH_VERSION:?}")"
"${cmake_binary:?}" --version

CMAKE_BUILD_PARALLEL_LEVEL="$(nproc)"
export CMAKE_BUILD_PARALLEL_LEVEL

# Use ccache if available.
if [[ -f "${mongoc_prefix:?}/.evergreen/scripts/find-ccache.sh" ]]; then
# shellcheck source=/dev/null
. "${mongoc_prefix:?}/.evergreen/scripts/find-ccache.sh"
find_ccache_and_export_vars "$(pwd)" || true
fi

cmake_flags=(
"-Werror=dev"
"-Werror=deprecated"
"-DCMAKE_BUILD_TYPE=Debug"
"-DCMAKE_FIND_NO_INSTALL_PREFIX=ON"
)

cat >main.cpp <<DOC
#include <bsoncxx/config/version.hpp>
#include <mongocxx/config/version.hpp>

#include <mongocxx/instance.hpp>

#include <iostream>

int main() {
mongocxx::instance instance;

std::cout << "bsoncxx: " << BSONCXX_VERSION_STRING << std::endl;
std::cout << "mongocxx: " << MONGOCXX_VERSION_STRING << std::endl;
}
DOC

# Support C Driver libraries obtained via both add_subdirectory() and find_package().
if [[ "${INSTALL_C_DRIVER:?}" == 1 ]]; then
# Different install prefixes.
cmake_flags+=("-DCMAKE_PREFIX_PATH=${mongocxx_prefix:?};${mongoc_prefix:?}")
else
# Same install prefix.
cmake_flags+=("-DCMAKE_PREFIX_PATH=${mongocxx_prefix:?}")
fi

echo "Configuring with CMake flags:"
printf " - %s\n" "${cmake_flags[@]:?}"

# Test importing C++ Driver libraries using find_package().
echo "Importing C++ Driver via find_package()..."
{
cat >|CMakeLists.txt <<DOC
cmake_minimum_required(VERSION ${CMAKE_MAJOR_VERSION:?}.${CMAKE_MINOR_VERSION:?})
project(cmake-compat)

find_package(mongocxx REQUIRED)

add_executable(main main.cpp)
target_link_libraries(main PRIVATE mongo::mongocxx_shared) # + mongo::bsoncxx_shared
DOC

"${cmake_binary:?}" -S . -B build-find "${cmake_flags[@]:?}"
"${cmake_binary:?}" --build build-find --target main
./build-find/main
} &>output.txt || {
cat output.txt >&2
exit 1
}
echo "Importing C++ Driver via find_package()... done."

echo "Importing C++ Driver via add_subdirectory()..."
{
cat >|CMakeLists.txt <<DOC
cmake_minimum_required(VERSION ${CMAKE_MAJOR_VERSION:?}.${CMAKE_MINOR_VERSION:?})
project(cmake-compat)

add_subdirectory(mongoc)
add_subdirectory(mongo-cxx-driver)

add_executable(main main.cpp)
target_link_libraries(main PRIVATE mongocxx_shared) # + bsoncxx_shared
DOC

"${cmake_binary:?}" -S . -B build-add "${cmake_flags[@]:?}"
"${cmake_binary:?}" --build build-add --target main
./build-add/main
} &>output.txt || {
cat output.txt >&2
exit 1
}
echo "Importing C++ Driver via add_subdirectory()... done."
Loading