[SERVER-51084] MongoDB fails to compile on Mac with XCode 12.0 Created: 22/Sep/20  Updated: 29/Oct/23  Resolved: 25/Sep/20

Status: Closed
Project: Core Server
Component/s: Build
Affects Version/s: None
Fix Version/s: 4.8.0

Type: Bug Priority: Major - P3
Reporter: Kaloian Manassiev Assignee: Billy Donahue
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Issue split
split to SERVER-51178 Add ability to disable specific compi... Closed
Related
related to SERVER-51231 suspicious long long to double conver... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Service arch 2020-10-05
Participants:

 Description   

My Mac force-updated its XCode to 12.0 and with the Clang which comes with that version, MongoDB fails to compile with the following error:

[kaloianm@Kal-MacBook-Pro:~/workspace/mongo]$ python3 buildscripts/scons.py --ssl --variables-files=etc/scons/xcode_macosx.vars --libc++ --detect-odr-violations --dbg=on --opt=off VARIANT_DIR=ninja --ninja=next generate-ninja
...
[kaloianm@Kal-MacBook-Pro:~/workspace/mongo]$ ninja build/ninja/mongo/client/authenticate.o
[1/1] Compiling build/ninja/mongo/client/authenticate.o
FAILED: build/ninja/mongo/client/authenticate.o
PATH='/usr/local/bin:/opt/bin:/bin:/usr/bin' PATHOSX='/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin' /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ @build/ninja/mongo/client/authenticate.o.rsp
src/mongo/client/authenticate.cpp:215:29: error: loop variable 'elem' of type 'const mongo::BSONElement' creates a copy from type 'const mongo::BSONElement' [-Werror,-Wrange-loop-analysis]
            for (const auto elem : obj) {
                            ^
src/mongo/client/authenticate.cpp:215:18: note: use reference type 'const mongo::BSONElement &' to prevent copying
            for (const auto elem : obj) {
                 ^~~~~~~~~~~~~~~~~
                            &
1 error generated.

This is the clang versions that I have now:

[kaloianm@Kal-MacBook-Pro:~/workspace/mongo]$ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang --version
Apple clang version 12.0.0 (clang-1200.0.32.2)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
[kaloianm@Kal-MacBook-Pro:~/workspace/mongo]$ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ --version
Apple clang version 12.0.0 (clang-1200.0.32.2)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin



 Comments   
Comment by Andrew Morrow (Inactive) [ 05/Jan/21 ]

ryan.egesdahl - I added my thoughts on SERVER-51178. Let's continue the discussion there.

Comment by Ryan Egesdahl (Inactive) [ 04/Jan/21 ]

acm I think what we settled on was wanting to be able to add specific no-error flags to the build like this:

buildscripts/scons.py --ssl --variables-files=etc/scons/xcode_macosx.vars --libc++ --detect-odr-violations --dbg=on --opt=off --ninja --build-tools=next --disable-warnings-as-errors=range-loop-analysis VARIANT_DIR=ninja generate-ninja

The idea was that we could exclude specific warnings from being marked as errors until we could fix them but not affect anything else that might pop up. The ordering of -Wall in the arguments wasn't as much of a problem as being able to turn off specific warnings-as-errors, which weren't being added in the right place by CFLAGS/CXXFLAGS.

Comment by Andrew Morrow (Inactive) [ 04/Jan/21 ]

ryan.egesdahl - The warning flag ordering issue is a longstanding nuisance. We had a (not very detailed) ticket for that work, once: SERVER-9568. Perhaps we should re-open it, because I agree that it is surprising that adding warnings suppressions to CXXFLAGS should work. Part of the issue, IIRC, is that CCFLAGS appears after CFLAGS or CXXFLAGS on the C[XX]COM variable expansion, meaning that if we add -Werror to CCFLAGS, it will always appear later on the compile line than the warning suppression you are trying to add with via CFLAGS or CXXFLAGS. And, if won't work to add your warning suppression flag to CCFLAGS on the command line either, because we AppendUnique -Werror. However, if we instead added -Werror to both CFLAGS and CXXFLAGS via Prepend, maybe it all works?

Comment by Githook User [ 01/Oct/20 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-51084 easy XCode12 fixes (excludes the int to double fixes)
Branch: master
https://github.com/mongodb/mongo/commit/27d663f5e7b66a06e76fcef08f47121e19f3fbd6

Comment by Billy Donahue [ 01/Oct/20 ]

Everything except the rounding errors is thought-free and obvious. Doing those first.

https://mongodbcr.appspot.com/694250004/

Comment by Billy Donahue [ 30/Sep/20 ]

First commit was only to fix a basic scons invocation.

Next up is what it would take to fix remaining issues with a more full scons invocation.

buildscripts/scons.py --ssl --variables-files=etc/scons/xcode_macosx.vars --libc++ --detect-odr-violations --dbg=on --opt=off --ninja --build-tools=next VARIANT_DIR=ninja generate-ninja

https://mongodbcr.appspot.com/663460026/

But we have to deal with what looks like a true positive warning about implicit int64->double conversions.
SERVER-51231

Comment by Githook User [ 25/Sep/20 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-51084 tweak range loop variable types to fix xcode build
Branch: master
https://github.com/mongodb/mongo/commit/deb9f8e6bf9517061404cf2f476cd08f60687d83

Comment by Billy Donahue [ 24/Sep/20 ]

CR https://mongodbcr.appspot.com/682650001/

Comment by Billy Donahue [ 24/Sep/20 ]

This is now personally screwing me up. I'm gong to just try to sweep the codebase and add & to loop variables to fix it.

Comment by Ryan Egesdahl (Inactive) [ 22/Sep/20 ]

It's possible that this would have worked except that the order of the flags is preventing it. We may simply need to add the flag after "-Wall" appears on the command line. Perhaps we should introduce a mechanism that allows us to disable specific errors and not just all of them?

Comment by Kaloian Manassiev [ 22/Sep/20 ]

On Slack ryan.egesdahl suggested that I try with the -Wno-error=range-loop-analysis compiler flag, but this doesn't seem to work:

[kaloianm@Kal-MacBook-Pro:~/workspace/mongo]$ python3 buildscripts/scons.py --ssl --variables-files=etc/scons/xcode_macosx.vars --libc++ --detect-odr-violations --dbg=on --opt=off VARIANT_DIR=ninja CXXFLAGS="-Wno-error=range-loop-analysis" --ninja=next generate-ninja
...
[kaloianm@Kal-MacBook-Pro:~/workspace/mongo]$ ninja build/ninja/mongo/client/authenticate.o
[1/1] Compiling build/ninja/mongo/client/authenticate.o
FAILED: build/ninja/mongo/client/authenticate.o
PATH='/usr/local/bin:/opt/bin:/bin:/usr/bin' PATHOSX='/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin' /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ @build/ninja/mongo/client/authenticate.o.rsp
src/mongo/client/authenticate.cpp:215:29: error: loop variable 'elem' of type 'const mongo::BSONElement' creates a copy from type 'const mongo::BSONElement' [-Werror,-Wrange-loop-analysis]
            for (const auto elem : obj) {
                            ^
src/mongo/client/authenticate.cpp:215:18: note: use reference type 'const mongo::BSONElement &' to prevent copying
            for (const auto elem : obj) {
                 ^~~~~~~~~~~~~~~~~
                            &
1 error generated.
ninja: build stopped: subcommand failed.

I can see in build.ninja that the flag has been reflected:

build build/ninja/mongo/client/authenticate.o: CXX src/mongo/client/authenticate.cpp | $
    src/mongo/client/authenticate.cpp || _generated_sources
  rspc = -o build/ninja/mongo/client/authenticate.o -c -Wno-error=range-loop-analysis $
      -Woverloaded-virtual -Werror=unused-result -Wpessimizing-move -Wredundant-move $
      -Wno-undefined-var-template -Wno-instantiation-after-specialization -fsized-deallocation $
      -Wno-defaulted-function-deleted -Wunused-exception-parameter -stdlib=libc++ -std=c++17 $
      -isysroot $
      /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk $
      -mmacosx-version-min=10.13 -target darwin17.0.0 -arch x86_64 -fno-omit-frame-pointer $
      -fno-strict-aliasing -fasynchronous-unwind-tables -ggdb -pthread -Wall -Wsign-compare $
      -Wno-unknown-pragmas -Winvalid-pch -Werror -O0 -Wno-unused-local-typedefs $
      -Wno-unused-function -Wno-unused-private-field -Wno-deprecated-declarations $
      -Wno-tautological-constant-out-of-range-compare -Wno-tautological-constant-compare $
      -Wno-tautological-unsigned-zero-compare -Wno-tautological-unsigned-enum-zero-compare $
      -Wno-unused-const-variable -Wno-missing-braces -Wno-inconsistent-missing-override $
      -Wno-potentially-evaluated-expression -Wno-unused-lambda-capture -Wno-exceptions $
      -Wunguarded-availability -fstack-protector-strong -fno-builtin-memcmp -MMD -MF $
      build/ninja/mongo/client/authenticate.o.d -DSAFEINT_USE_INTRINSICS=0 -DPCRE_STATIC $
      -DBOOST_THREAD_VERSION=5 -DBOOST_THREAD_USES_DATETIME -DBOOST_SYSTEM_NO_DEPRECATED $
      -DBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS -DBOOST_ENABLE_ASSERT_DEBUG_HANDLER $
      -DBOOST_LOG_NO_SHORTHAND_NAMES -DBOOST_LOG_USE_NATIVE_SYSLOG $
      -DBOOST_LOG_WITHOUT_THREAD_ATTR -DABSL_FORCE_ALIGNED_ACCESS $
      -Isrc/third_party/variant-1.4.0/include -Isrc/third_party/SafeInt $
      -Isrc/third_party/pcre-8.42 -Isrc/third_party/fmt/dist/include $
      -Isrc/third_party/boost-1.70.0 -Isrc/third_party/abseil-cpp-master/abseil-cpp -Ibuild/ninja $
      -Isrc src/mongo/client/authenticate.cpp
  CXX = $
      /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
  env = PATH='/usr/local/bin:/opt/bin:/bin:/usr/bin' $
      PATHOSX='/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin'

Generated at Thu Feb 08 05:24:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.