[MONGOCRYPT-451] Cannot build with shared libbson Created: 29/Jun/22  Updated: 27/Jan/23  Resolved: 28/Jul/22

Status: Closed
Project: Libmongocrypt
Component/s: cmake
Affects Version/s: 1.5.0
Fix Version/s: None

Type: Bug Priority: Unknown
Reporter: Remi Collet Assignee: Colby Pike
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File CMakeCache.txt    
Issue Links:
Cloners
is cloned by MONGOCRYPT-522 CLONE - Cannot build with shared libbson Closed

 Description   

I'm unable to build RPM of new version using system shared libbson.

In all case, it seems the static libbson is required (which is not available in the package per packaging Guidelines)

 



 Comments   
Comment by Colby Pike [ 28/Jul/22 ]

I believe this is all settled now.  Feel free to re-open if you run into any new issues.

Comment by Remi Collet [ 18/Jul/22 ]

Build in Fedora Rawhide using

https://src.fedoraproject.org/rpms/libmongocrypt/raw/rawhide/f/libmongocrypt-static.patch

Perhaps will have to keep it rawhide only because of ABI/API change (MONGOCRYPT-460)

(looks like each day I hate cmake a bit more)

Comment by Colby Pike [ 07/Jul/22 ]

Those references in mongocrypt-config.cmake will not create issues. Those are there for setting up link rules at import time and do not require any bson-static targets.

Comment by Remi Collet [ 07/Jul/22 ]

Yes, using

 

sed -e '/target_link_libraries/s/bson_static/bson_shared/' -i cmake/ImportBSON.cmake

 

build passes

(tests are no more available)

 

But some static are now referenced in installed cmake files:

 

+ grep -r static cmake
cmake/mongocrypt/mongocrypt-config.cmake:    # The user has named a library that should be linked as the static libbson library
cmake/mongocrypt/mongocrypt-config.cmake:        TARGET mongo::_mongocrypt-libbson_for_static
cmake/mongocrypt/mongocrypt-config.cmake:#   (Note: static libmongocrypt always needs to link against an external libbson, as it does not
cmake/mongocrypt/mongocrypt_targets.cmake:foreach(_expectedTarget mongo::_mongocrypt-libbson_for_static mongo::_mongocrypt-libbson_for_shared mongo::mongocrypt)
cmake/mongocrypt/mongocrypt_targets.cmake:# Create imported target mongo::_mongocrypt-libbson_for_static
cmake/mongocrypt/mongocrypt_targets.cmake:add_library(mongo::_mongocrypt-libbson_for_static INTERFACE IMPORTED)

Comment by Colby Pike [ 06/Jul/22 ]

I believe I have found the issue. The mongocrypt_static attempts to link with bson_static, but that target is not defined in your build. That CMake target also exposes the usage requirements that set up the header search paths. Since bson_static does not refer to anything, the build does not receive any usage requirements that allow it to compile and link.

In ImportBSON.cmake, there is a line:

target_link_libraries (_mongocrypt-libbson_for_static INTERFACE $<BUILD_INTERFACE:bson_static>)

Replace it with this:

target_link_libraries (_mongocrypt-libbson_for_static INTERFACE $<BUILD_INTERFACE:bson_shared>)

Comment by Remi Collet [ 02/Jul/22 ]

CMakeCache.txt attached

Comment by Colby Pike [ 01/Jul/22 ]

Can you post your CMakeCache.txt from the failing build?

Comment by Remi Collet [ 01/Jul/22 ]

Using:

{{    -DENABLE_PIC:BOOL=ON }}
{{    -DUSE_SHARED_LIBBSON:BOOL=ON }}
{{    -DMONGOCRYPT_MONGOC_DIR:STRING=USE-SYSTEM }}
{{    -DENABLE_ONLINE_TESTS:BOOL=OFF }}
{{    -DBUILD_TESTING:BOOL=OFF }}
    -DENABLE_STATIC:BOOL=OFF

Still failing:

[ 48%] Building C object CMakeFiles/mongocrypt_static.dir/src/crypto/cng.c.o
/usr/lib64/ccache/gcc -DKMS_MSG_STATIC -DMLIB_USER -DMONGOCRYPT_LITTLE_ENDIAN -DMONGOCRYPT_STATIC_DEFINE -I/dev/shm/extras/BUILD/libmongocrypt-1.5.0/kms-message/src -I/dev/shm/extras/BUILD/libmongocrypt-1.5.0/src -I/dev/shm/extras/BUILD/libmongocrypt-1.5.0/redhat-linux-build/src -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -Werror=implicit -Werror=return-type -Werror=incompatible-pointer-types -Werror=int-conversion -Werror=discarded-qualifiers -Werror=uninitialized -fPIC -std=gnu99 -MD -MT CMakeFiles/mongocrypt_static.dir/src/crypto/cng.c.o -MF CMakeFiles/mongocrypt_static.dir/src/crypto/cng.c.o.d -o CMakeFiles/mongocrypt_static.dir/src/crypto/cng.c.o -c /dev/shm/extras/BUILD/libmongocrypt-1.5.0/src/crypto/cng.c
In file included from /dev/shm/extras/BUILD/libmongocrypt-1.5.0/src/crypto/../mongocrypt-crypto-private.h:21,
                 from /dev/shm/extras/BUILD/libmongocrypt-1.5.0/src/crypto/cng.c:17:
/dev/shm/extras/BUILD/libmongocrypt-1.5.0/src/crypto/../mongocrypt-buffer-private.h:20:10: fatal error: bson/bson.h: No such file or directory
   20 | #include <bson/bson.h>
      |          ^~~~~~~~~~~~~
compilation terminated.

 

Notice: this issue also blocks update in official repository of

  • mongo-c-driver 1.22.0
  • upcoming pecl extension 1.14.0
Comment by Colby Pike [ 30/Jun/22 ]

Hi Remi,

I made the changes that are relevant here. The static libbson in this case is only needed to compile some test programs. Does the build succeed if you set BUILD_TESTING=OFF as a CMake setting?

Comment by Remi Collet [ 29/Jun/22 ]

Package content:

# rpm -q libbson-devel
libbson-devel-1.21.2-1.fc35.remi.x86_64
# rpm -ql libbson-devel 
/usr/include/libbson-1.0
/usr/include/libbson-1.0/bson
/usr/include/libbson-1.0/bson.h
...
/usr/lib64/cmake/bson-1.0
/usr/lib64/cmake/bson-1.0/bson-1.0-config-version.cmake
/usr/lib64/cmake/bson-1.0/bson-1.0-config.cmake
/usr/lib64/cmake/bson-1.0/bson-targets-relwithdebinfo.cmake
/usr/lib64/cmake/bson-1.0/bson-targets.cmake
/usr/lib64/cmake/libbson-1.0
/usr/lib64/cmake/libbson-1.0/libbson-1.0-config-version.cmake
/usr/lib64/cmake/libbson-1.0/libbson-1.0-config.cmake
/usr/lib64/libbson-1.0.so
/usr/lib64/pkgconfig/libbson-1.0.pc

 

Comment by Remi Collet [ 29/Jun/22 ]

Using     -DUSE_SHARED_LIBBSON:BOOL=ON    -DMONGOCRYPT_MONGOC_DIR:STRING=USE-SYSTEM    -DENABLE_ONLINE_TESTS:BOOL=OFF     -DENABLE_STATIC:BOOL=OFF

gmake[2]: *** No rule to make target '_MONGOCRYPT_SYSTEM_LIBBSON_STATIC-NOTFOUND', needed by 'mongo_crypt_v1.so'.  Stop.
gmake[2]: *** Waiting for unfinished jobs....
gmake[2]: Entering directory '/dev/shm/extras/BUILD/libmongocrypt-1.5.0/redhat-linux-build'
gmake[2]: *** No rule to make target '_MONGOCRYPT_SYSTEM_LIBBSON_STATIC-NOTFOUND', needed by 'stubbed-crypt_shared-2.dll'.  Stop.
gmake[2]: *** Waiting for unfinished jobs....

 

Trying with removing find_library (_MONGOCRYPT_SYSTEM_LIBBSON_STATIC ...

/dev/shm/extras/BUILD/libmongocrypt-1.5.0/test/crypt_shared-stub.cpp:20:10: fatal error: bson/bson.h: No such file or directory
   20 | #include <bson/bson.h>
      |          ^~~~~~~~~~~~~
compilation terminated.

Generated at Thu Feb 08 09:08:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.