You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by sz...@apache.org on 2024/05/10 21:06:15 UTC
(nifi-minifi-cpp) 01/02: MINIFICPP-2371 Build fix for >= libc++17
This is an automated email from the ASF dual-hosted git repository.
szaszm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
commit ef58807d70da2ce723f2e4ad8f0a04b0ee858515
Author: Martin Zink <ma...@apache.org>
AuthorDate: Fri May 10 15:50:12 2024 +0200
MINIFICPP-2371 Build fix for >= libc++17
Closes #1786
Signed-off-by: Marton Szasz <sz...@apache.org>
---
.github/workflows/ci.yml | 3 --
bootstrap/package_manager.py | 5 ++
bootstrap/system_dependency.py | 1 +
cmake/Date.cmake | 6 +++
extensions/expression-language/CMakeLists.txt | 29 +++++++++++
libminifi/include/utils/TimeUtil.h | 2 +-
thirdparty/date/826_libcpp_17_build_fix.patch | 69 +++++++++++++++++++++++++++
7 files changed, 111 insertions(+), 4 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 7ca9c8bba..1e14505d6 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -90,9 +90,6 @@ jobs:
echo -e "127.0.0.1\t$HOSTNAME" | sudo tee -a /etc/hosts > /dev/null
- name: build
run: |
- export PATH="/usr/local/opt/flex/bin:/usr/local/opt/bison/bin:$PATH"
- export LDFLAGS="-L/usr/local/opt/flex/lib,-L/usr/local/opt/bison/lib"
- export CPPFLAGS="-I/usr/local/opt/flex/include"
python -m venv venv && source venv/bin/activate && pip install -r requirements.txt && python main.py --noninteractive --skip-compiler-install --cmake-options="-DCMAKE_C_FLAGS=${CPPFLAGS} ${CFLAGS} -DCMAKE_CXX_FLAGS=${CPPFLAGS} ${CXXFLAGS}" --minifi-options="${MACOS_MINIFI_OPTIONS}"
working-directory: bootstrap
- name: cache save
diff --git a/bootstrap/package_manager.py b/bootstrap/package_manager.py
index b5257c55f..d9ecdb510 100644
--- a/bootstrap/package_manager.py
+++ b/bootstrap/package_manager.py
@@ -105,6 +105,11 @@ class BrewPackageManager(PackageManager):
lines = [line.split('@', 1)[0] for line in lines]
return set(lines)
+ def run_cmd(self, cmd: str) -> bool:
+ add_m4_to_path_cmd = 'export PATH="$(brew --prefix m4)/bin:$PATH"'
+ result = subprocess.run(f"{add_m4_to_path_cmd} && {cmd}", shell=True, text=True)
+ return result.returncode == 0
+
class AptPackageManager(PackageManager):
def __init__(self, no_confirm):
diff --git a/bootstrap/system_dependency.py b/bootstrap/system_dependency.py
index 74a864f74..f4c273f3b 100644
--- a/bootstrap/system_dependency.py
+++ b/bootstrap/system_dependency.py
@@ -27,6 +27,7 @@ def _create_system_dependencies(minifi_options: MinifiOptions) -> Dict[str, Set[
if minifi_options.is_enabled("ENABLE_EXPRESSION_LANGUAGE"):
system_dependencies['bison'] = {'bison'}
system_dependencies['flex'] = {'flex'}
+ system_dependencies['m4'] = {'m4'}
if minifi_options.is_enabled("ENABLE_LIBARCHIVE"):
system_dependencies['libarchive'] = {'libarchive'}
if minifi_options.is_enabled("ENABLE_PCAP"):
diff --git a/cmake/Date.cmake b/cmake/Date.cmake
index 696f51ba4..3224e4187 100644
--- a/cmake/Date.cmake
+++ b/cmake/Date.cmake
@@ -45,9 +45,15 @@ if (WIN32)
COMPONENT bin)
endif()
+set(PATCH_FILE "${CMAKE_SOURCE_DIR}/thirdparty/date/826_libcpp_17_build_fix.patch")
+set(PC ${Bash_EXECUTABLE} -c "set -x &&\
+ (\\\"${Patch_EXECUTABLE}\\\" -p1 -R -s -f --dry-run -i \\\"${PATCH_FILE}\\\" || \\\"${Patch_EXECUTABLE}\\\" -p1 -N -i \\\"${PATCH_FILE}\\\")")
+
+
FetchContent_Declare(date_src
URL https://github.com/HowardHinnant/date/archive/refs/tags/v3.0.1.tar.gz
URL_HASH SHA256=7a390f200f0ccd207e8cff6757e04817c1a0aec3e327b006b7eb451c57ee3538
+ PATCH_COMMAND "${PC}"
)
FetchContent_GetProperties(date_src)
if (NOT date_src_POPULATED)
diff --git a/extensions/expression-language/CMakeLists.txt b/extensions/expression-language/CMakeLists.txt
index 0b357cea1..8f89c9958 100644
--- a/extensions/expression-language/CMakeLists.txt
+++ b/extensions/expression-language/CMakeLists.txt
@@ -64,6 +64,32 @@ if(WIN32)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/winflexbison")
endif()
+# On macOS brew installed bison and flex are preferred
+if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
+ execute_process(
+ COMMAND brew --prefix bison
+ RESULT_VARIABLE BREW_BISON
+ OUTPUT_VARIABLE BREW_BISON_PREFIX
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if (BREW_BISON EQUAL 0 AND EXISTS "${BREW_BISON_PREFIX}")
+ message(STATUS "Found Bison keg installed by Homebrew at ${BREW_BISON_PREFIX}")
+ set(BISON_EXECUTABLE "${BREW_BISON_PREFIX}/bin/bison")
+ endif()
+
+ execute_process(
+ COMMAND brew --prefix flex
+ RESULT_VARIABLE BREW_FLEX
+ OUTPUT_VARIABLE BREW_FLEX_PREFIX
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if (BREW_FLEX EQUAL 0 AND EXISTS "${BREW_FLEX_PREFIX}")
+ message(STATUS "Found Flex keg installed by Homebrew at ${BREW_FLEX_PREFIX}")
+ set(FLEX_EXECUTABLE "${BREW_FLEX_PREFIX}/bin/flex")
+ set(BREW_FLEX_INCLUDE "${BREW_FLEX_PREFIX}/include")
+ endif()
+endif()
+
find_package(BISON REQUIRED)
find_package(FLEX REQUIRED)
@@ -107,6 +133,9 @@ add_minifi_library(minifi-expression-language-extensions SHARED ${SOURCES} ${BIS
target_link_libraries(minifi-expression-language-extensions ${LIBMINIFI})
target_link_libraries(minifi-expression-language-extensions RapidJSON CURL::libcurl)
+if (BREW_FLEX_INCLUDE)
+ target_include_directories(minifi-expression-language-extensions PRIVATE ${BREW_FLEX_INCLUDE})
+endif()
register_extension(minifi-expression-language-extensions "EXPRESSION LANGUAGE EXTENSIONS" EXPRESSION-LANGUAGE-EXTENSIONS "This enables NiFi expression language" "extensions/expression-language/tests")
register_extension_linter(minifi-expression-language-extensions-linter)
diff --git a/libminifi/include/utils/TimeUtil.h b/libminifi/include/utils/TimeUtil.h
index 7cd022d9f..72f828431 100644
--- a/libminifi/include/utils/TimeUtil.h
+++ b/libminifi/include/utils/TimeUtil.h
@@ -44,7 +44,7 @@
#define TIME_FORMAT "%Y-%m-%d %H:%M:%S"
-#if defined(_LIBCPP_VERSION)
+#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 170000
namespace org::apache::nifi::minifi::detail {
template<typename T>
concept has_spaceship_operator = requires(T t, T u) { t <=> u; }; // NOLINT(readability/braces)
diff --git a/thirdparty/date/826_libcpp_17_build_fix.patch b/thirdparty/date/826_libcpp_17_build_fix.patch
new file mode 100644
index 000000000..4d0647996
--- /dev/null
+++ b/thirdparty/date/826_libcpp_17_build_fix.patch
@@ -0,0 +1,69 @@
+diff --git a/include/date/date.h b/include/date/date.h
+index 7b6b4e4..db91ed6 100644
+--- a/include/date/date.h
++++ b/include/date/date.h
+@@ -4228,7 +4228,7 @@ inline
+ std::basic_ostream<CharT, Traits>&
+ operator<<(std::basic_ostream<CharT, Traits>& os, const local_time<Duration>& ut)
+ {
+- return (os << sys_time<Duration>{ut.time_since_epoch()});
++ return (date::operator<<(os, sys_time<Duration>{ut.time_since_epoch()}));
+ }
+
+ namespace detail
+diff --git a/include/date/ptz.h b/include/date/ptz.h
+index ebd6e04..8b9a046 100644
+--- a/include/date/ptz.h
++++ b/include/date/ptz.h
+@@ -593,7 +593,7 @@ time_zone::name() const
+ auto print_offset = [](seconds off)
+ {
+ std::string nm;
+- hh_mm_ss<seconds> offset{-off};
++ date::hh_mm_ss<seconds> offset{-off};
+ if (offset.is_negative())
+ nm += '-';
+ nm += std::to_string(offset.hours().count());
+diff --git a/include/date/tz.h b/include/date/tz.h
+index 4921068..bacd055 100644
+--- a/include/date/tz.h
++++ b/include/date/tz.h
+@@ -231,8 +231,8 @@ nonexistent_local_time::make_msg(local_time<Duration> tp, const local_info& i)
+ << i.first.abbrev << " and\n"
+ << local_seconds{i.second.begin.time_since_epoch()} + i.second.offset << ' '
+ << i.second.abbrev
+- << " which are both equivalent to\n"
+- << i.first.end << " UTC";
++ << " which are both equivalent to\n";
++ date::operator<<(os, i.first.end) << " UTC";
+ return os.str();
+ }
+
+diff --git a/include/date/tz_private.h b/include/date/tz_private.h
+index aec01d0..1a01f17 100644
+--- a/include/date/tz_private.h
++++ b/include/date/tz_private.h
+@@ -289,8 +289,7 @@ struct transition
+ std::ostream&
+ operator<<(std::ostream& os, const transition& t)
+ {
+- using date::operator<<;
+- os << t.timepoint << "Z ";
++ date::operator<<(os, t.timepoint) << "Z ";
+ if (t.info->offset >= std::chrono::seconds{0})
+ os << '+';
+ os << make_time(t.info->offset);
+diff --git a/src/tz.cpp b/src/tz.cpp
+index 26babbd..98daeb4 100644
+--- a/src/tz.cpp
++++ b/src/tz.cpp
+@@ -2625,8 +2625,7 @@ operator<<(std::ostream& os, const time_zone& z)
+ std::ostream&
+ operator<<(std::ostream& os, const leap_second& x)
+ {
+- using namespace date;
+- return os << x.date_ << " +";
++ return date::operator<<(os, x.date_) << " +";
+ }
+
+ #if USE_OS_TZDB