1SUMMARY = "Protocol Buffers - structured data serialisation mechanism"
2DESCRIPTION = "Protocol Buffers are a way of encoding structured data in an \
3efficient yet extensible format. Google uses Protocol Buffers for almost \
4all of its internal RPC protocols and file formats."
5HOMEPAGE = "https://github.com/google/protobuf"
6SECTION = "console/tools"
7LICENSE = "BSD-3-Clause"
8LIC_FILES_CHKSUM = "file://LICENSE;md5=37b5762e07f0af8c74ce80a8bda4266b"
9
10DEPENDS = "zlib abseil-cpp"
11DEPENDS:append:class-target = " protobuf-native"
12
13SRCREV = "9d0ec0f92b5b5fdeeda11f9dcecc1872ff378014"
14
15SRC_URI = "gitsm://github.com/protocolbuffers/protobuf.git;branch=25.x;protocol=https \
16           file://run-ptest \
17           file://0001-examples-Makefile-respect-CXX-LDFLAGS-variables-fix-.patch \
18           "
19SRC_URI:append:mips:toolchain-clang = " file://0001-Fix-build-on-mips-clang.patch "
20SRC_URI:append:mipsel:toolchain-clang = " file://0001-Fix-build-on-mips-clang.patch "
21
22UPSTREAM_CHECK_GITTAGREGEX = "v(?P<pver>.(25\.(\d+)))"
23
24S = "${WORKDIR}/git"
25
26inherit cmake pkgconfig ptest
27
28PACKAGECONFIG ??= ""
29PACKAGECONFIG:class-native ?= "compiler"
30PACKAGECONFIG:class-nativesdk ?= "compiler"
31PACKAGECONFIG[python] = ",,"
32PACKAGECONFIG[compiler] = "-Dprotobuf_BUILD_PROTOC_BINARIES=ON,-Dprotobuf_BUILD_PROTOC_BINARIES=OFF"
33
34EXTRA_OECMAKE += "\
35    -Dprotobuf_BUILD_SHARED_LIBS=ON \
36    -Dprotobuf_BUILD_LIBPROTOC=ON \
37    -Dprotobuf_BUILD_TESTS=OFF \
38    -Dprotobuf_BUILD_EXAMPLES=OFF \
39    -Dprotobuf_ABSL_PROVIDER="package" \
40"
41
42TEST_SRC_DIR = "examples"
43LANG_SUPPORT = "cpp ${@bb.utils.contains('PACKAGECONFIG', 'python', 'python', '', d)}"
44
45do_compile_ptest() {
46	mkdir -p "${B}/${TEST_SRC_DIR}"
47
48	# Add the location of the cross-compiled header and library files
49	# which haven't been installed yet.
50	cp "${B}/protobuf.pc" "${B}/${TEST_SRC_DIR}/protobuf.pc"
51	cp ${S}/${TEST_SRC_DIR}/*.cc "${B}/${TEST_SRC_DIR}/"
52	cp ${S}/${TEST_SRC_DIR}/*.proto "${B}/${TEST_SRC_DIR}/"
53	cp ${S}/${TEST_SRC_DIR}/*.py "${B}/${TEST_SRC_DIR}/"
54	cp ${S}/${TEST_SRC_DIR}/Makefile "${B}/${TEST_SRC_DIR}/"
55	# Adapt protobuf.pc
56	sed -e 's|libdir=|libdir=${PKG_CONFIG_SYSROOT_DIR}|' -i "${B}/${TEST_SRC_DIR}/protobuf.pc"
57	sed -e 's|Cflags:|Cflags: -I${S}/src |' -i "${B}/${TEST_SRC_DIR}/protobuf.pc"
58	sed -e 's|Cflags:|Cflags: -I${WORKDIR}/recipe-sysroot${includedir} |' -i "${B}/${TEST_SRC_DIR}/protobuf.pc"
59	sed -e 's|Libs:|Libs: -L${B}|' -i "${B}/${TEST_SRC_DIR}/protobuf.pc"
60	sed -e 's|Libs:|Libs: -L${WORKDIR}/recipe-sysroot/usr/lib |' -i "${B}/${TEST_SRC_DIR}/protobuf.pc"
61	sed -e 's|Libs:|Libs: -labsl_log_internal_check_op |' -i "${B}/${TEST_SRC_DIR}/protobuf.pc"
62	sed -e 's|Libs:|Libs: -labsl_log_internal_message |' -i "${B}/${TEST_SRC_DIR}/protobuf.pc"
63	# Adapt uf8_range.pc
64	cp "${B}/third_party/utf8_range/utf8_range.pc" "${B}/${TEST_SRC_DIR}/utf8_range.pc"
65	sed -e 's|libdir=|libdir=${PKG_CONFIG_SYSROOT_DIR}|' -i "${B}/${TEST_SRC_DIR}/utf8_range.pc"
66	sed -e 's|Libs:|Libs= -L${B}/third_party/utf8_range |' -i "${B}/${TEST_SRC_DIR}/utf8_range.pc"
67	# Until out-of-tree build of examples is supported, we have to use this approach
68	sed -e 's|../src/google/protobuf/.libs/timestamp.pb.o|${B}/CMakeFiles/libprotobuf.dir/src/google/protobuf/timestamp.pb.cc.o|' -i "${B}/${TEST_SRC_DIR}/Makefile"
69	export PKG_CONFIG_PATH="${B}/${TEST_SRC_DIR}"
70
71	# Save the pkgcfg sysroot variable, and update it to nothing so
72	# that it doesn't append the sysroot to the beginning of paths.
73	# The header and library files aren't installed to the target
74	# system yet.  So the absolute paths were specified above.
75	save_pkg_config_sysroot_dir=$PKG_CONFIG_SYSROOT_DIR
76	export PKG_CONFIG_SYSROOT_DIR=
77
78	# Compile the tests
79	for lang in ${LANG_SUPPORT}; do
80		oe_runmake -C "${B}/${TEST_SRC_DIR}" ${lang}
81	done
82
83	# Restore the pkgconfig sysroot variable
84	export PKG_CONFIG_SYSROOT_DIR=$save_pkg_config_sysroot_dir
85}
86
87do_install_ptest() {
88	local olddir=`pwd`
89
90	cd "${S}/${TEST_SRC_DIR}"
91	install -d "${D}/${PTEST_PATH}"
92	for i in add_person* list_people*; do
93		if [ -x "$i" ]; then
94			install "$i" "${D}/${PTEST_PATH}"
95		fi
96	done
97	cp "${B}/${TEST_SRC_DIR}/addressbook_pb2.py" "${D}/${PTEST_PATH}"
98	cd "$olddir"
99}
100
101PACKAGE_BEFORE_PN = "${PN}-compiler ${PN}-lite"
102
103FILES:${PN}-compiler = "${bindir} ${libdir}/libprotoc${SOLIBS}"
104FILES:${PN}-lite = "${libdir}/libprotobuf-lite${SOLIBS}"
105
106# CMake requires protoc binary to exist in sysroot, even if it has wrong architecture.
107SYSROOT_DIRS += "${bindir}"
108
109RDEPENDS:${PN} = "abseil-cpp"
110RDEPENDS:${PN}-lite = "abseil-cpp"
111RDEPENDS:${PN}-compiler = "${PN}"
112RDEPENDS:${PN}-dev += "${@bb.utils.contains('PACKAGECONFIG', 'compiler', '${PN}-compiler', '', d)}"
113RDEPENDS:${PN}-ptest = "bash ${@bb.utils.contains('PACKAGECONFIG', 'python', 'python3-protobuf', '', d)}"
114
115MIPS_INSTRUCTION_SET = "mips"
116
117BBCLASSEXTEND = "native nativesdk"
118
119LDFLAGS:append:arm = " -latomic"
120LDFLAGS:append:mips = " -latomic"
121LDFLAGS:append:powerpc = " -latomic"
122LDFLAGS:append:mipsel = " -latomic"
123LDFLAGS:append:riscv32 = " -latomic"
124