Skip to contentSkip to conversation

boost: Add support for building boost-asio as a shared library

PATCH Superseded Gustav Lindberg 2 participants 2 messages Sep 3

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v7 1/1 boost: Add support for building boost-asio as a shared library

This is needed to build boost asio as a shared library rather than a header-only library, which is needed to save memory.

This can be enabled by adding PACKAGECONFIG:append = " asio" to boost_%.bbappend.

---
 meta/recipes-support/boost/boost.inc          | 25 +++++++++++++++++++
 .../boost/boost/boost_asio.cpp                |  1 +
 2 files changed, 26 insertions(+)
 create mode 100644 meta/recipes-support/boost/boost/boost_asio.cpp
meta/recipes-support/boost/boost.inc +25 -0
index 64a57ddfb2..4ac3f7af5b 100644
@@ -44,6 +44,7 @@ BOOST_LIBS = "\
 	type_erasure \
 	url \
 	wave \
+	${@bb.utils.contains('PACKAGECONFIG', 'asio', 'asio', '', d)} \
 	${@bb.utils.filter('PACKAGECONFIG', 'locale python', d)} \
 	${@bb.utils.contains('PACKAGECONFIG', 'graph_parallel', 'graph_parallel mpi', \
 			     bb.utils.filter('PACKAGECONFIG', 'mpi', d), d)} \
@@ -51,11 +52,14 @@ BOOST_LIBS = "\
 
 # optional libraries
 PACKAGECONFIG ??= "locale python"
+PACKAGECONFIG[asio] = ",,"
 PACKAGECONFIG[locale] = ",,icu"
 PACKAGECONFIG[graph_parallel] = ",,,boost-mpi mpich"
 PACKAGECONFIG[mpi] = ",,mpich"
 PACKAGECONFIG[python] = ",,python3"
 
+SRC_URI:append = " ${@bb.utils.contains('PACKAGECONFIG', 'asio', 'file://boost_asio.cpp', '', d)}"
+
 inherit python3-dir
 PYTHON_ROOT = "${STAGING_DIR_HOST}/${prefix}"
 
@@ -198,6 +202,20 @@ do_compile() {
 		--debug-configuration
 }
 
+do_compile:append() {
+	if ${@bb.utils.contains('PACKAGECONFIG', 'asio', 'true', 'false', d)}; then
+		${CXX} ${CPPFLAGS} ${CXXFLAGS} \
+			-DBOOST_ASIO_DYN_LINK=1 \
+			-I${S} \
+			-fPIC \
+			-shared \
+			-Wl,-soname,libboost_asio.so.${PV} \
+			${UNPACKDIR}/boost_asio.cpp \
+			${LDFLAGS} \
+			-o ${B}/libboost_asio.so.${PV}
+	fi
+}
+
 do_install() {
 	cd ${S}
 	b2 ${BJAM_OPTS} \
@@ -220,4 +238,11 @@ do_install() {
 
 }
 
+do_install:append() {
+	if ${@bb.utils.contains('PACKAGECONFIG', 'asio', 'true', 'false', d)}; then
+		install -Dm 0755 ${B}/libboost_asio.so.${PV} ${D}${libdir}/libboost_asio.so.${PV}
+		ln -sf libboost_asio.so.${PV} ${D}${libdir}/libboost_asio.so
+	fi
+}
+
 BBCLASSEXTEND = "native nativesdk"
meta/recipes-support/boost/boost/boost_asio.cpp new file +1 -0
new file mode 100644
index 0000000000..eb3b7262c3
@@ -0,0 +1 @@
+#include <boost/asio/impl/src.hpp>
\ No newline at end of file
Signature · 3 lines
2.43.0

Move the shared library build to the existing boost recipe, and allow enabling it with a PACKAGECONFIG
#1 lore raw

meta/recipes-support/boost/boost.inc BOOST_LIBS = "\ · line 47

Quoted 7 lines · Gustav Lindberg via lists.openembedded.org
meta/recipes-support/boost/boost.inc +1 -0
@@ -44,6 +44,7 @@ BOOST_LIBS = "\
        type_erasure \
        url \
        wave \
+       ${@bb.utils.contains('PACKAGECONFIG', 'asio', 'asio', '', d)} \

Adding asio to BOOST_LIBS enables asio as a header-only install? Then it should not be subject to PACKAGECONFIG, it can simply be added unconditionally like all other libraries.

meta/recipes-support/boost/boost.inc BOOST_LIBS = "\ · line 55

Quoted 1 line
meta/recipes-support/boost/boost.inc +1 -0
+PACKAGECONFIG[asio] = ",,"

Then this should be named 'asio-shared' as it is also used to build and install a shared library.

meta/recipes-support/boost/boost.inc do_compile() { · line 216

Quoted 12 lines
meta/recipes-support/boost/boost.inc +12 -0
+do_compile:append() {
+       if ${@bb.utils.contains('PACKAGECONFIG', 'asio', 'true', 'false', d)}; then
+               ${CXX} ${CPPFLAGS} ${CXXFLAGS} \
+                       -DBOOST_ASIO_DYN_LINK=1 \
+                       -I${S} \
+                       -fPIC \
+                       -shared \
+                       -Wl,-soname,libboost_asio.so.${PV} \
+                       ${UNPACKDIR}/boost_asio.cpp \
+                       ${LDFLAGS} \
+                       -o ${B}/libboost_asio.so.${PV}
+       fi

No custom compiler executions please. Building a shared library should be done by the boost build system itself, and enabled via a flag to it during do_configure (e.g. via PACKAGECONFIG_CONFARGS or BJAM_EXTRA). You probably need to patch boost to do this, and send the needed patch upstream.

meta/recipes-support/boost/boost.inc do_install() { · line 246

Quoted 6 lines
meta/recipes-support/boost/boost.inc +6 -0
+do_install:append() {
+       if ${@bb.utils.contains('PACKAGECONFIG', 'asio', 'true', 'false', d)}; then
+               install -Dm 0755 ${B}/libboost_asio.so.${PV} ${D}${libdir}/libboost_asio.so.${PV}
+               ln -sf libboost_asio.so.${PV} ${D}${libdir}/libboost_asio.so
+       fi
+}

Same here: no custom installation, boost itself should do it if it was enabled.

Alex