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

build: make dependency on fast_float optional in CMake build #2310

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
build: make dependency on fast_float optional in CMake build
The fast_float library isn't widely available, especially for older
distributions. Furthermore, `FOLLY_CONV_ATOD_MODE` isn't even set by
the CMake build, so conversion doesn't actually use fast_float.
  • Loading branch information
mhx committed Oct 10, 2024
commit 62ceff43c89d755085e1900c34fc71f0ce1dc4b4
2 changes: 2 additions & 0 deletions CMake/folly-config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#cmakedefine FOLLY_HAVE_PTHREAD 1
#cmakedefine FOLLY_HAVE_PTHREAD_ATFORK 1

#cmakedefine FOLLY_HAVE_FASTFLOAT 1

#cmakedefine FOLLY_HAVE_LIBGFLAGS 1
#cmakedefine FOLLY_UNUSUAL_GFLAGS_NAMESPACE 1
#cmakedefine FOLLY_GFLAGS_NAMESPACE @FOLLY_GFLAGS_NAMESPACE@
Expand Down
7 changes: 5 additions & 2 deletions CMake/folly-deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ find_package(DoubleConversion MODULE REQUIRED)
list(APPEND FOLLY_LINK_LIBRARIES ${DOUBLE_CONVERSION_LIBRARY})
list(APPEND FOLLY_INCLUDE_DIRECTORIES ${DOUBLE_CONVERSION_INCLUDE_DIR})

find_package(FastFloat MODULE REQUIRED)
list(APPEND FOLLY_INCLUDE_DIRECTORIES ${FASTFLOAT_INCLUDE_DIR})
find_package(FastFloat MODULE)
set(FOLLY_HAVE_FASTFLOAT ${FASTFLOAT_FOUND})
if(FASTFLOAT_FOUND)
list(APPEND FOLLY_INCLUDE_DIRECTORIES ${FASTFLOAT_INCLUDE_DIR})
endif()

find_package(Gflags MODULE)
set(FOLLY_HAVE_LIBGFLAGS ${LIBGFLAGS_FOUND})
Expand Down
6 changes: 5 additions & 1 deletion folly/Conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

#include <folly/lang/SafeAssert.h>

#if FOLLY_HAVE_FASTFLOAT
#include <fast_float/fast_float.h> // @manual=fbsource//third-party/fast_float:fast_float
#endif

namespace folly {
namespace detail {
Expand Down Expand Up @@ -462,6 +464,7 @@ Expected<Tgt, ConversionCode> str_to_floating_double_conversion(
return Tgt(result);
}

#if FOLLY_HAVE_FASTFLOAT
/// Uses `fast_float::from_chars` to convert from string to an integer.
template <class Tgt>
Expected<Tgt, ConversionCode> str_to_floating_fast_float_from_chars(
Expand Down Expand Up @@ -505,14 +508,15 @@ template Expected<float, ConversionCode>
str_to_floating_fast_float_from_chars<float>(StringPiece* src) noexcept;
template Expected<double, ConversionCode>
str_to_floating_fast_float_from_chars<double>(StringPiece* src) noexcept;
#endif

/**
* StringPiece to double, with progress information. Alters the
* StringPiece parameter to munch the already-parsed characters.
*/
template <class Tgt>
Expected<Tgt, ConversionCode> str_to_floating(StringPiece* src) noexcept {
#if defined(FOLLY_CONV_ATOD_MODE) && FOLLY_CONV_ATOD_MODE == 1
#if FOLLY_HAVE_FASTFLOAT && defined(FOLLY_CONV_ATOD_MODE) && FOLLY_CONV_ATOD_MODE == 1
return detail::str_to_floating_fast_float_from_chars<Tgt>(src);
#else
return detail::str_to_floating_double_conversion<Tgt>(src);
Expand Down
2 changes: 2 additions & 0 deletions folly/Conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,7 @@ extern template Expected<float, ConversionCode> str_to_floating<float>(
extern template Expected<double, ConversionCode> str_to_floating<double>(
StringPiece* src) noexcept;

#if FOLLY_HAVE_FASTFLOAT
template <typename T>
Expected<T, ConversionCode> str_to_floating_fast_float_from_chars(
StringPiece* src) noexcept;
Expand All @@ -1469,6 +1470,7 @@ extern template Expected<float, ConversionCode>
str_to_floating_fast_float_from_chars<float>(StringPiece* src) noexcept;
extern template Expected<double, ConversionCode>
str_to_floating_fast_float_from_chars<double>(StringPiece* src) noexcept;
#endif

template <class Tgt>
Expected<Tgt, ConversionCode> digits_to(const char* b, const char* e) noexcept;
Expand Down
2 changes: 2 additions & 0 deletions folly/test/ConvTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1772,6 +1772,7 @@ TEST(Conv, TryStringToFloat) {
tryStringToFloat<folly::StringPiece>(StrToFloatTryTo<folly::StringPiece>());
}

#if FOLLY_HAVE_FASTFLOAT
/// Uses `folly::detail::str_to_floating_fast_float_from_chars` to convert a
/// string to a float.
template <class String>
Expand All @@ -1792,6 +1793,7 @@ TEST(Conv, TryStringToFloat_FastFloatFromChars) {
tryStringToFloat<folly::StringPiece>(
StrToFloatFastFloatFromChars<folly::StringPiece>());
}
#endif

template <class String>
void tryToDouble() {
Expand Down
Loading