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 5 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
17 changes: 7 additions & 10 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
if ! ( cd cmake/$DIR && ./build.sh "$@" >|output.txt 2>&1); then
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
if ! ( cd cmake-deprecated/$DIR && ./build.sh "$@" >|output.txt 2>&1); then
cat cmake-deprecated/$DIR/output.txt 1>&2
exit 1
fi

if [ "Windows_NT" != "$OS" ]; then
if ! ( cd pkg-config/$DIR && ./build.sh >|output.txt 2>&1); then
cat output.txt 1>&2
if [[ ! ( "$OSTYPE" =~ cygwin ) ]]; then
if ! ( cd pkg-config/$DIR && ./build.sh "$@" >|output.txt 2>&1); then
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}" -DCMAKE_VERBOSE_MAKEFILE=ON -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
71 changes: 63 additions & 8 deletions .mci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ functions:
export BUILD_TYPE=${build_type}
export PATH="${extra_path}:$PATH"
export RUN_DISTCHECK=${RUN_DISTCHECK}
# distro_id is needed by find-cmake-version.sh, but we don't
# want to use add_expansions_to_env
export distro_id=${distro_id}

ADDL_OPTS=${code_coverage_cmake_flags}
if [ "${USE_STATIC_LIBS}" ]; then
Expand All @@ -367,13 +370,20 @@ functions:
ADDL_OPTS="$ADDL_OPTS -DENABLE_TESTS=OFF"
fi

if [ "${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 Down Expand Up @@ -402,10 +412,13 @@ functions:
set -o errexit
set -o pipefail

# distro_id is needed by find-cmake-version.sh, but we don't
# want to use add_expansions_to_env
export distro_id=${distro_id}
# 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 +466,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 +527,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 +572,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 +673,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 @@ -679,7 +691,15 @@ functions:
# API version to example clients, so example projects will fail when requireApiVersion
# is true.
if [[ -z "$MONGODB_API_VERSION" ]]; then
if [ "${REQUIRED_CXX_STANDARD}" ]; then
ADDL_OPTS="$ADDL_OPTS -DCMAKE_CXX_STANDARD=${REQUIRED_CXX_STANDARD} -DCMAKE_CXX_STANDARD_REQUIRED=ON"
CXX_STANDARD=${REQUIRED_CXX_STANDARD}
fi
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 +859,37 @@ 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

- 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

- name: compile_with_shared_libs
commands:
- func: "setup"
Expand Down Expand Up @@ -1184,6 +1235,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 +1258,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
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
2 changes: 1 addition & 1 deletion examples/projects/mongocxx/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
8 changes: 8 additions & 0 deletions src/bsoncxx/document/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,17 @@ class BSONCXX_API value {
std::size_t _length{0};
};

#if defined(__GNUC__) && (__cplusplus >= 201709L)
// Silence false positive with g++ 10.2.1 on Debian 11.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
BSONCXX_INLINE document::view value::view() const noexcept {
return document::view{static_cast<uint8_t*>(_data.get()), _length};
}
#if defined(__GNUC__) && (__cplusplus >= 201709L)
#pragma GCC diagnostic pop
#endif

BSONCXX_INLINE value::operator document::view() const noexcept {
return view();
Expand Down
8 changes: 8 additions & 0 deletions src/mongocxx/options/private/transaction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,21 @@ class transaction::impl {
libmongoc::transaction_opts_set_max_commit_time_ms(_transaction_opt_t.get(), ms.count());
}

#if defined(__GNUC__) && (__cplusplus >= 201709L)
// Silence false positive with g++ 10.2.1 on Debian 11.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
stdx::optional<std::chrono::milliseconds> max_commit_time_ms() const {
auto ms = libmongoc::transaction_opts_get_max_commit_time_ms(_transaction_opt_t.get());
if (!ms) {
return {};
}
return {std::chrono::milliseconds{ms}};
}
#if defined(__GNUC__) && (__cplusplus >= 201709L)
#pragma GCC diagnostic pop
#endif

mongoc_transaction_opt_t* get_transaction_opt_t() const noexcept {
return _transaction_opt_t.get();
Expand Down
2 changes: 1 addition & 1 deletion src/mongocxx/test_util/mock.hh
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class mock<R (*)(Args...)> {

// Visiting functions get called in addition to the original C-Driver function
rule& visit(std::function<void(Args...)> func) {
_callbacks.emplace([=](Args... args) {
_callbacks.emplace([this, func](Args... args) {
func(args...);
return _parent->_func(args...);
});
Expand Down