Re: libupb.a needed by anything using protobuf .cmake files

"Xi Ruoyao" ([email protected] via blfs-dev Mailing List) <[email protected]>
Newsgroups gmane.linux.lfs.beyond.devel
Message-ID <[email protected]>
On Sat, 2025-05-24 at 12:12 +0800, Xi Ruoyao wrote:
> On Fri, 2025-05-23 at 23:20 +0200, Pierre Labastie wrote:
> > /usr/lib/cmake/protobuf/protobuf-targets.cmake contains:
> > -----
> > add_library(protobuf::libupb STATIC IMPORTED)
> > -----
> > So if we remove libupb.a as done in protobuf instructions (since
> > protobuf-31), any CMakeLists.txt using this file will fail with:
> > ----------
> > CMake Error at /usr/lib/cmake/protobuf/protobuf-targets.cmake:132
> > (message):
> >   The imported target "protobuf::libupb" references the file
> > 
> >      "/usr/lib/libupb.a"
> > 
> >   but this file does not exist.  Possible reasons include:
> > 
> >   * The file was deleted, renamed, or moved to another location.
> > 
> >   * An install or uninstall procedure did not complete successfully.
> > 
> >   * The installation package was faulty and contained
> > 
> >      "/usr/lib/cmake/protobuf/protobuf-targets.cmake"
> > 
> >   but not all the files it references.
> > -----------
> > So I think we should remove the line "rm /usr/lib/libupb.a" when
> > installing protobuf. libupb.a is about 520KB in size...
> 
> The problem here is not to save space.  It's just it shouldn't be
> installed even per upstream documentation
> (https://github.com/protocolbuffers/protobuf/blob/main/upb/README.md):
> 
>    While upb offers a C API, the C API & ABI are not stable. For this
>    reason, upb is not generally offered as a C library for direct
>    consumption, and there are no releases.
> 
> I'll try to figure out a way to prevent it from being installed.

Tentative patch:

diff --color -Naur protobuf-31.0/cmake/install.cmake protobuf-31.0.patched/cmake/install.cmake
--- protobuf-31.0/cmake/install.cmake	2025-05-14 23:37:13.000000000 +0800
+++ protobuf-31.0.patched/cmake/install.cmake	2025-05-24 12:39:08.572837445 +0800
@@ -37,9 +37,6 @@
 if (protobuf_BUILD_LIBPROTOC)
     list(APPEND _protobuf_libraries libprotoc)
 endif (protobuf_BUILD_LIBPROTOC)
-if (protobuf_BUILD_LIBUPB)
-  list(APPEND _protobuf_libraries libupb)
-endif ()
 
 foreach(_library ${_protobuf_libraries})
   if (UNIX AND NOT APPLE)
diff --color -Naur protobuf-31.0/cmake/libprotoc.cmake protobuf-31.0.patched/cmake/libprotoc.cmake
--- protobuf-31.0/cmake/libprotoc.cmake	2025-05-14 23:37:13.000000000 +0800
+++ protobuf-31.0.patched/cmake/libprotoc.cmake	2025-05-24 12:28:03.095300298 +0800
@@ -16,8 +16,8 @@
   set_target_properties(libprotoc PROPERTIES
     LINK_DEPENDS ${protobuf_SOURCE_DIR}/src/libprotoc.map)
 endif()
-target_link_libraries(libprotoc PRIVATE libprotobuf)
-target_link_libraries(libprotoc PUBLIC libupb ${protobuf_ABSL_USED_TARGETS})
+target_link_libraries(libprotoc PRIVATE libprotobuf libupb)
+target_link_libraries(libprotoc PUBLIC ${protobuf_ABSL_USED_TARGETS})
 protobuf_configure_target(libprotoc)
 if(protobuf_BUILD_SHARED_LIBS)
   target_compile_definitions(libprotoc


-- 
Xi Ruoyao <[email protected]>
School of Aerospace Science and Technology, Xidian University

-- 
http://lists.linuxfromscratch.org/sympa/info/blfs-dev
Unsubscribe: See the above information page
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.