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-685 update libbson to 1.27.1 #818

Merged
merged 21 commits into from
May 31, 2024
Merged

Conversation

kevinAlbs
Copy link
Contributor

Summary

Update bundled libbson to 1.27.1

Apply workarounds to resolve errors on RHEL 6.2 with gcc 4.4.7:

  • Define __STDC_LIMIT_MACROS when compiling with C++.
  • Disable GCC diagnostic macros in functions for gcc < 4.6.

Remove workarounds for older libbson:

  • Replace CONCAT macro with BSON_CONCAT.
  • Remove BSON_SUBTYPE_ENCRYPTED (now defined in libbson).
  • Remove workaround for CDRIVER-3340.

Verified with this patch build: https://spruce.mongodb.com/version/6650b53f05094a0007522646

Background

Motivation

Updating bundled libbson is to address an issue reported in Skyk that was fixed in libbson 1.25.0: https://security.snyk.io/vuln/SNYK-UNMANAGED-MONGODBMONGOCDRIVER-6156642

Workaround: define __STDC_LIMIT_MACROS for C++ targets

Defining __STDC_LIMIT_MACROS resolves an error on this patch when compiling a C++ test target: bson-cmp.h:144: error: 'INT8_MIN' was not declared in this scope. The stdint.h header on a spawned RHEL 6.2 host includes:

/* The ISO C99 standard specifies that in C++ implementations these
   macros should only be defined if explicitly requested.  */
#if !defined __cplusplus || defined __STDC_LIMIT_MACROS

Workaround: remove diagnostic pragma on old GCC

Removing the GCC diagnostic pragma resolves an error on this patch: mongoc-aggregate.c:97: error: #pragma GCC diagnostic not allowed inside functions. I expect this is unavailable on GCC 4.6 and older. GCC 4.6 changelog notes:

Support for selectively enabling and disabling warnings via #pragma GCC diagnostic has been added

Due to the workarounds, MONGOCRYPT-688 was filed to propose dropping RHEL 6.2 support for libmongocrypt.

Adding a runtime check

Removing the workaround of CDRIVER-3340 motivated adding a compile-time check to ensure libbson is newer than 1.16.0 (to include fix of CDRIVER-3340). The check for 1.16.0 is a precaution to ensure using a system install of libbson is 1.16.0 or newer. When libbson is loaded from the system, a version check is not performed.

kevinAlbs added 16 commits May 24, 2024 11:41
If a `BUILD_VERSION` is specified for libmongocrypt, do not apply the same value for the embedded C driver.
libmongoc is not required to build libmongocrypt.
removes open TODO comments
It is now defined in libbson
The removed code adds a runtime requirement of libbson 1.16.0 or newer. Add a check to ensure libbson 1.16.0 or newer is used at compile-time. This may prevent use of an older system install of libbson.
VERSION_CURRENT is now committed into the C driver
Will be used to patch libbson
To resolve build error on GCC 4.4.7 on RHEL 6.2
To resolve build error on RHEL 6.2
@kevinAlbs kevinAlbs marked this pull request as ready for review May 28, 2024 15:09
Copy link
Collaborator

@rcsanchez97 rcsanchez97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines 145 to 149
if (BUILD_VERSION)
# Both libmongocrypt and C driver support setting a `BUILD_VERSION`. Do not reuse the `BUILD_VERSION` for libmongocrypt when building the C driver.
# Set the `BUILD_VERSION` in this file to only apply to the C driver subproject.
set (BUILD_VERSION ${MONGOC_FETCH_TAG_FOR_LIBBSON})
endif()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to only set the build version if its already defined for the parent project? This could also be unset(BUILD_VERSION) to clear the value from the scope and let the sub-project infer its own value, or alternatively it can unconditionally set BUILD_VERSION to the fetch tag value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Updated to unconditionally set BUILD_VERSION.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is moved to a separate module, I'd prefer it more module-like so that it doesn't peek at variables in the includer's scope and behave different when included multiple times. For example:

find_program(GIT_EXECUTABLE git)
find_program(PATCH_EXECUTABLE patch)

#[[
    Form a new Patch-applying command for the given inputs

    make_patch_command(
        <outvar>
        [DIRECTORY <dir>]
        [STRIP_COMPONENTS <N>]
        PATCHES [<file> ...]
    )
]]
function(make_patch_command out)
    cmake_parse_arguments(PARSE_ARGV 1 patch "" "DIRECTORY;STRIP_COMPONENTS" "PATCHES")
    if(GIT_COMMAND)
        # git ...
        set(cmd ${GIT_EXECUTABLE})

        if(patch_DIRECTORY)
            # git --work-tree=...
            list(APPEND cmd --work-tree=${patch_DIRECTORY})
        endif()
        # git ... apply ...
        list(APPEND cmd apply)
        # git ... apply -pN ...
        if(patch_STRIP_COMPONENTS)
            list(APPEND cmd -p${patch_STRIP_COMPONENTS})
        endif()
        # git ... apply ...
        foreach(p IN LISTS patch_PATCHES)
            # git ... apply ... <file>
            list(APPEND cmd ${p})
        endforeach()
    else()
        # patch ...
        set(cmd ${PATCH_EXECUTABLE})
        if(patch_DIRECTORY)
            # patch --dir=...
            list(APPEND cmd --dir=${patch_DIRECTORY})
        endif()
        # patch ... -pN ...
        if(patch_STRIP_COMPONENTS)
            list(APPEND cmd -p${patch_STRIP_COMPONENTS})
        endif()
        foreach(p IN LISTS patch_PATCHES)
            # patch ... ---input=<file>
            list(APPEND cmd --input=${p})
        endforeach()
    endif()
    set("${out}" "${cmd}" PARENT_SCOPE)
endfunction()

and then callers can use it via make_patch_command

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it. Thank you for the suggestion! Updated.

@vector-of-bool vector-of-bool self-requested a review May 28, 2024 19:55
Copy link
Contributor

@vector-of-bool vector-of-bool left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I discovered two simplifications to the patch command function.

cmake/Patch.cmake Outdated Show resolved Hide resolved
cmake/Patch.cmake Outdated Show resolved Hide resolved
Copy link
Collaborator

@rcsanchez97 rcsanchez97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kevinAlbs kevinAlbs merged commit 6298012 into mongodb:master May 31, 2024
12 of 13 checks passed
kevinAlbs added a commit that referenced this pull request Jun 18, 2024
* update bundled libbson to 1.27.1

* override `BUILD_VERSION` for C driver

If a `BUILD_VERSION` is specified for libmongocrypt, do not apply the same value for the embedded C driver.

* Clarify `ENABLE_ONLINE_TESTS` requires libmongoc. libmongoc is not required to build libmongocrypt.

* use the now-available `BSON_CONCAT` and remove TODOs

* remove `BSON_SUBTYPE_ENCRYPTED` (now defined in libbson)

* remove workaround for CDRIVER-3340

The removed code adds a runtime requirement of libbson 1.16.0 or newer. Add a check to ensure libbson 1.16.0 or newer is used at compile-time. This may prevent use of an older system install of libbson.

* disable building tests and counters in C driver

* update version in `prep_c_driver_source.sh`

* remove unnecessary VERSION_CURRENT

VERSION_CURRENT is now committed into the C driver

* add a `make_patch_command` CMake helper use for libbson and IntelDFP

* patch libbson to remove GCC diagnostic pragma

To resolve build error on GCC 4.4.7 on RHEL 6.2

* define `__STDC_LIMIT_MACROS`

To resolve build error on RHEL 6.2

* apply patch in linker tests

* reference ticket to drop RHEL 6.2

---------

Co-authored-by: vector-of-bool <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants