[SERVER-44592] Can't build server with --use-system-mongo-c Created: 13/Nov/19  Updated: 27/Oct/23  Resolved: 19/Nov/19

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

Type: Bug Priority: Minor - P4
Reporter: Ryan Schmidt Assignee: Andrew Morrow (Inactive)
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

/opt/local/bin/python3.7 buildscripts/scons.py CC=/opt/local/bin/clang-mp-7.0 CXX=/opt/local/bin/clang++-mp-7.0 --use-system-mongo-c

Sprint: Dev Platform 2019-12-02
Participants:

 Description   

Hi, on macOS 10.13.6 with Xcode 9.4.1, I tried building mongodb 4.2.1 with --use-system-mongo-c. I have mongo-c-driver 1.15.2 installed with MacPorts. The build failed with:

Checking for mongoc_get_major_version() in C library mongoc-1.0... (cached) no
Checking for mongoc_get_major_version() in darwin framework mongoc...(cached) no
Failed to find the required C driver headers

It builds fine using the bundled mongoc if I don't useĀ --use-system-mongo-c.



 Comments   
Comment by Andrew Morrow (Inactive) [ 19/Nov/19 ]

ryandesign - I agree, it is a bit of an unusual situation regarding building mongoc_embedded. The reason it is a little unusual is that this mongoc_embedded is specialized code that interoperates with the MongoDB C driver, such that the C driver can be connected to the library version of MongoDB, mongo_embedded. The assumption is that if you don't have a C driver available, there isn't any need to have the embedded extension either. Ideally, this code would live in the mongo-c-driver repository, not here. However, the future of mongo_embedded is uncertain, so we don't want to move it just to kill it off. So for now it is staying put.

Regarding making better use of pkgconfig, I agree that this would be valuable. Would you mind filing a ticket? There is a lot of build system work that needs to be done for MongoDB, so I can't promise we will get to it soon. In the meantime, my recommendation would be that you build with --use-system-mongo-c=off (as you indicated you would do), and that you add any necessary paths explicitly to CPPPATH and LIBPATH.

Given that this works by design (for better or worse), I'm going to close this ticket, but do let me know if there is more that I can help with here.

Comment by Ryan Schmidt [ 16/Nov/19 ]

Thank you for the explanations! There's a lot of good information there that I didn't know. There may be an opportunity here to improve the build system.

I didn't know that there wasn't a bundled copy of mongo-c-driver and thatĀ --use-system-mongo-c controlled whether mongoc_embedded gets built at all. That's unexpected. I had expected it to be like the other --use-system-... flags which, as far as I know, merely select between using a bundled library or a system copy of the library. It might be easier to understand if the option were renamed to something like --enable-mongoc-embedded.

I should mention that I'm encountering these issues in the process of updating the MacPorts mongodb port from 4.0.x to 4.2.x. Years ago, around the time of mongodb 3.0.3, I had run into a problem where mongodb would fail to build if the then-current version of libbson and/or mongo-c-driver was installed. I assumed at the time that the libbson/mongo-c-driver and mongodb release schedules were not aligned, and that mongodb included a bundled copy of a different version of libbson/mongo-c-driver with which it was compatible, and I marked this conflict in our mongodb port with the intention of coming back to it some day, which turned out to be now.

I don't specifically want mongoc_embedded, so I will use --use-system-mongo-c=off. Automatic checks are great for users who build manually, but are not so great for MacPorts because we want to be very specific about what we build. We don't want some optional feature to become enabled on some user's system just because they had some library installed. So I will look through the other available options and make sure we're explicitly enabling or disabling everything the way we want it.

In MacPorts we do specify CPPPATH and LIBPATH; I forgot to mention that. And if I add /opt/local/include/libmongoc-1.0 /opt/local/include/libbson-1.0 to CPPPATH then it does find mongo-c-driver. But it's unexpected that I should have to specify that manually; mongodb should get whatever flags it needs from its dependencies' pkg-config files.

Comment by Andrew Morrow (Inactive) [ 13/Nov/19 ]

Hi ryandesign -

You don't need the C driver to build standard MongoDB, and there isn't a bundled copy of it in the tree - the only option is to use the system copy. That check is only there in case you want to build the code under src/mongo/embedded/mongoc_embedded, which isn't part of normal MongoDB and which isn't built by default. In fact, that part of the tree won't even be enabled if the check for the C driver doesn't find a valid driver installation. The flag --use-system-mongo-c is defined as follows:

add_option('use-system-mongo-c',
    choices=['on', 'off', 'auto'],
    const='on',
    default="auto",
    help="use system version of the mongo-c-driver (auto will use it if it's found)",
    nargs='?',
    type='choice',
)

So it defaults to auto - meaning that if it isn't found, it won't be used. It shouldn't be failing your build, and you can safely ignore that configure check. If you would like to explicitly disable the check for some reason, you can build with --use-system-mongo-c=off.

That said, if you really want to be able to make this work, my suspicion is that the MacPorts include and library paths aren't enabled for your build, so the C driver you have installed there can't be found. I don't know exactly what the installation setup for mongo-c-driver looks like in MacPorts, but you probably need something like the following:

/opt/local/bin/python3.7 buildscripts/scons.py CC=/opt/local/bin/clang-mp-7.0 CXX=/opt/local/bin/clang++-mp-7.0 --use-system-mongo-c CPPPATH=/opt/local/include/libmongoc-1.0 LIBPATH=/opt/local/lib

An improvement on the above would be to get these path arguments for CPPPATH and LIBPATH via pkgconfig.

If you are actually interested in building the embedded code, I suggest reaching out on mongodb-dev first https://groups.google.com/forum/#!forum/mongodb-dev so we can discuss.

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