-
Notifications
You must be signed in to change notification settings - Fork 88
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?
Changes from 11 commits
96fbf86
439d92a
ae0353d
07f4e80
eaf5855
e5503ff
e0eddf1
0a5a54a
0911c45
df2ff5b
75556b3
e1680db
446b383
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,67 +2,104 @@ | |||||
This file handles importing the DFP (decimal floating point) library for decimal128 support. It | ||||||
is patterned after ImportBSON in this same directory. | ||||||
|
||||||
Initially, the only supported DFP implementation is Intel DFP. However, this module will allow | ||||||
for the future addition of support for libdfp. | ||||||
|
||||||
This file defines, exports, and installs one INTERFACE target: mongocrypt::intel_dfp. | ||||||
This file defines, exports, and installs one INTERFACE target: _mongocrypt::dfp. | ||||||
|
||||||
The target(s) from this file are used to link the DFP library correctly for the build | ||||||
configuration of libmongocrypt. At find_package() time, we can resolve these interface targets | ||||||
to link to the DFP library based on the build configurations of libmongocrypt. | ||||||
|
||||||
In the initial implementation both mongo::mongocrypt and mongo::mongocrypt_static must link to | ||||||
mongocrypt::intel_dfp (this is because if we link to the Intel DFP which is vendored with | ||||||
_mongocrypt::dfp (this is because if we link to the Intel DFP which is vendored with | ||||||
libmongocrypt then we will link the object files directly and if we use the system Intel DFP then | ||||||
we will be linking with .a static library archives). | ||||||
|
||||||
The default behavior is to use the Intel DFP which is vendored in this repository. By setting | ||||||
MONGOCRYPT_DFP_DIR=USE-SYSTEM the build will assume that an appropriate Intel DFP implementation | ||||||
MONGOCRYPT_DFP_DIR=USE-SYSTEM the build will assume that an appropriate DFP implementation | ||||||
can be found in a location where it has been installed system-wide (most likely under /usr or | ||||||
/usr/local). | ||||||
/usr/local). It will search for an installation of IntelDFP or of libdfp. | ||||||
]] | ||||||
|
||||||
if (DEFINED MONGOCRYPT_DFP_DIR AND NOT MONGOCRYPT_DFP_DIR STREQUAL "USE-SYSTEM") | ||||||
message (FATAL_ERROR "The only valid value for MONGOCRYPT_DFP_DIR is USE-SYSTEM") | ||||||
endif () | ||||||
|
||||||
function (_import_dfp) | ||||||
find_library (_MONGOCRYPT_SYSTEM_INTEL_DFP_STATIC "${CMAKE_STATIC_LIBRARY_PREFIX}bidgcc000${CMAKE_STATIC_LIBRARY_SUFFIX}") | ||||||
find_path (_MONGOCRYPT_SYSTEM_INTEL_DFP_INCLUDE_DIR bid_conf.h) | ||||||
add_library (intel_dfp STATIC IMPORTED) | ||||||
set_target_properties (intel_dfp PROPERTIES | ||||||
INTERFACE_INCLUDE_DIRECTORIES "${_MONGOCRYPT_SYSTEM_INTEL_DFP_INCLUDE_DIR}" | ||||||
) | ||||||
set_property (TARGET intel_dfp PROPERTY IMPORTED_LOCATION "${_MONGOCRYPT_SYSTEM_INTEL_DFP_STATIC}") | ||||||
set_property ( | ||||||
CACHE _MONGOCRYPT_SYSTEM_INTEL_DFP_INCLUDE_DIR | ||||||
PROPERTY ADVANCED | ||||||
TRUE | ||||||
if (NOT _MONGOCRYPT_SYSTEM_DFP_LIB OR NOT _MONGOCRYPT_SYSTEM_DFP_INCLUDE_DIR) | ||||||
message (CHECK_START "Searching for a decimal floating-point library") | ||||||
# Clear prior settings if either one may have been unset: | ||||||
unset (_MONGOCRYPT_SYSTEM_DFP_LIB CACHE) | ||||||
unset (_MONGOCRYPT_SYSTEM_DFP_INCLUDE_DIR CACHE) | ||||||
# Search for the IntelDFP library: | ||||||
find_library ( | ||||||
_inteldfp_lib | ||||||
NAMES bidgcc000 "${CMAKE_STATIC_LIBRARY_PREFIX}bidgcc000${CMAKE_STATIC_LIBRARY_SUFFIX}" | ||||||
NO_CACHE | ||||||
) | ||||||
# Search for the libdfp library: | ||||||
find_library ( | ||||||
_libdfp_lib | ||||||
NAMES dfp "${CMAKE_STATIC_LIBRARY_PREFIX}dfp${CMAKE_STATIC_LIBRARY_SUFFIX}" | ||||||
NO_CACHE | ||||||
) | ||||||
|
||||||
# Search for the include-path for IntelDFP: | ||||||
find_path (_inteldfp_bid_conf_h_dir bid_conf.h NO_CACHE) | ||||||
# Search for math.h contained in libdfp: | ||||||
find_file (_libdfp_dfp_math_h "dfp/math.h" NO_CACHE) | ||||||
|
||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
message (CHECK_PASS "Using IntelDFP: ${_inteldfp_lib}") | ||||||
set (_lib "${_inteldfp_lib}") | ||||||
set (_inc_dir "${_inteldfp_bid_conf_h_dir}") | ||||||
elseif (_libdfp_lib AND _libdfp_dfp_math_h) | ||||||
# Use libdfp: | ||||||
message (CHECK_PASS "Using libdfp: ${_libdfp_lib}") | ||||||
set (_lib "${_libdfp_lib}") | ||||||
# We want to add the 'dfp/' directory as an include-dir, so it intercepts | ||||||
# the default stdlib headers: | ||||||
get_filename_component (_inc_dir "${_libdfp_dfp_math_h}" DIRECTORY) | ||||||
else () | ||||||
# Nope: | ||||||
message (CHECK_FAIL "No decimal floating-point library was found.") | ||||||
message (SEND_ERROR "Failed to import a decimal floating-point library from the system") | ||||||
endif () | ||||||
|
||||||
set (_MONGOCRYPT_SYSTEM_DFP_LIB "${_lib}" CACHE PATH "System DFP library to use") | ||||||
set (_MONGOCRYPT_SYSTEM_DFP_INCLUDE_DIR "${_inc_dir}" CACHE PATH "include-search-dir for the system DFP library") | ||||||
mark_as_advanced (_MONGOCRYPT_SYSTEM_DFP_LIB _MONGOCRYPT_SYSTEM_DFP_INCLUDE_DIR) | ||||||
endif () | ||||||
|
||||||
add_library (_mongocrypt::system-dfp UNKNOWN IMPORTED) | ||||||
set_target_properties ( | ||||||
_mongocrypt::system-dfp PROPERTIES | ||||||
IMPORTED_LOCATION "${_MONGOCRYPT_SYSTEM_DFP_LIB}" | ||||||
INTERFACE_INCLUDE_DIRECTORIES "${_MONGOCRYPT_SYSTEM_DFP_INCLUDE_DIR}" | ||||||
) | ||||||
endfunction () | ||||||
|
||||||
# This library is used to pivot the used DFP library at configure/find_package time: | ||||||
add_library (_mongocrypt-dfp INTERFACE) | ||||||
add_library (mongocrypt::dfp ALIAS _mongocrypt-dfp) | ||||||
install (TARGETS _mongocrypt-dfp EXPORT mongocrypt_targets) | ||||||
|
||||||
if (NOT DEFINED MONGOCRYPT_DFP_DIR) | ||||||
# The user did not provide a MONGOCRYPT_DFP_DIR, so we'll set one up | ||||||
include (IntelDFP) | ||||||
elseif (MONGOCRYPT_DFP_DIR STREQUAL "USE-SYSTEM") | ||||||
message (STATUS "NOTE: Using system-wide Intel DFP library. This is intended only for package maintainers.") | ||||||
set (USE_SYSTEM_INTEL_DFP "ON") | ||||||
message (STATUS "NOTE: Using system-wide DFP library. This is intended only for package maintainers.") | ||||||
|
||||||
# Do the import in a function to isolate variable scope | ||||||
_import_dfp () | ||||||
|
||||||
# Define interface targets to be used to control the DFP used at both build and import time. | ||||||
# Refer to mongocrypt-config.cmake to see how these targets are used by consumers | ||||||
add_library (_mongocrypt-intel_dfp INTERFACE) | ||||||
add_library (mongocrypt::intel_dfp ALIAS _mongocrypt-intel_dfp) | ||||||
install ( | ||||||
TARGETS _mongocrypt-intel_dfp | ||||||
EXPORT mongocrypt_targets | ||||||
) | ||||||
|
||||||
# Link to Intel DFP, only exporting that usage for the local build tree. | ||||||
# The mongocrypt-config file will later add the appropriate link library for downstream | ||||||
# users during find_package() | ||||||
target_link_libraries (_mongocrypt-intel_dfp INTERFACE $<BUILD_INTERFACE:intel_dfp>) | ||||||
|
||||||
# Link to the import target for the system's DFP library. | ||||||
# mongocrypt-config.cmake will later add a matching IMPORTED target | ||||||
# for downstream users during find_package() | ||||||
target_link_libraries (_mongocrypt-dfp INTERFACE _mongocrypt::system-dfp) | ||||||
# Hints for mongocrypt-config.cmake: | ||||||
set (USE_SYSTEM_DFP "ON") | ||||||
get_target_property (_loc _mongocrypt::system-dfp IMPORTED_LOCATION) | ||||||
get_filename_component (SYSTEM_DFP_FILENAME "${_loc}" NAME) | ||||||
endif () | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -9,7 +9,7 @@ Build-Depends: debhelper (>= 10), | |||||||
quilt, | ||||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Let's drop the version, as it's not strictly necessary for libdfp-dev and including it will make backporting libmongocrypt more difficult. |
||||||||
libbson-dev | ||||||||
Standards-Version: 4.6.2 | ||||||||
Section: libs | ||||||||
|
@@ -21,7 +21,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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We should specify |
||||||||
Description: client-side field level encryption library - dev files | ||||||||
libmongocrypt facilitates the client-side encryption and decryption, | ||||||||
|
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 .