git: 22f31cfa3606 - main - misc/lbann: Fix build with protobuf 22+

From: Po-Chuan Hsieh <sunpoet_at_FreeBSD.org>
Date: Thu, 14 Dec 2023 17:03:37 UTC
The branch main has been updated by sunpoet:

URL: https://cgit.FreeBSD.org/ports/commit/?id=22f31cfa360640812df820452e62c8de2e6cf795

commit 22f31cfa360640812df820452e62c8de2e6cf795
Author:     Po-Chuan Hsieh <sunpoet@FreeBSD.org>
AuthorDate: 2023-12-14 16:22:39 +0000
Commit:     Po-Chuan Hsieh <sunpoet@FreeBSD.org>
CommitDate: 2023-12-14 17:03:06 +0000

    misc/lbann: Fix build with protobuf 22+
    
    - While I'm here, remove patch-cmake_modules_SetupProtobuf.cmake which is no longer needed now
---
 misc/lbann/Makefile                                |  5 +-
 .../files/patch-cmake_modules_SetupProtobuf.cmake  | 13 ----
 misc/lbann/files/patch-protobuf                    | 78 ++++++++++++++++++++++
 3 files changed, 81 insertions(+), 15 deletions(-)

diff --git a/misc/lbann/Makefile b/misc/lbann/Makefile
index 1f145f969d1c..86a29e0283a7 100644
--- a/misc/lbann/Makefile
+++ b/misc/lbann/Makefile
@@ -21,7 +21,7 @@ LIB_DEPENDS=	libconduit.so:science/conduit \
 		libprotobuf.so:devel/protobuf \
 		libsiloh5.so:science/silo
 
-USES=		cmake:testing compiler:c++17-lang localbase pkgconfig
+USES=		cmake:testing compiler:c++17-lang localbase:ldflags pkgconfig
 
 USE_GITHUB=	yes
 GH_ACCOUNT=	LLNL
@@ -41,7 +41,8 @@ CMAKE_OFF=	LBANN_WITH_CNPY \
 CMAKE_ON=	LBANN_USE_PROTOBUF_MODULE
 CMAKE_TESTING_ON=	LBANN_WITH_UNIT_TESTING # requires MPI cluster
 
-LDFLAGS+=	-lexecinfo
+LDFLAGS+=	-labsl_hash -labsl_log_internal_message -labsl_log_internal_nullguard -labsl_spinlock_wait -lexecinfo
+USE_CXXSTD=	c++17
 
 OPTIONS_SINGLE=		MPI
 OPTIONS_SINGLE_MPI=	MPICH OPENMPI
diff --git a/misc/lbann/files/patch-cmake_modules_SetupProtobuf.cmake b/misc/lbann/files/patch-cmake_modules_SetupProtobuf.cmake
deleted file mode 100644
index 7ad9e788ca42..000000000000
--- a/misc/lbann/files/patch-cmake_modules_SetupProtobuf.cmake
+++ /dev/null
@@ -1,13 +0,0 @@
-- https://gitlab.kitware.com/cmake/cmake/-/issues/24218
-
---- cmake/modules/SetupProtobuf.cmake.orig	2022-12-02 19:45:09 UTC
-+++ cmake/modules/SetupProtobuf.cmake
-@@ -65,7 +65,7 @@ else ()
-     PATH_SUFFIXES lib64/cmake/protobuf lib/cmake/protobuf
-     NO_DEFAULT_PATH)
-   if(NOT Protobuf_FOUND)
--    find_package(Protobuf "${PROTOBUF_MIN_VERSION}" CONFIG QUIET REQUIRED)
-+    find_package(Protobuf "${PROTOBUF_MIN_VERSION}" QUIET REQUIRED)
-   endif ()
-   message(STATUS "Found Protobuf: ${Protobuf_DIR}")
- endif ()
diff --git a/misc/lbann/files/patch-protobuf b/misc/lbann/files/patch-protobuf
new file mode 100644
index 000000000000..fae535a200d7
--- /dev/null
+++ b/misc/lbann/files/patch-protobuf
@@ -0,0 +1,78 @@
+--- src/utils/protobuf.cpp.orig	2022-11-12 00:17:51 UTC
++++ src/utils/protobuf.cpp
+@@ -41,9 +41,8 @@
+ // should be refactored to use the specialized "zero-copy" streams
+ // that ship with protobuf.
+ 
+-namespace pb = google::protobuf;
+-static pb::FieldDescriptor const*
+-get_oneof_field_descriptor(pb::Message const& msg,
++static google::protobuf::FieldDescriptor const*
++get_oneof_field_descriptor(google::protobuf::Message const& msg,
+                            std::string const& oneof_name)
+ {
+   auto oneof_handle = msg.GetDescriptor()->FindOneofByName(oneof_name);
+@@ -52,14 +51,14 @@ get_oneof_field_descriptor(pb::Message const& msg,
+   return msg.GetReflection()->GetOneofFieldDescriptor(msg, oneof_handle);
+ }
+ 
+-bool lbann::protobuf::has_oneof(pb::Message const& msg,
++bool lbann::protobuf::has_oneof(google::protobuf::Message const& msg,
+                                 std::string const& oneof_name)
+ {
+   return (bool)get_oneof_field_descriptor(msg, oneof_name);
+ }
+ 
+-pb::Message const&
+-lbann::protobuf::get_oneof_message(pb::Message const& msg,
++google::protobuf::Message const&
++lbann::protobuf::get_oneof_message(google::protobuf::Message const& msg,
+                                    std::string const& oneof_name)
+ {
+   auto oneof_field = get_oneof_field_descriptor(msg, oneof_name);
+@@ -71,7 +70,7 @@ lbann::protobuf::get_oneof_message(pb::Message const& 
+                 "}\n");
+   }
+ 
+-  if (oneof_field->type() != pb::FieldDescriptor::TYPE_MESSAGE) {
++  if (oneof_field->type() != google::protobuf::FieldDescriptor::TYPE_MESSAGE) {
+     LBANN_ERROR("Oneof \"",
+                 oneof_name,
+                 "\" has field \"",
+@@ -105,15 +104,15 @@ static std::string remove_scope_from_type(std::string 
+     return type.substr(pos + 1);
+ }
+ 
+-std::string lbann::protobuf::message_type(pb::Message const& msg)
++std::string lbann::protobuf::message_type(google::protobuf::Message const& msg)
+ {
+   return msg.GetDescriptor()->name();
+ }
+ 
+-std::string lbann::protobuf::message_type(pb::Any const& msg)
++std::string lbann::protobuf::message_type(google::protobuf::Any const& msg)
+ {
+   std::string full_type;
+-  pb::Any::ParseAnyTypeUrl(msg.type_url(), &full_type);
++  google::protobuf::Any::ParseAnyTypeUrl(msg.type_url(), &full_type);
+   return remove_scope_from_type(full_type);
+ }
+ 
+@@ -171,7 +170,7 @@ void lbann::protobuf::text::fill(std::istream& is,
+ void lbann::protobuf::text::fill(std::string const& str,
+                                  google::protobuf::Message& msg)
+ {
+-  if (!pb::TextFormat::ParseFromString(str, &msg))
++  if (!google::protobuf::TextFormat::ParseFromString(str, &msg))
+     LBANN_ERROR("Unable to parse prototext from string.");
+ }
+ 
+@@ -187,7 +186,7 @@ void lbann::protobuf::text::write(std::ostream& os,
+                                   google::protobuf::Message const& msg)
+ {
+   google::protobuf::io::OstreamOutputStream output(&os);
+-  if (!pb::TextFormat::Print(msg, &output))
++  if (!google::protobuf::TextFormat::Print(msg, &output))
+     LBANN_ERROR("Failed to print prototext to stream.");
+ }
+