[SERVER-85779] Build failure with C++20 due to use of unary_function in boost Created: 26/Jan/24  Updated: 30/Jan/24

Status: Needs Scheduling
Project: Core Server
Component/s: None
Affects Version/s: 7.0.5
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Ryan Schmidt Assignee: Thomas Langston
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-85763 Build failure with Xcode 15 Needs Scheduling
Assigned Teams:
Build
Operating System: ALL
Steps To Reproduce:

% tar xzf mongodb-src-r7.0.5.tar.gz
% cd mongodb-src-r7.0.5
% python3.11 -m venv venv
% venv/bin/python3.11 -m pip install -r etc/pip/compile-requirements.txt
...
% venv/bin/python3.11 buildscripts/scons.py install-mongod --disable-warnings-as-errors=configure --disable-warnings-as-errors=source
Checking required python packages...
Requirements list:
...
Resolved to these distributions:
...
scons: Reading SConscript files ...
scons: running with args /Users/me/mongodb-src-r7.0.5/venv/bin/python3.11 buildscripts/scons.py install-mongod --disable-warnings-as-errors=configure --disable-warnings-as-errors=source
WARNING: The build_metrics tool might not work as intended due to a failed import:
No module named 'jsonschema'
scons version: 3.1.2
python version: 3 11 7 'final' 0
Mkdir("build/tmp_test_data")
CC is gcc
gcc found in $PATH at /usr/bin/gcc
CXX is g++
g++ found in $PATH at /usr/bin/g++
Checking if dev env is valid... skipped
Checking if C++ compiler "g++" is GCC... no
Checking if C++ compiler "g++" is clang... yes
Checking if C compiler "gcc" is clang... yes
Detected a aarch64 processor
Checking if target OS macOS is supported by the toolchain... yes
Checking if C compiler is clang 12.0 (or Apple XCode 13.0) or newer...yes
Checking if C++ compiler is clang 12.0 (or Apple XCode 13.0) or newer...yes
Checking for sufficient macOS target version minimum... yes
Checking whether the C compiler works... yes
Checking whether the C++ compiler works... yes
Checking that the C++ compiler can link a C++ program... yes
Checking if C compiler supports -Wno-unused-local-typedefs... yes
Checking if C compiler supports -Wno-unused-function... yes
Checking if C compiler supports -Wno-unused-private-field... yes
Checking if C compiler supports -Wno-deprecated-declarations... yes
Checking if C compiler supports -Wno-tautological-constant-out-of-range-compare... yes
Checking if C compiler supports -Wno-tautological-constant-compare... yes
Checking if C compiler supports -Wno-tautological-unsigned-zero-compare... yes
Checking if C compiler supports -Wno-tautological-unsigned-enum-zero-compare... yes
Checking if C compiler supports -Wno-unused-const-variable... yes
Checking if C compiler supports -Wno-unused-but-set-variable... yes
Checking if C compiler supports -Wno-missing-braces... yes
Checking if C compiler supports -Wno-inconsistent-missing-override... yes
Checking if C compiler supports -Wno-potentially-evaluated-expression... yes
Checking if C++ compiler supports -Wpessimizing-move... yes
Checking if C++ compiler supports -Wno-maybe-uninitialized... no
Checking if C++ compiler supports -Wno-undefined-var-template... yes
Checking if C++ compiler supports -Wno-instantiation-after-specialization... yes
Checking if C compiler supports -Wno-unused-lambda-capture... yes
Checking if C++ compiler supports -fsized-deallocation... yes
Checking if C++ compiler supports -Wno-defaulted-function-deleted... yes
Checking if C++ compiler supports -Wunused-exception-parameter... yes
Checking if C++ compiler supports -Wno-deprecated... yes
Checking if C++ compiler supports -Wno-deprecated-builtins... yes
Checking if -Wnon-virtual-dtor works reasonably... no
Checking if C compiler supports -Wunguarded-availability... yes
Checking if C compiler supports -fstack-protector-strong... yes
Checking if we are using libstdc++... no
Checking if C++ compiler supports -std=c++20... yes
Checking if C compiler supports -std=c11... yes
Checking for C++20... yes
...
In file included from src/mongo/idl/cluster_server_parameter_op_observer.cpp:30:
In file included from src/mongo/idl/cluster_server_parameter_op_observer.h:35:
In file included from src/mongo/db/client.h:43:
In file included from src/mongo/db/service_context.h:39:
In file included from src/mongo/db/session/logical_session_id.h:32:
In file included from src/third_party/boost/boost/functional/hash.hpp:6:
src/third_party/boost/boost/container_hash/hash.hpp:132:33: error: no template named 'unary_function' in namespace 'std'; did you mean '__unary_function'?
        struct hash_base : std::unary_function<T, std::size_t> {};
                           ~~~~~^~~~~~~~~~~~~~
                                __unary_function
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__functional/unary_function.h:46:1: note: '__unary_function' declared here
using __unary_function = __unary_function_keep_layout_base<_Arg, _Result>;
^

Participants:

 Description   

Building mongodb 7.0.5 on macOS 14.2.1 with Xcode 15.2 fails because you appear to be using C++20 mode and your bundled boost uses 

std::unary_function

which was removed from the language as of C++17. 

See https://github.com/boostorg/functional/pull/21



 Comments   
Comment by Daniel Moody [ 30/Jan/24 ]

boost officially added this define to there configuration in boost >= 1.80.0, so we should add this as always defined in our build and/or upgrade boost: https://github.com/boostorg/config/commit/a7cfad38eae88cf72da8bffadd6098980f427ff7

Comment by Ryan Schmidt [ 27/Jan/24 ]

Thank you, that suggestion does work around the bug. Can you make your build system apply that automatically so users don't have to specify it manually?

I may be wrong about it affecting all macOS versions. What I meant is it is not dependent on the OS version; it's dependent on the compiler. The compilers in some versions of Xcode might not have this issue, but for example a user on macOS 13 could experience the problem if they upgrade to Xcode 15 (and recall that Apple loves pushing out updates to App Store apps automatically) or a user on any OS could experience the problem if they use a newer clang that they've installed separately.

Comment by Ryan Schmidt [ 26/Jan/24 ]

Thanks, I will try your suggestion.

The issue affects all macOS versions.

Comment by Daniel Moody [ 26/Jan/24 ]

ryandesign Also note that macos 14 is not "supported" platform for mongodb 7.0, but it may still work, we just don't have test coverage for it yet

Comment by Daniel Moody [ 26/Jan/24 ]

ryandesign to workaround this issue, you can add the argument on the scons command line:

CPPDEFINES=BOOST_NO_CXX98_FUNCTION_BASE

This will cause boost to not try to use that function.

Generated at Thu Feb 08 06:58:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.