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

"Pierre Labastie" ([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:39 +0800, Xi Ruoyao wrote:
> 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
> 
This fails with:
FAILED: CMakeFiles/protoc.dir/src/google/protobuf/compiler/main.cc.o 
/usr/bin/c++ -DPROTOBUF_USE_DLLS -I/sources/protobuf/protobuf-
31.0/build -I/sources/protobuf/protobuf-31.0 -
I/sources/protobuf/protobuf-31.0/build/src -
I/sources/protobuf/protobuf-31.0/src -I/sources/protobuf/protobuf-
31.0/third_party/utf8_range -O3 -DNDEBUG -fPIE -MD -MT
CMakeFiles/protoc.dir/src/google/protobuf/compiler/main.cc.o -MF
CMakeFiles/protoc.dir/src/google/protobuf/compiler/main.cc.o.d -o
CMakeFiles/protoc.dir/src/google/protobuf/compiler/main.cc.o -c
/sources/protobuf/protobuf-31.0/src/google/protobuf/compiler/main.cc

In file included from /sources/protobuf/protobuf-
31.0/upb/reflection/common.h:15,
                 from /sources/protobuf/protobuf-
31.0/upb/reflection/def_pool.h:15,
                 from /sources/protobuf/protobuf-
31.0/upb/reflection/def.h:12,
                 from /sources/protobuf/protobuf-
31.0/upb/reflection/def.hpp:26,
                 from /sources/protobuf/protobuf-
31.0/upb_generator/minitable/generator.h:9,
                 from /sources/protobuf/protobuf-
31.0/src/google/protobuf/compiler/main.cc:20:
/sources/protobuf/protobuf-
31.0/upb/reflection/descriptor_bootstrap.h:14:10: fatal error:
google/protobuf/descriptor.upb.h: No such file or directory
   14 | #include "google/protobuf/descriptor.upb.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Note that there is
<sourcedir>/upb/reflection/cmake/google/protobuf/descriptor.upb.h,
but it cannot be found because there is no
-I<sourcedir>/upb/reflection/cmake
so I guess we need some "target_include_directories" somewhere...

Pierre

-- 
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.