-
Notifications
You must be signed in to change notification settings - Fork 94
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-535 Support libdfp as a Decimal128 abstraction #566
base: master
Are you sure you want to change the base?
Conversation
This is actually the correct solution. For instance, in the C driver, the libmongoc-dev package expresses the following dependencies:
In general, we need that sort of thing to ensure access to a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code changes look reasonable.
I am concerned about the extra cost for supporting libdfp. Supporting both libdfp and IntelDFP makes two variants of libmongocrypt to test and maintain. IIUC libmongocrypt built with libdfp is not tested Evergreen. IMO the benefit of adding support for libdfp needs to outweigh that cost. On platforms where IntelDFP is not available as a package, users have the option to build libmongocrypt from source using the vendored IntelDFP.
I prefer proceeding with the "off-switch" to disable Decimal128 with Range Index support on platforms where it is unavailable. Then wait to see if there are requests to support Decimal128 with Range Index support on those platforms.
set (_lib NOTFOUND) | ||
set (_inc_dir NOTFOUND) | ||
if (_inteldfp_lib AND _inteldfp_bid_conf_h_dir) | ||
# Use libdfp: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Use libdfp: | |
# Use IntelDFP: |
@@ -300,7 +300,7 @@ deb-build: | |||
ARG env=deb-unstable | |||
FROM +env.$env | |||
RUN __install git-buildpackage fakeroot debhelper cmake libbson-dev \ | |||
libintelrdfpmath-dev | |||
libdfp-dev quilt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can drop quilt from here. It is no longer necessary after the Debian packaging changes included in #567 .
@@ -8,7 +8,7 @@ Build-Depends: debhelper (>= 10), | |||
cmake, | |||
libssl-dev, | |||
pkg-config, | |||
libintelrdfpmath-dev (>= 2.0u2-6), | |||
libdfp-dev (>= 1.0.16-1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libdfp-dev (>= 1.0.16-1), | |
libdfp-dev, |
Let's drop the version, as it's not strictly necessary for libdfp-dev and including it will make backporting libmongocrypt more difficult.
@@ -20,7 +20,6 @@ Architecture: any | |||
Multi-Arch: same | |||
Depends: libbson-dev, | |||
libmongocrypt0 (= ${binary:Version}), | |||
libintelrdfpmath-dev (>= 2.0u2-6), | |||
${misc:Depends} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${misc:Depends} | |
libdfp-dev, | |
${misc:Depends} |
We should specify libdfp-dev
here, as things like headers, static libraries, and configure scripts could be needed by consumers of libmongocrypt.
This changeset allows building using a system-installation of libdfp as an alternative to IntelDFP.
Change Summary
Package/CMake Changes
MONGOCRYPT_DFP_DIR
toUSE-SYSTEM
will search for both IntelDFP and libdfp. If IntelDFP is found, it will be used; otherwise if libdfp is found, it will be used; otherwise we generate an error._mongocrypt::dfp
is anINTERFACE
target alike what was previously defined, and is used to pivot the selection of a DFP backend._mongocrypt::system-dfp
is anIMPORTED
target that points to the system-installed DFP library._mongocrypt::dfp
links to this library iffUSE-SYSTEM
was specified._mongocrypt::system-dfp
library needs to be redefined if we were built withUSE-SYSTEM
, and a minimum amount offind_library
logic was inserted intomongocrypt-config.cmake
to find the same library that was used for the build. This is similar to the prior version, but it now needs to consider whether we are built with IntelDFP or libdfp. We export the filename of the found library into themongocrypt-config.cmake
so that we can find the correct matching library later on..pc
for the shared library has the link to the DFP lib file removed since either: 1) We linked against a static DFP lib, and themongocrypt.so
already contains the required TUs, or 2) we built against a dynamic DFP lib, and themongocrypt.so
will already have the reference to the properSONAME
. This makes the explicit linking unecessary in either case. The explicit link may fail if the generated.pc
contains the path to a dev-only symlink (this is the case on e.g. Fedora Rawhide wherelibdfp.so
is a symilnk tolibdfp.so.1
, but thelibdfp
runtime package only includeslibdfp.so.1
). Alternative solution: Have libmongocrypt-dev depend on the libdfp-dev packages, but that feels like a heavier burden on users.add_test
can be finicky)libdfp-dev
instead oflibintelrdfp-dev
as the build-dep for the libmongocrypt deb. This can be rolled back if we don't want to make that switch.Code Changes
#include
ingmath.h
, and checking for_DFP_MATH_H
. If found, it means that libdfp has intercepted the stdlib headers and the stdlib symbols may be replaced by the libdfp shims. This switchesmc-dec128.h
to use libdfp as the backend instead of IntelDFP.dec128
classifying functions were renamed to use the stdlib-like names (e.g.is_inf
→isinf
).MC_IF_LIBDFP(...)
, which expands its arguments if libdfp is in use, andMC_IF_IntelDFP(...)
which expands its arguments if libdfp is not in use.<fenv.h>
facilities, which are awful and painful and Widely Regarded as a Bad Move. (Which is why the IntelDFP version opts for the explicit-env arguments for rounding and exceptions).MC_HOLD_FENV(Rounding, FlagsPtr)
, which is a control-statement-like function-macro that wraps a code block and saves/restores the floating-point environment, while also setting the appropriate rounding mode and firingSIGFPE
in the case of unhandled div-by-zero.#include
-order can affect the behavior of libdfp on the required functions, so we need to ensure it comes first in the TU.