Skip to content
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

[MONGOCRYPT-583] cmake/bson: allow shared-only system lib #681

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tharvik
Copy link

@tharvik tharvik commented Jul 30, 2023

see jira's issue for general intro. some comments now

  • when loading system, only load the wanted library, so it creates target bson_shared if USE_SHARED_LIBBSON else bson_shared; that allows to have {shared,static}-only system library
  • extract a function to actually perform the system library load that can be used by both shared and static; also fail early if lib not found
  • now, _mongocrypt-libbson_for_{shared,static} links to shared only iff USE_SHARED_LIBBSON else to static
    • fun info: one can craft a static mongocrypt with a dynamic libbson (dunno why one would want that)
  • move around some code
    • install static lib iff we localy built it
    • set runtime output of shared iff we localy built it
  • for enforcing the local build for test, I wasn't really sure of the check you wanted to make, I took a broad one (fails if test && (system || shared)) but really depend on your use cases

@vector-of-bool
Copy link
Contributor

Sorry for the delay on this one. We have some open tasks to improve the handling of simultaneous/selective static/shared builds in libmongocrypt, libmongoc, and libbson. There's also an unfortunate cyclic dependency-ish between the projects that led to the strange manual import behavior that is currently seen in the code.

Unfortunately, the changes as they currently are may wreak havoc on some of our other users, but I do sympathize with the challenges of packaging according to distribution policies, and I will happily help get this sorted. If I could collect more information: What are the constraints that you are trying to satisfy that are not currently met by the current process?

@vector-of-bool vector-of-bool added the need-info More information is needed before proceeding label Aug 15, 2023
@vector-of-bool vector-of-bool changed the title cmake/bson: allow shared-only system lib [MONGOCRYPT-583] cmake/bson: allow shared-only system lib Aug 15, 2023
@tharvik
Copy link
Author

tharvik commented Sep 8, 2023

Sorry for the delay on this one.

no worries, I'm late too :)

We have some open tasks to improve the handling of simultaneous/selective static/shared builds in libmongocrypt, libmongoc, and libbson.

ho, I missed thoses then, I hope I didn't duplicate an existing one. can you point me to the related ones you've in mind?

What are the constraints that you are trying to satisfy that are not currently met by the current process?

when packaging on Gentoo, we try our best to unbundle all dependencies of a given project; in my case, I'm trying to package libmongocrypt which (by default) bundles libbson. we also let users choose if they want a static lib in addition to a dynamic library (via the static-libs USE flag).

I though by that simply using -DMONGOCRYPT_MONGOC_DIR=USE-SYSTEM for unbundling and a combination -DENABLE_STATIC and -DUSE_SHARED_LIBBSON for the static part would work as I intended. spoiler, it didn't.

  • when build a dynamic-only lib, so -DUSE_SHARED_LIBBSON=YES -DENABLE_STATIC=NO, it fails with

    ninja: error: '_MONGOCRYPT_SYSTEM_LIBBSON_STATIC-NOTFOUND', needed by 'mongo_crypt_v1.so', missing and no known rule to make it
    

    indeed, system libbson is dynamic-only, no way to find a static version on the system, but I specifically asked for no static. installing a static and dynamic libbson works but that disregards users' wishes to have everything dynamic.

  • when build a static and dynamic lib, so -DUSE_SHARED_LIBBSON=NO -DENABLE_STATIC=YES (setting the shared libbson flag to true gives the previous error), it fails with

    [...]
    -- Using [USE-SYSTEM] as a sub-project for libbson
    
    CMake Error at cmake/ImportBSON.cmake:148 (add_subdirectory):
      add_subdirectory given source "USE-SYSTEM" which is not an existing
      directory.
    Call Stack (most recent call first):
      cmake/ImportBSON.cmake:164 (_import_bson)
      CMakeLists.txt:47 (include)
    
    CMake Error at cmake/ImportBSON.cmake:195 (set_property):
      set_property could not find TARGET bson_shared.  Perhaps it has not yet
      been created.
    Call Stack (most recent call first):
      CMakeLists.txt:47 (include)
    
    CMake Error at cmake/ImportBSON.cmake:202 (set_target_properties):
      set_target_properties Can not find target to add properties to: bson_static
    Call Stack (most recent call first):
      CMakeLists.txt:47 (include)
    

    so that's kinda unexpected. I asked for the system lib via this special value of MONGOCRYPT_MONGOC_DIR but it is used as a path which is clearly wrong.

to summarize, I want to be able to

  • build libmongocrypt.so while having only libbson.so
  • and, based on user choice, to also have libmongocrypt.a (in this case, libbson.a will be provided by pkg manager)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-info More information is needed before proceeding
Projects
None yet
2 participants