Skip to content

CXX-2577 compile and test with c++20 #968

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 15 commits into from
May 30, 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
11 changes: 4 additions & 7 deletions .evergreen/build_example_projects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,25 @@ else
DIR=shared
fi

. .evergreen/find_cmake.sh
export CMAKE="$CMAKE"

cd examples/projects

for project in bsoncxx mongocxx; do
(
cd $project

if ! ( cd cmake/$DIR && ./build.sh >|output.txt 2>&1); then
cat output.txt 1>&2
cat cmake/$DIR/output.txt 1>&2
exit 1
fi

if ! ( cd cmake-deprecated/$DIR && ./build.sh >|output.txt 2>&1); then
cat output.txt 1>&2
cat cmake-deprecated/$DIR/output.txt 1>&2
exit 1
fi

if [ "Windows_NT" != "$OS" ]; then
if [[ ! ( "$OSTYPE" =~ cygwin ) ]]; then
if ! ( cd pkg-config/$DIR && ./build.sh >|output.txt 2>&1); then
cat output.txt 1>&2
cat pkg-config/$DIR/output.txt 1>&2
exit 1
fi
fi
Expand Down
12 changes: 5 additions & 7 deletions .evergreen/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ case "$OS" in
;;
esac

. .evergreen/find_cmake.sh

cd build
"$CMAKE" -G "$GENERATOR" "-DCMAKE_BUILD_TYPE=${BUILD_TYPE}" -DMONGOCXX_ENABLE_SLOW_TESTS=ON -DENABLE_UNINSTALL=ON "$@" ..
"$CMAKE" --build . --config $BUILD_TYPE -- $CMAKE_BUILD_OPTS
"$CMAKE" --build . --config $BUILD_TYPE --target install -- $CMAKE_BUILD_OPTS
"$CMAKE" --build . --config $BUILD_TYPE --target $CMAKE_EXAMPLES_TARGET -- $CMAKE_BUILD_OPTS
"${cmake_binary}" -G "$GENERATOR" "-DCMAKE_BUILD_TYPE=${BUILD_TYPE}" -DMONGOCXX_ENABLE_SLOW_TESTS=ON -DENABLE_UNINSTALL=ON "$@" ..
"${cmake_binary}" --build . --config $BUILD_TYPE -- $CMAKE_BUILD_OPTS
"${cmake_binary}" --build . --config $BUILD_TYPE --target install -- $CMAKE_BUILD_OPTS
"${cmake_binary}" --build . --config $BUILD_TYPE --target $CMAKE_EXAMPLES_TARGET -- $CMAKE_BUILD_OPTS

if [ "$_RUN_DISTCHECK" ]; then
DISTCHECK_BUILD_OPTS="-j$CONCURRENCY" "$CMAKE" --build . --config $BUILD_TYPE --target distcheck
DISTCHECK_BUILD_OPTS="-j$CONCURRENCY" "${cmake_binary}" --build . --config $BUILD_TYPE --target distcheck
fi
116 changes: 108 additions & 8 deletions .mci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ functions:
git clone [email protected]:mongodb-labs/drivers-evergreen-tools.git
fi
cd drivers-evergreen-tools
# The legacy shell is only present in server 5.0 builds and earlier,
# but there is no 5.0 build for RHEL9, so we have to avoid it
if [[ "${build_variant}" =~ "rhel9" ]]; then
export SKIP_LEGACY_SHELL=1
fi
export DRIVERS_TOOLS=$(pwd)
if [ "Windows_NT" == "$OS" ]; then
export DRIVERS_TOOLS=$(cygpath -m $DRIVERS_TOOLS)
Expand Down Expand Up @@ -351,6 +356,7 @@ functions:
params:
shell: bash
working_dir: "mongo-cxx-driver"
include_expansions_in_env: ["distro_id"]
script: |
set -o errexit
set -o pipefail
Expand All @@ -367,13 +373,20 @@ functions:
ADDL_OPTS="$ADDL_OPTS -DENABLE_TESTS=OFF"
fi

if [[ -n "${REQUIRED_CXX_STANDARD}" ]]; then
ADDL_OPTS="$ADDL_OPTS -DCMAKE_CXX_STANDARD=${REQUIRED_CXX_STANDARD} -DCMAKE_CXX_STANDARD_REQUIRED=ON"
fi

MONGOC_PREFIX="$(pwd)/../mongoc"
echo "MONGOC_PREFIX=$MONGOC_PREFIX"

if [ "Windows_NT" == "$OS" ]; then
if [[ "$OSTYPE" =~ cygwin ]]; then
MONGOC_PREFIX=$(cygpath -m "$MONGOC_PREFIX")
fi
export CMAKE=${cmake}
. "$MONGOC_PREFIX/.evergreen/scripts/find-cmake-latest.sh"
declare cmake_binary
export cmake_binary="$(find_cmake_latest)"
command -v "$cmake_binary"

if [ ! -d ../drivers-evergreen-tools ]; then
git clone --depth 1 [email protected]:mongodb-labs/drivers-evergreen-tools.git ../drivers-evergreen-tools
Expand All @@ -398,14 +411,15 @@ functions:
params:
shell: bash
working_dir: "mongo-cxx-driver"
include_expansions_in_env: ["distro_id"]
script: |
set -o errexit
set -o pipefail

# Grabs the mongocryptd path
pushd ..
export MONGOCRYPTD_PATH=$(pwd)/
if [ "Windows_NT" == "$OS" ]; then
if [[ "$OSTYPE" =~ cygwin ]]; then
export MONGOCRYPTD_PATH=$(cygpath -m $MONGOCRYPTD_PATH)
fi
popd # ..
Expand Down Expand Up @@ -453,7 +467,7 @@ functions:

pushd ../../drivers-evergreen-tools
export DRIVERS_TOOLS=$(pwd)
if [ "Windows_NT" == "$OS" ]; then
if [[ "$OSTYPE" =~ cygwin ]]; then
export DRIVERS_TOOLS=$(cygpath -m $DRIVERS_TOOLS)
fi
popd # ../../drivers-evergreen-tools
Expand Down Expand Up @@ -514,7 +528,7 @@ functions:
register_ca_cert() {
local OS=$(uname -s | tr '[:upper:]' '[:lower:]')
echo "register_ca_cert: OS: $OS"
case "$OS" in
case "$OSTYPE" in
cygwin*)
certutil.exe -addstore "Root" "$DRIVERS_TOOLS\.evergreen\x509gen\ca.pem"
;;
Expand Down Expand Up @@ -559,7 +573,7 @@ functions:
echo "Waiting for mock KMS servers to start... done."
fi

if [ "Windows_NT" == "$OS" ]; then
if [[ "$OSTYPE" =~ cygwin ]]; then
CTEST_OUTPUT_ON_FAILURE=1 MSBuild.exe /p:Configuration=${build_type} /verbosity:minimal RUN_TESTS.vcxproj
# Only run examples if MONGODB_API_VERSION is unset. We do not append
# API version to example clients, so examples will fail when requireApiVersion
Expand Down Expand Up @@ -660,8 +674,7 @@ functions:
export CC="${example_projects_cc}"
export CXX="${example_projects_cxx}"
export CXX_STANDARD="${example_projects_cxx_standard}"
export CMAKE=${cmake}
if [ "Windows_NT" == "$OS" ]; then
if [[ "$OSTYPE" =~ cygwin ]]; then
export MSVC=1
elif [ "$(uname -s | tr '[:upper:]' '[:lower:]')" == "darwin" ]; then
export DYLD_LIBRARY_PATH="$(pwd)/build/install/lib:$DYLD_LIBRARY_PATH"
Expand All @@ -680,6 +693,10 @@ functions:
# is true.
if [[ -z "$MONGODB_API_VERSION" ]]; then
echo "Building example projects..."
. "$PREFIX/.evergreen/scripts/find-cmake-latest.sh"
declare cmake_binary
export cmake_binary="$(find_cmake_latest)"
command -v "$cmake_binary"
.evergreen/build_example_projects.sh
echo "Building example projects... done."
fi
Expand Down Expand Up @@ -839,6 +856,39 @@ tasks:
- func: "run_kms_servers"
- func: "test"

- name: compile_and_test_with_shared_libs_cxx20
commands:
- func: "setup"
- func: "start_mongod"
- func: "install_c_driver"
- func: "compile"
vars:
RUN_DISTCHECK: 1
REQUIRED_CXX_STANDARD: 20
- func: "clone_drivers-evergreen-tools"
- func: "run_kms_servers"
- func: "test"
vars:
REQUIRED_CXX_STANDARD: 20
example_projects_cxx_standard: 20

- name: compile_and_test_with_shared_libs_extra_alignment_cxx20
commands:
- func: "setup"
- func: "start_mongod"
- func: "install_c_driver"
vars:
BSON_EXTRA_ALIGNMENT: 1
- func: "compile"
vars:
REQUIRED_CXX_STANDARD: 20
- func: "clone_drivers-evergreen-tools"
- func: "run_kms_servers"
- func: "test"
vars:
REQUIRED_CXX_STANDARD: 20
example_projects_cxx_standard: 20

- name: compile_with_shared_libs
commands:
- func: "setup"
Expand Down Expand Up @@ -1171,6 +1221,52 @@ buildvariants:
#######################################
# Linux Buildvariants #
#######################################
- name: rhel9-release-latest
display_name: "RHEL 9 Release (MongoDB Latest)"
expansions:
build_type: "Release"
tar_options: *linux_tar_options
extra_path: *linux_extra_path
cmake_flags: *linux_cmake_flags
mongodb_version: *version_latest
lib_dir: "lib64"
run_on:
- rhel90-large
tasks:
- name: compile_and_test_with_shared_libs
- name: compile_and_test_with_shared_libs_extra_alignment
- name: compile_and_test_with_shared_libs_cxx20
- 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: build_example_with_add_subdirectory
distros:
- rhel90-large

- name: arm-rhel9-release-latest
display_name: "arm64 RHEL 9 Release (MongoDB Latest)"
expansions:
build_type: "Release"
tar_options: *linux_tar_options
extra_path: *linux_extra_path
cmake_flags: *linux_cmake_flags
mongodb_version: *version_latest
lib_dir: "lib64"
run_on:
- rhel90-arm64-large
tasks:
- name: compile_and_test_with_shared_libs
- name: compile_and_test_with_shared_libs_extra_alignment
- name: compile_and_test_with_shared_libs_cxx20
- 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: build_example_with_add_subdirectory
distros:
- rhel90-arm64-large

- name: debian11-release-latest
display_name: "Debian 11 Release (MongoDB Latest)"
expansions:
Expand All @@ -1184,6 +1280,8 @@ buildvariants:
tasks:
- name: compile_and_test_with_shared_libs
- name: compile_and_test_with_shared_libs_extra_alignment
- name: compile_and_test_with_shared_libs_cxx20
- 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
Expand All @@ -1205,6 +1303,8 @@ buildvariants:
tasks:
- name: compile_and_test_with_shared_libs
- name: compile_and_test_with_shared_libs_extra_alignment
- name: compile_and_test_with_shared_libs_cxx20
- 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
Expand Down
15 changes: 8 additions & 7 deletions cmake/BsoncxxUtil.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ function(bsoncxx_add_library TARGET OUTPUT_NAME LINK_TYPE)
$<BUILD_INTERFACE:${source_dir}/include>
$<BUILD_INTERFACE:${CMAKE_INSTALL_PREFIX}/${BSONCXX_HEADER_INSTALL_DIR}>
)
elseif(BSONCXX_POLY_USE_BOOST)
if (CMAKE_VERSION VERSION_LESS 3.15.0)
target_include_directories(${TARGET} PUBLIC ${Boost_INCLUDE_DIRS})
else()
target_link_libraries(${TARGET} PUBLIC Boost::boost)
endif()
elseif(BSONCXX_POLY_USE_BOOST)
find_package(Boost 1.56.0 REQUIRED)
if(CMAKE_VERSION VERSION_LESS 3.15.0)
target_include_directories(${TARGET} PUBLIC ${Boost_INCLUDE_DIRS})
else()
target_link_libraries(${TARGET} PUBLIC Boost::boost)
endif()
endif()

target_link_libraries(${TARGET} PRIVATE ${libbson_target})
Expand All @@ -66,7 +67,7 @@ endfunction(bsoncxx_add_library)

# Install the specified forms of the bsoncxx library (i.e., shared and/or static)
# with associated CMake config files
function(bsoncxx_install BSONCXX_TARGET_LIST BSONCXX_PKG_DEP)
function(bsoncxx_install BSONCXX_TARGET_LIST BSONCXX_PKG_DEP BSONCXX_BOOST_PKG_DEP)
install(TARGETS
${BSONCXX_TARGET_LIST}
EXPORT bsoncxx_targets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -o pipefail

BUILD_TYPE=${BUILD_TYPE:-Release}
CXX_STANDARD=${CXX_STANDARD:-11}
CMAKE=${CMAKE:-cmake}
CMAKE=${cmake_binary:-cmake}

rm -rf build/*
cd build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -o pipefail

BUILD_TYPE=${BUILD_TYPE:-Release}
CXX_STANDARD=${CXX_STANDARD:-11}
CMAKE=${CMAKE:-cmake}
CMAKE=${cmake_binary:-cmake}

rm -rf build/*
cd build
Expand Down
2 changes: 1 addition & 1 deletion examples/projects/bsoncxx/cmake/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ add_executable(hello_bsoncxx ../../hello_bsoncxx.cpp)

# Visual Studio pre 2017 requires boost polyfill.
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
if (CXX_STANDARD LESS 17)
if (CMAKE_CXX_STANDARD LESS 17)
find_package(Boost 1.56.0 REQUIRED)
if (CMAKE_VERSION VERSION_LESS 3.15.0)
target_include_directories(hello_bsoncxx PRIVATE ${Boost_INCLUDE_DIRS})
Expand Down
2 changes: 1 addition & 1 deletion examples/projects/bsoncxx/cmake/shared/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -o pipefail

BUILD_TYPE=${BUILD_TYPE:-Release}
CXX_STANDARD=${CXX_STANDARD:-11}
CMAKE=${CMAKE:-cmake}
CMAKE=${cmake_binary:-cmake}

rm -rf build/*
cd build
Expand Down
2 changes: 1 addition & 1 deletion examples/projects/bsoncxx/cmake/static/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ add_executable(hello_bsoncxx ../../hello_bsoncxx.cpp)

# Visual Studio pre 2017 requires boost polyfill.
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
if (CXX_STANDARD LESS 17)
if (CMAKE_CXX_STANDARD LESS 17)
find_package(Boost 1.56.0 REQUIRED)
if (CMAKE_VERSION VERSION_LESS 3.15.0)
target_include_directories(hello_bsoncxx PRIVATE ${Boost_INCLUDE_DIRS})
Expand Down
2 changes: 1 addition & 1 deletion examples/projects/bsoncxx/cmake/static/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -o pipefail

BUILD_TYPE=${BUILD_TYPE:-Release}
CXX_STANDARD=${CXX_STANDARD:-11}
CMAKE=${CMAKE:-cmake}
CMAKE=${cmake_binary:-cmake}

rm -rf build/*
cd build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -o pipefail

BUILD_TYPE=${BUILD_TYPE:-Release}
CXX_STANDARD=${CXX_STANDARD:-11}
CMAKE=${CMAKE:-cmake}
CMAKE=${cmake_binary:-cmake}

rm -rf build/*
cd build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -o pipefail

BUILD_TYPE=${BUILD_TYPE:-Release}
CXX_STANDARD=${CXX_STANDARD:-11}
CMAKE=${CMAKE:-cmake}
CMAKE=${cmake_binary:-cmake}

rm -rf build/*
cd build
Expand Down
2 changes: 1 addition & 1 deletion examples/projects/mongocxx/cmake/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ add_executable(hello_mongocxx ../../hello_mongocxx.cpp)

# Visual Studio pre 2017 requires boost polyfill.
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
if (CXX_STANDARD LESS 17)
if (CMAKE_CXX_STANDARD LESS 17)
find_package(Boost 1.56.0 REQUIRED)
if (CMAKE_VERSION VERSION_LESS 3.15.0)
target_include_directories(hello_mongocxx PRIVATE ${Boost_INCLUDE_DIRS})
Expand Down
2 changes: 1 addition & 1 deletion examples/projects/mongocxx/cmake/shared/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -o pipefail

BUILD_TYPE=${BUILD_TYPE:-Release}
CXX_STANDARD=${CXX_STANDARD:-11}
CMAKE=${CMAKE:-cmake}
CMAKE=${cmake_binary:-cmake}

rm -rf build/*
cd build
Expand Down
2 changes: 1 addition & 1 deletion examples/projects/mongocxx/cmake/static/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ add_executable(hello_mongocxx ../../hello_mongocxx.cpp)

# Visual Studio pre 2017 requires boost polyfill.
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
if (CXX_STANDARD LESS 17)
if (CMAKE_CXX_STANDARD LESS 17)
find_package(Boost 1.56.0 REQUIRED)
if (CMAKE_VERSION VERSION_LESS 3.15.0)
target_include_directories(hello_mongocxx PRIVATE ${Boost_INCLUDE_DIRS})
Expand Down
Loading