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

protobuf: Update to the latest version #25194

Open
tiagogaspar8 opened this issue Oct 24, 2024 · 23 comments
Open

protobuf: Update to the latest version #25194

tiagogaspar8 opened this issue Oct 24, 2024 · 23 comments

Comments

@tiagogaspar8
Copy link
Contributor

Maintainer: Ken Keys [email protected] @kenkeys
Environment: All

Description:

The protobuf package is extremely out of date. I have tried to update it but unfortunately, I don't have enough knowledge to do it myself, and as I'm trying to update the netdata package, it needs the latest version.

@Ra2-IFV
Copy link
Contributor

Ra2-IFV commented Nov 13, 2024

It introduced a new dependency, abseil, openwrt doen't have this

@tiagogaspar8
Copy link
Contributor Author

I managed to compile protobuf, I will submit a pull request as soon as I can

@Ra2-IFV
Copy link
Contributor

Ra2-IFV commented Nov 13, 2024

Yeah I also did it, just need to get a copy abseil and place it under third_party/abseil-cpp

index 7e60e8498..9cb94b726 100644
--- a/libs/protobuf/Makefile
+++ b/libs/protobuf/Makefile
@@ -8,19 +8,19 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=protobuf
-PKG_VERSION:=3.17.3
-PKG_RELEASE:=2
+PKG_VERSION:=28.3
+PKG_RELEASE:=1
 
-PKG_SOURCE:=$(PKG_NAME)-cpp-$(PKG_VERSION).tar.gz
-PKG_SOURCE_URL:=https://github.com/google/protobuf/releases/download/v$(PKG_VERSION)
-PKG_HASH:=51cec99f108b83422b7af1170afd7aeb2dd77d2bcbb7b6bad1f92509e9ccf8cb
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=https://github.com/protocolbuffers/protobuf/releases/download/v$(PKG_VERSION)
+PKG_HASH:=7c3ebd7aaedd86fa5dc479a0fda803f602caaf78d8aff7ce83b89e1b8ae7442a
 
 PKG_MAINTAINER:=Ken Keys <[email protected]>
 PKG_LICENSE:=BSD-3-Clause
 PKG_LICENSE_FILES:=LICENSE
 PKG_CPE_ID:=cpe:/a:google:protobuf
 
-CMAKE_SOURCE_SUBDIR:=cmake
+# CMAKE_SOURCE_SUBDIR:=cmake
 
 include $(INCLUDE_DIR)/package.mk
 include $(INCLUDE_DIR)/host-build.mk

@tiagogaspar8
Copy link
Contributor Author

You don't need that, protobuff automatically pulls, compiles and installs abseil, I can share the makefile in a pull request later today, I'd appreciate your input 😁

@vortexilation
Copy link
Contributor

vortexilation commented Nov 13, 2024

How about separating abseil-cpp dependency from protobuf ? , this will make version pinning and updating easier without dependent to each other :

# SPDX-License-Identifier: GPL-2.0-only
#
# Copyright (C) 2021 Martin Schneider <[email protected]>

include $(TOPDIR)/rules.mk

PKG_NAME:=abseil-cpp
PKG_VERSION:=20240116.1
PKG_RELEASE:=1

PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/abseil/abseil-cpp.git
PKG_MIRROR_HASH:=1afa569daf7268a724924ab98b54af8cdbbefa33dc8e044ce5df9bd5e708f640
PKG_SOURCE_DATE:=2024-11-08
PKG_SOURCE_VERSION:=2f9e432cce407ce0ae50676696666f33a77d42ac

PKG_LICENSE:=MIT
PKG_LICENSE_FILES:=LICENSE

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/cmake.mk

define Package/abseil-cpp
	SECTION:=libs
	CATEGORY:=Libraries
	TITLE:=Abseil Common Libraries
	URL:=https://github.com/abseil/abseil-cpp
	DEPENDS:=+libstdcpp
endef

define Package/abseil-cpp/description
	The repository contains the Abseil C++ library code. 
	Abseil is an open-source collection of C++ code (compliant to C++14) designed to augment the C++ standard library.
endef

CMAKE_OPTIONS+=-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON

define Package/abseil-cpp/install
	$(INSTALL_DIR) $(1)/usr/lib
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/* $(1)/usr/lib/
endef

define Build/InstallDev
	$(INSTALL_DIR) $(1)/usr/lib
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/* $(1)/usr/lib
	$(INSTALL_DIR) $(1)/usr/include
	$(CP) $(PKG_INSTALL_DIR)/usr/include/* $(1)/usr/include
endef

$(eval $(call BuildPackage,abseil-cpp))
diff -Naur a/libs/protobuf/Makefile b/libs/protobuf/Makefile
--- a/libs/protobuf/Makefile
+++ b/libs/protobuf/Makefile
@@ -8,19 +8,21 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=protobuf
-PKG_VERSION:=3.17.3
-PKG_RELEASE:=2
+PKG_VERSION:=25.3
+PKG_RELEASE:=1
 
-PKG_SOURCE:=$(PKG_NAME)-cpp-$(PKG_VERSION).tar.gz
-PKG_SOURCE_URL:=https://github.com/google/protobuf/releases/download/v$(PKG_VERSION)
-PKG_HASH:=51cec99f108b83422b7af1170afd7aeb2dd77d2bcbb7b6bad1f92509e9ccf8cb
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL:=https://github.com/protocolbuffers/protobuf.git
+PKG_MIRROR_HASH:=63ddc2978bc7cdd357f66ed70f273a787960e990a328887b7f65d119094c7353
+PKG_SOURCE_DATE:=2024-11-08
+PKG_SOURCE_VERSION:=4a2aef570deb2bfb8927426558701e8bfc26f2a4
 
 PKG_MAINTAINER:=Ken Keys <[email protected]>
 PKG_LICENSE:=BSD-3-Clause
 PKG_LICENSE_FILES:=LICENSE
 PKG_CPE_ID:=cpe:/a:google:protobuf
 
-CMAKE_SOURCE_SUBDIR:=cmake
+CMAKE_BINARY_SUBDIR:=build
 
 include $(INCLUDE_DIR)/package.mk
 include $(INCLUDE_DIR)/host-build.mk
@@ -31,7 +33,7 @@
   CATEGORY:=Libraries
   TITLE:=A structured data encoding library
   URL:=https://github.com/google/protobuf
-  DEPENDS:=+zlib +libpthread +libatomic +libstdcpp
+  DEPENDS:=+zlib +libpthread +libatomic +libstdcpp +abseil-cpp
 endef
 
 define Package/protobuf
@@ -74,9 +76,12 @@
 	-Dprotobuf_BUILD_PROTOC_BINARIES=ON \
 	-Dprotobuf_BUILD_TESTS=OFF \
 	-Dprotobuf_WITH_ZLIB=ON \
-	-DBUILD_SHARED_LIBS=ON
+	-DBUILD_SHARED_LIBS=ON \
+	-Dprotobuf_ABSL_PROVIDER=package \
+	-Dabsl_DIR=$(STAGING_DIR)/usr/lib/cmake/absl
 
 TARGET_LDFLAGS += -latomic
+TARGET_CFLAGS += -fPIC
 
 define Build/InstallDev
 	$(call Build/InstallDev/cmake,$(1))
@@ -84,28 +89,23 @@
 	$(SED) 's,/usr/lib,$$$${exec_prefix}/lib,g' $(1)/usr/lib/pkgconfig/protobuf.pc
 	$(SED) 's,/usr/include,$$$${prefix}/include,g' $(1)/usr/lib/pkgconfig/protobuf-lite.pc
 	$(SED) 's,/usr/lib,$$$${exec_prefix}/lib,g' $(1)/usr/lib/pkgconfig/protobuf-lite.pc
+	$(INSTALL_DIR) $(1)/usr/lib $(1)/usr/include
+	$(CP) $(PKG_INSTALL_DIR)/usr/include/* $(1)/usr/include/
+	$(CP) $(PKG_INSTALL_DIR)/usr/lib/* $(1)/usr/lib/
+	$(CP) $(PKG_INSTALL_DIR)/usr/lib/cmake $(1)/usr/lib/cmake
+	$(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig $(1)/usr/lib/pkgconfig
 endef
 
 define Package/protobuf-lite/install
-	$(INSTALL_DIR) \
-		$(1)/usr/lib
-
-	$(CP) \
-		$(PKG_INSTALL_DIR)/usr/lib/libprotobuf-lite.so* \
-		$(1)/usr/lib/
+	$(INSTALL_DIR) $(1)/usr/lib
+	$(CP) $(PKG_INSTALL_DIR)/usr/lib/libutf8_* $(1)/usr/lib/
+	$(CP) $(PKG_INSTALL_DIR)/usr/lib/libprotobuf-lite.so* $(1)/usr/lib/
 endef
 
 define Package/protobuf/install
-	$(INSTALL_DIR) \
-		$(1)/usr/lib
-
-	$(CP) \
-		$(PKG_INSTALL_DIR)/usr/lib/libprotoc.so*  \
-		$(1)/usr/lib/
-
-	$(CP) \
-		$(PKG_INSTALL_DIR)/usr/lib/libprotobuf.so* \
-		$(1)/usr/lib/
+	$(INSTALL_DIR) $(1)/usr/lib
+	$(CP) $(PKG_INSTALL_DIR)/usr/lib/libprotoc.so* $(1)/usr/lib/
+	$(CP) $(PKG_INSTALL_DIR)/usr/lib/libprotobuf.so* $(1)/usr/lib/
 endef
 
 $(eval $(call BuildPackage,protobuf))
#
# Copyright (C) 2011 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=libprotobuf-c
PKG_VERSION:=1.5.0
PKG_RELEASE:=1

PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/protobuf-c/protobuf-c.git
PKG_MIRROR_HASH:=09f22b5b5ef76c51969eefea9dd4d3e8cc5064b5c64de996d0596887c8cda34b
PKG_SOURCE_DATE:=2024-11-10
PKG_SOURCE_VERSION:=2480f4d9d2fa97e5511ed0914ee529a344e969a7
#PKG_BUILD_DIR:=$(BUILD_DIR)/protobuf-c-$(PKG_VERSION)
#HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/protobuf-c-$(PKG_VERSION)

PKG_MAINTAINER:=
PKG_LICENSE:=BSD-2-Clause
PKG_LICENSE_FILES:=LICENSE
PKG_CPE_ID:=cpe:/a:protobuf-c_project:protobuf-c

HOST_BUILD_DEPENDS:=protobuf/host
PKG_BUILD_DEPENDS:=protobuf

CMAKE_INSTALL:=1
CMAKE_SOURCE_SUBDIR:=build-cmake

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/host-build.mk
include $(INCLUDE_DIR)/cmake.mk
include $(INCLUDE_DIR)/nls.mk

define Package/libprotobuf-c
  TITLE:=Protocol Buffers library
  SECTION:=libs
  CATEGORY:=Libraries
  DEPENDS:=+libpthread +libatomic +libstdcpp +protobuf
  URL:=https://github.com/protobuf-c/protobuf-c
endef

define Package/libprotobuf-c/description
  Runtime library to use Google Protocol Buffers from C applications.
  Protocol Buffers are a way of encoding structured data in an efficient yet
  extensible format. Google uses Protocol Buffers for almost all of its
  internal RPC protocols and file formats.
endef

##For protoc & git runtime at configure
ifeq ($(CONFIG_BUILD_NLS),y)
	export LD_LIBRARY_PATH=$(STAGING_DIR)/usr/lib:$(ICONV_PREFIX)/lib:$(INTL_PREFIX)/lib
endif

CMAKE_HOST_OPTIONS += \
	-DBUILD_SHARED_LIBS=ON \
	-DCMAKE_CXX_STANDARD=11 \
	-DCMAKE_SKIP_RPATH=OFF \
	-DCMAKE_INSTALL_RPATH="${STAGING_DIR_HOSTPKG}/lib"

CMAKE_OPTIONS += \
	-DBUILD_SHARED_LIBS=ON \
	-DBUILD_PROTOC=ON \
	-DCMAKE_SKIP_RPATH=OFF \
	-DCMAKE_INSTALL_RPATH="${STAGING_DIR}/usr/lib"

define Build/InstallDev
	$(INSTALL_DIR) $(1)/usr/include
	$(CP) $(PKG_INSTALL_DIR)/usr/include/* $(1)/usr/include
	$(INSTALL_DIR) $(1)/usr/lib
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/* $(1)/usr/lib/
	$(INSTALL_DIR) $(1)/usr/bin
	$(CP) $(PKG_INSTALL_DIR)/usr/bin/protoc-gen-c $(1)/usr/bin
	$(LN) protoc-gen-c $(1)/usr/bin/protoc-c
endef

define Package/libprotobuf-c/install
	$(INSTALL_DIR) $(1)/usr/lib
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/libprotobuf-c.so* $(1)/usr/lib/
	
endef

$(eval $(call BuildPackage,libprotobuf-c))
$(eval $(call HostBuild))

I suggest to use protobuf version 25.3 or 26.0 as version above it is not supported by protobuf-c

Above Makefile changes has been tested by compiling frr and netdata v2.0.0.

@tiagogaspar8
Copy link
Contributor Author

tiagogaspar8 commented Nov 13, 2024

You managed to compile netdata 2.0? 😲
I have a pull request open here for aged and I was looking for help on how to get it to build...
#22677
Also, do you want to open a pull request for Protobuf?

@Ra2-IFV
Copy link
Contributor

Ra2-IFV commented Nov 13, 2024

I fixed the patch for protobuf 28.3, if anyone needs it

I suggest to use protobuf version 25.3 or 26.0 as version above it is not supported by protobuf-c

Might need refreshing if you are updating to a different version

--- a/cmake/install.cmake
+++ b/cmake/install.cmake
@@ -35,8 +35,8 @@ endif ()
 
 foreach(_library ${_protobuf_libraries})
   if (UNIX AND NOT APPLE)
-    set_property(TARGET ${_library}
-      PROPERTY INSTALL_RPATH "$ORIGIN")
+    # set_property(TARGET ${_library}
+    #   PROPERTY INSTALL_RPATH "$ORIGIN")
   elseif (APPLE)
     set_property(TARGET ${_library}
       PROPERTY INSTALL_RPATH "@loader_path")
@@ -62,8 +62,8 @@ if (protobuf_BUILD_PROTOC_BINARIES)
   endif ()
   foreach (binary IN LISTS _protobuf_binaries)
     if (UNIX AND NOT APPLE)
-      set_property(TARGET ${binary}
-        PROPERTY INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
+      # set_property(TARGET ${binary}
+      #   PROPERTY INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
     elseif (APPLE)
       set_property(TARGET ${binary}
         PROPERTY INSTALL_RPATH "@loader_path/../lib")

@vortexilation
Copy link
Contributor

@tiagogaspar8
Yes, but forgot to mention it's all on glibc, not musl, i will try musl now.
Probably harder on musl.

About your post on that PR, i am not encountering the same thing on glibc.

You could open up protobuf PR based on my finding if you want.

Here is the rough draft for netdata 2.0 package and libs package :
netdata.zip

The netdata 2.0 package from me is different, it using cmake build system instead.

@vortexilation
Copy link
Contributor

vortexilation commented Nov 13, 2024

@tiagogaspar8
Your previous issue on netdata repo, if I am not mistaken I have encountered it before, try to not using bundled abseil-cpp/protobuf from netdata.
Use it's own external abseil-cpp and protobuf OpenWrt package like above.

[EDIT]
On musl, it's totally different world, lot's of new errors.

Stuck with :

Error loading shared library libatomic.so.1: No such file or directory (needed by /home/user/works/openwrt/staging_dir/target-x86_64_musl/usr/bin/protoc)
Error loading shared library libprotoc.so.25.3.0: No such file or directory (needed by /home/user/works/openwrt/staging_dir/target-x86_64_musl/usr/bin/protoc)

Even tough I have set LD_LIBRARY_PATH

[EDIT#2]
Managed to compiled netdata 2.0 for musl targeting x86/64.

Need to add the following to protobuf Makefile :

TARGET_LDFLAGS += \
	-Wl,-rpath $(STAGING_DIR_ROOT)/lib:$(STAGING_DIR_ROOT)/usr/lib

@tiagogaspar8
Copy link
Contributor Author

tiagogaspar8 commented Nov 23, 2024

Hey @vortexilation, I was trying your suggestion but it's not working, and now I noticed you mentioned it's working for you when targeting x86/64, could you try your setup targeting another arch besides x86?
For reference, the latest error I'm seeing is:

[422/872] cd /mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0 && /mnt/openwrt/ss_mod/staging_dir/host/bin/cmake -E make_directory /mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0/CMakeFiles && /mnt/openwrt/ss_mod/staging_dir/host/bin/cmake -E touch /mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0/CMakeFiles/ebpf-co-re-complete && /mnt/openwrt/ss_mod/staging_dir/host/bin/cmake -E touch /mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0/ebpf-co-re-prefix/src/ebpf-co-re-stamp/ebpf-co-re-done
[423/872] cd /mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0/ebpf-code-legacy-prefix/src/ebpf-code-legacy-build && sh -c "mkdir -p /mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0/ebpf-legacy-build/ebpf.d && mv /mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0/ebpf-legacy/*netdata_ebpf_*.o /mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0/ebpf-legacy-build/ebpf.d" && /mnt/openwrt/ss_mod/staging_dir/host/bin/cmake -E touch /mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0/ebpf-code-legacy-prefix/src/ebpf-code-legacy-stamp/ebpf-code-legacy-build
[424/872] cd /mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0 && /mnt/openwrt/ss_mod/staging_dir/target-aarch64_cortex-a53_musl/usr/bin/protoc-28.3.0 -I/mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0/src/aclk/aclk-schemas --cpp_out=/mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0/src/aclk/aclk-schemas /mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0/src/aclk/aclk-schemas/proto/aclk/v1/lib.proto
FAILED: src/aclk/aclk-schemas/proto/aclk/v1/lib.pb.cc src/aclk/aclk-schemas/proto/aclk/v1/lib.pb.h /mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0/src/aclk/aclk-schemas/proto/aclk/v1/lib.pb.cc /mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0/src/aclk/aclk-schemas/proto/aclk/v1/lib.pb.h 
cd /mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0 && /mnt/openwrt/ss_mod/staging_dir/target-aarch64_cortex-a53_musl/usr/bin/protoc-28.3.0 -I/mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0/src/aclk/aclk-schemas --cpp_out=/mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0/src/aclk/aclk-schemas /mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0/src/aclk/aclk-schemas/proto/aclk/v1/lib.proto
qemu-aarch64-static: Could not open '/lib/ld-musl-aarch64.so.1': No such file or directory
ninja: build stopped: subcommand failed.
make[2]: *** [Makefile:106: /mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0/.built] Error 1

Thanks!

@vortexilation
Copy link
Contributor

vortexilation commented Nov 23, 2024

@tiagogaspar8
Trying to build for aarch64_cortex-a53_musl now, but my build environment quite messy as currently testing for kernel 6.12.

Could you try to locate "ld-musl-aarch64.so.1" in your staging_dir directory?. I assume it's on $(STAGING_DIR_ROOT)/lib ?.

[EDIT]
Try to add this in your netdata Makefile :

export LD_LIBRARY_PATH=$(STAGING_DIR_ROOT)/lib

@tiagogaspar8
Copy link
Contributor Author

Tried it but no luck unfortunately 😢
I think the issue stems from this line here:
https://github.com/netdata/netdata/blob/v2.0.0/packaging/cmake/Modules/NetdataProtobuf.cmake#L174
Netdata is trying to compile the files for aclk-schemas but it doesn't pass the LD flags to protobuf as it should, not sure how to fix it though

@vortexilation
Copy link
Contributor

vortexilation commented Nov 23, 2024

/mnt/openwrt/ss_mod/staging_dir/target-aarch64_cortex-a53_musl/usr/bin/protoc-28.3.0 -I/mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0/src/aclk/aclk-schemas --cpp_out=/mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0/src/aclk/aclk-schemas /mnt/openwrt/ss_mod/build_dir/target-aarch64_cortex-a53_musl/netdata-v2.0.0/src/aclk/aclk-schemas/proto/aclk/v1/lib.proto

I think it failed to run protoc successfully because of could not found ld-musl-aarch64.so.1 dependency.

Where do you put the line ?

export LD_LIBRARY_PATH=$(STAGING_DIR_ROOT)/lib

@tiagogaspar8
Copy link
Contributor Author

BTW, forgot to say I found the mentioned lib in staging_dir/target-aarch64_cortex-a53_musl/root-mediatek/lib

I think it failed to run protoc successfully because of could not found ld-musl-aarch64.so.1 dependency.

Yes, I just thought it was looking for it in the wrong place because the error states it's looking for it in the /lib, which for me means root filesystem of the building host, am I wrong?

Where do you put the line?

I put it above the CMAKE_OPTIONS as in your makefile

@vortexilation
Copy link
Contributor

vortexilation commented Nov 23, 2024

BTW, forgot to say I found the mentioned lib in staging_dir/target-aarch64_cortex-a53_musl/root-mediatek/lib

Yes that's exactly what $(STAGING_DIR_ROOT)/lib is.

Yes, I just thought it was looking for it in the wrong place because the error states it's looking for it in the /lib, which for me means root filesystem of the building host, am I wrong?

Yes, you are correct, the netdata build system is not also looking at the OpenWrt toolchain, $(STAGING_DIR_ROOT)/lib , which is ld-musl-aarch64.so.1 located.

Btw what is your target device?

@tiagogaspar8
Copy link
Contributor Author

The device I'm currently building for is Gl.inet MT6000, Mediatek Filogic.
Did your build succeed?

@vortexilation
Copy link
Contributor

vortexilation commented Nov 23, 2024

Yes, my build is succeed (NXP i.MX8M), even with latest netdata 2.0.3.
Probably the issue is with your build host/os ?, I didn't encounter the ld-musl-aarch64.so.1 not found error.
I am using debian sid.

Changes :
Protobuf Makefile

#
# Copyright (C) 2007-2015 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=protobuf
PKG_VERSION:=25.3
PKG_RELEASE:=1

PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/protocolbuffers/protobuf.git
PKG_MIRROR_HASH:=63ddc2978bc7cdd357f66ed70f273a787960e990a328887b7f65d119094c7353
PKG_SOURCE_DATE:=2024-11-08
PKG_SOURCE_VERSION:=4a2aef570deb2bfb8927426558701e8bfc26f2a4

PKG_MAINTAINER:=Ken Keys <[email protected]>
PKG_LICENSE:=BSD-3-Clause
PKG_LICENSE_FILES:=LICENSE
PKG_CPE_ID:=cpe:/a:google:protobuf

CMAKE_BINARY_SUBDIR:=build

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/host-build.mk
include $(INCLUDE_DIR)/cmake.mk

define Package/protobuf/Default
  SECTION:=libs
  CATEGORY:=Libraries
  TITLE:=A structured data encoding library
  URL:=https://github.com/google/protobuf
  DEPENDS:=+zlib +libpthread +libatomic +libstdcpp +abseil-cpp
endef

define Package/protobuf
  $(call Package/protobuf/Default)
  DEPENDS+=+protobuf-lite
endef

define Package/protobuf-lite
  $(call Package/protobuf/Default)
endef

define Package/protobuf/description/Default
Protocol Buffers are a way of encoding structured data in an efficient
yet extensible format. Google uses Protocol Buffers for almost all
of its internal RPC protocols and file formats.
endef

define Package/protobuf/description
$(call Package/protobuf/description/Default)

This package provides the libprotoc, libprotobuf, and libprotobuf-lite
libraries.  For a much smaller protobuf package, see "protobuf-lite".

endef

define Package/protobuf-lite/description
$(call Package/protobuf/description/Default)

This package provides the libprotobuf-lite library.

endef

#ifdef CONFIG_USE_MUSL
#TARGET_LDFLAGS += \
#	-Wl,-rpath $(STAGING_DIR_ROOT)/lib:$(STAGING_DIR_ROOT)/usr/lib
#endif

CMAKE_HOST_OPTIONS += \
	-Dprotobuf_BUILD_PROTOC_BINARIES=ON \
	-Dprotobuf_BUILD_TESTS=OFF \
	-DBUILD_SHARED_LIBS=OFF \
	-DCMAKE_INSTALL_LIBDIR=lib

CMAKE_OPTIONS += \
	-Dprotobuf_BUILD_PROTOC_BINARIES=ON \
	-Dprotobuf_BUILD_TESTS=OFF \
	-Dprotobuf_WITH_ZLIB=ON \
	-DBUILD_SHARED_LIBS=ON \
	-Dprotobuf_ABSL_PROVIDER=package \
	-Dabsl_DIR=$(STAGING_DIR)/usr/lib/cmake/absl

TARGET_LDFLAGS += -latomic
TARGET_CFLAGS += -fPIC

define Host/Install
	$(INSTALL_DIR) $(STAGING_DIR_HOSTPKG)/bin
	$(CP) $(HOST_BUILD_DIR)/build/protoc* $(1)/bin/
endef

define Build/InstallDev
	$(call Build/InstallDev/cmake,$(1))
	$(SED) 's,/usr/include,$$$${prefix}/include,g' $(1)/usr/lib/pkgconfig/protobuf.pc
	$(SED) 's,/usr/lib,$$$${exec_prefix}/lib,g' $(1)/usr/lib/pkgconfig/protobuf.pc
	$(SED) 's,/usr/include,$$$${prefix}/include,g' $(1)/usr/lib/pkgconfig/protobuf-lite.pc
	$(SED) 's,/usr/lib,$$$${exec_prefix}/lib,g' $(1)/usr/lib/pkgconfig/protobuf-lite.pc
	$(INSTALL_DIR) $(1)/usr/lib $(1)/usr/include
	$(CP) $(PKG_INSTALL_DIR)/usr/include/* $(1)/usr/include/
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/* $(1)/usr/lib/
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/cmake $(1)/usr/lib/cmake
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig $(1)/usr/lib/pkgconfig
endef

define Package/protobuf-lite/install
	$(INSTALL_DIR) $(1)/usr/lib
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/libutf8_* $(1)/usr/lib/
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/libprotobuf-lite.so* $(1)/usr/lib/
endef

define Package/protobuf/install
	$(INSTALL_DIR) $(1)/usr/lib
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/libprotoc.so* $(1)/usr/lib/
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/libprotobuf.so* $(1)/usr/lib/
endef

$(eval $(call BuildPackage,protobuf))
$(eval $(call BuildPackage,protobuf-lite))
$(eval $(call HostBuild,protobuf))

Netdata Makefile :

#
# Copyright (C) 2008-2016 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=netdata
PKG_VERSION:=2.0.3
PKG_RELEASE:=1

PKG_MAINTAINER:=Josef Schlehofer <[email protected]>, Daniel Engberg <[email protected]>
PKG_LICENSE:=GPL-3.0-or-later
PKG_LICENSE_FILES:=COPYING
PKG_CPE_ID:=cpe:/a:my-netdata:netdata

PKG_SOURCE:=$(PKG_NAME)-v$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://github.com/netdata/netdata/releases/download/v$(PKG_VERSION)
PKG_HASH:=f75c3829bf50bfaca436afcafe99f6c64ca5a89bcdd67ca22acd35c42a4b4fb5
PKG_BUILD_DIR=$(BUILD_DIR)/$(PKG_NAME)-v$(PKG_VERSION)

PKG_INSTALL:=1
PKG_BUILD_PARALLEL:=1
PKG_FIXUP:=autoreconf
PKG_BUILD_FLAGS:=no-mips16 gc-sections

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/cmake.mk
include $(INCLUDE_DIR)/nls.mk

define Package/netdata
  SECTION:=admin
  CATEGORY:=Administration
  DEPENDS:=+zlib +libuuid +libuv +libmnl +libjson-c +libpcap +libjudy +libsnappy $(INTL_DEPENDS) $(ICONV_DEPENDS) +libopenssl +liblz4 +protobuf +libyaml +libzstd \
  +libnetfilter-acct +brotli +libdatachannel $(BPF_DEPENDS) +libelf +zlib +kmod-sched-core +kmod-sched-bpf +libcurl +libstdcpp +libopenssl
  TITLE:=Real-time performance monitoring tool
  URL:=https://www.netdata.cloud/
endef

define Package/netdata/description
  netdata is a highly optimized Linux daemon providing real-time performance
  monitoring for Linux systems, applications and SNMP devices over the web.

  If you want to use Python plugins install python3, python3-yaml and
  python3-urllib3
endef

TARGET_CFLAGS := $(filter-out -O%,$(TARGET_CFLAGS)) -O3
TARGET_LDFLAGS += -L$(STAGING_DIR)/usr/lib

CMAKE_OPTIONS += \
	-DCMAKE_INSTALL_PREFIX=/ \
	-DCMAKE_CROSSCOMPILING=TRUE \
	-DENABLE_ACLK=TRUE \
	-DENABLE_CLOUD=TRUE \
	-DENABLE_DBENGINE=TRUE \
	-DENABLE_WEBRTC=FALSE \
	-DENABLE_H2O=TRUE \
	-DENABLE_PLUGIN_NFACCT=TRUE \
	-DENABLE_PLUGIN_CUPS=FALSE \
	-DENABLE_PLUGIN_FREEIPMI=FALSE \
	-DENABLE_EXPORTER_MONGODB=TRUE \
	-DENABLE_PLUGIN_APPS=TRUE \
	-DENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE=TRUE \
	-DENABLE_PLUGIN_XENSTAT=FALSE \
	-DENABLE_PLUGIN_EBPF=FALSE \
	-DENABLE_PLUGIN_GO=FALSE \
	-DENABLE_PLUGIN_SYSTEMD_JOURNAL=FALSE \
	-DProtobuf_PROTOC_EXECUTABLE=$(STAGING_DIR_HOSTPKG)/bin/protoc

define Package/netdata/conffiles
/etc/netdata/
endef

define Package/netdata/install
	$(INSTALL_DIR) $(1)/etc/netdata/custom-plugins.d
	$(CP) $(PKG_INSTALL_DIR)/etc/netdata $(1)/etc
	$(CP) ./files/netdata.conf $(1)/etc/netdata
	touch $(1)/etc/netdata/.opt-out-from-anonymous-statistics
	$(INSTALL_DIR) $(1)/usr/lib
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/netdata $(1)/usr/lib
	$(CP) $(1)/usr/lib/netdata/conf.d/health_alarm_notify.conf $(1)/etc
	$(INSTALL_DIR) $(1)/usr/libexec/netdata/plugins.d
	$(CP) $(PKG_INSTALL_DIR)/usr/libexec/netdata/plugins.d/tc-qos-helper.sh $(1)/etc
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/netdata $(1)/usr/sbin
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/netdatacli $(1)/usr/sbin
	$(INSTALL_DIR) $(1)/usr/share/netdata
	$(CP) $(PKG_INSTALL_DIR)/usr/share/netdata $(1)/usr/share
	rm $(1)/usr/share/netdata/web/demo*html
	rm $(1)/usr/share/netdata/web/fonts/*.svg
	rm $(1)/usr/share/netdata/web/fonts/*.ttf
	rm $(1)/usr/share/netdata/web/fonts/*.woff
	rm $(1)/usr/share/netdata/web/images/*.png
	rm $(1)/usr/share/netdata/web/images/*.gif
	rm $(1)/usr/share/netdata/web/images/*.ico
	rm -rf $(1)/usr/share/netdata/web/old
	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_BIN) ./files/netdata.init $(1)/etc/init.d/netdata
endef

$(eval $(call BuildPackage,netdata))

@vortexilation
Copy link
Contributor

vortexilation commented Nov 23, 2024

My solution with export LD_LIBRARY_PATH=$(STAGING_DIR_ROOT)/lib is wrong for aarch64 cross-compiling, it should be fixed with protoc binary which build for host (x86_64) not current protoc binary (/mnt/openwrt/ss_mod/staging_dir/target-aarch64_cortex-a53_musl/usr/bin/protoc-28.3.0) which build for aarch64, my latest changes above should fixes it up.

protoc for host (x86_64) need to be re-build with :

make package/protobuf/host/{clean,compile} -j9 V=s 2>&1 | tee build.log

Note : The new protoc for host (x86_64) will exist at /mnt/openwrt/ss_mod/staging_dir/hostpkg/bin directory.
Then continue with netdata re-build.

@tiagogaspar8
Copy link
Contributor Author

Good news! after some testing, I managed to compile!
I am now testing running it in my router, and I've faced a new bug when claiming with the token, have you faced this?
msg="CLAIM: Cannot generate RSA key, EVP_PKEY_keygen() failed"
Regarding Protobud, do you have any reason to have abseil as a separate package? Using your makefile I was not able to build protobuf + abseil, so If I'm going to submit a patch to update protobud it will probably be with the only makefile I can compile 😕

@vortexilation
Copy link
Contributor

Glad that you can build it.

I am now testing running it in my router, and I've faced a new bug when claiming with the token, have you faced this?
msg="CLAIM: Cannot generate RSA key, EVP_PKEY_keygen() failed"

This is happening when running the netdata?

Regarding separate abseil-cpp, If i am not mistaken it was about a package failed to compile if using bundled abseil-cpp, but I cannot recall exactly which package is it.

About protobuf, I suggest to keep it with version 25.3, as above 26.0 will make libprotobuf-c problematic when compiling it.
Also netdata only needs max protobuf 25.3 for compilation.

@tiagogaspar8
Copy link
Contributor Author

This is happening when running the netdata?

Yes, when installed on my router and trying to claim the agent in netdata cloud with the token.

Regarding separate abseil-cpp, If i am not mistaken it was about a package failed to compile if using bundled abseil-cpp, but I cannot recall exactly which package is it.

If you remember let me know so I can find it and troubleshoot it

About protobuf, I suggest to keep it with version 25.3, as above 26.0 will make libprotobuf-c https://github.com/protobuf-c/protobuf-c/pull/711when compiling it.
Also netdata only needs max protobuf 25.3 for compilation.

I'll keep it in version 25 for now, but I'll push it to 25.5, which is the latest bugfix release.
I'm not sure how protobuf-c can be kept, it hasn't been updated in almost a year.

@vortexilation
Copy link
Contributor

vortexilation commented Nov 25, 2024

Yes, when installed on my router and trying to claim the agent in netdata cloud with the token.

Haven't tested netdata thoroughly , I don't experiencing it in here x86_64, maybe you could try to upgrade OpenSSL lib.

There are quite a lot of package depending on protobuf-c , for protobuf 25.3 supports in protobuf-c you need this specific branch.

@vortexilation
Copy link
Contributor

@tiagogaspar8

Node 22.11.0 seems has issue with bundled abseil-cpp from protobuf 25.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants