DPDK patches and discussions
 help / color / mirror / Atom feed
From: Thomas Monjalon <thomas@monjalon.net>
To: dev@dpdk.org
Cc: Matan Azrad <matan@mellanox.com>,
	Shahaf Shuler <shahafs@mellanox.com>,
	John McNamara <john.mcnamara@intel.com>,
	Marko Kovacevic <marko.kovacevic@intel.com>,
	Viacheslav Ovsiienko <viacheslavo@mellanox.com>,
	Bruce Richardson <bruce.richardson@intel.com>
Subject: [dpdk-dev] [PATCH 3/3] net/mlx: support static ibverbs linkage with meson
Date: Thu, 16 Jan 2020 08:16:56 +0100	[thread overview]
Message-ID: <20200116071656.1663967-4-thomas@monjalon.net> (raw)
In-Reply-To: <20200116071656.1663967-1-thomas@monjalon.net>

The libibverbs (and libmlx4/5) can be statically embedded
in the shared PMD library, or in the application with the static PMD.
It was supported with make build system in
commit 2c0dd7b69fb0 ("config: add static linkage of mlx dependency").

The same feature is enabled with meson.

The main difference, in meson build system, is the generated .pc file
giving arguments to link DPDK with the application.
Forcing meson to link with static dependencies is not really handled
in meson and especially when generating a .pc file.
A fix is in progress for meson, but anyway we will have to live without
such a fix until a better version of meson is widely available:
	https://github.com/mesonbuild/meson/pull/6393

First, the static flavour must be explicitly picked thanks to the syntax
	-l:libfoo.a
Second, in case DPDK is statically linked, the .pc file must not advertise
the simple syntax -lfoo which would pick the shared library when linking
the application.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 buildtools/meson.build       |  2 ++
 doc/guides/nics/mlx4.rst     |  4 ++++
 doc/guides/nics/mlx5.rst     |  4 ++++
 drivers/net/mlx4/meson.build | 20 ++++++++++++++++----
 drivers/net/mlx5/meson.build | 20 ++++++++++++++++----
 meson_options.txt            |  4 ++--
 6 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/buildtools/meson.build b/buildtools/meson.build
index 6ef2c5721c..4ae427fae0 100644
--- a/buildtools/meson.build
+++ b/buildtools/meson.build
@@ -7,6 +7,8 @@ pmdinfo = find_program('gen-pmdinfo-cfile.sh')
 
 check_experimental_syms = find_program('check-experimental-syms.sh')
 
+pkg_config_static = find_program('pkg-config-static.sh')
+
 # set up map-to-def script using python, either built-in or external
 python3 = import('python').find_installation(required: false)
 if python3.found()
diff --git a/doc/guides/nics/mlx4.rst b/doc/guides/nics/mlx4.rst
index d0e8a8b2ff..4b1d1aceb2 100644
--- a/doc/guides/nics/mlx4.rst
+++ b/doc/guides/nics/mlx4.rst
@@ -92,6 +92,10 @@ These options can be modified in the ``.config`` file.
   adds additional run-time checks and debugging messages at the cost of
   lower performance.
 
+This option is available in meson:
+
+- ``ibverbs_link`` can be ``static``, ``shared``, or ``dlopen``.
+
 Environment variables
 ~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/doc/guides/nics/mlx5.rst b/doc/guides/nics/mlx5.rst
index 18573cf6a0..29a9d88b03 100644
--- a/doc/guides/nics/mlx5.rst
+++ b/doc/guides/nics/mlx5.rst
@@ -270,6 +270,10 @@ These options can be modified in the ``.config`` file.
    64. Default armv8a configuration of make build and meson build set it to 128
    then brings performance degradation.
 
+This option is available in meson:
+
+- ``ibverbs_link`` can be ``static``, ``shared``, or ``dlopen``.
+
 Environment variables
 ~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/drivers/net/mlx4/meson.build b/drivers/net/mlx4/meson.build
index 9eb4988420..cdab360faa 100644
--- a/drivers/net/mlx4/meson.build
+++ b/drivers/net/mlx4/meson.build
@@ -9,6 +9,7 @@ if not is_linux
 endif
 build = true
 
+static_ibverbs = (get_option('ibverbs_link') == 'static')
 pmd_dlopen = (get_option('ibverbs_link') == 'dlopen')
 LIB_GLUE_BASE = 'librte_pmd_mlx4_glue.so'
 LIB_GLUE_VERSION = '18.02.0'
@@ -24,12 +25,24 @@ endif
 libnames = [ 'mlx4', 'ibverbs' ]
 libs = []
 foreach libname:libnames
-	lib = dependency('lib' + libname, required:false)
-	if not lib.found()
+	lib = dependency('lib' + libname, static:static_ibverbs, required:false)
+	if not lib.found() and not static_ibverbs
 		lib = cc.find_library(libname, required:false)
 	endif
 	if lib.found()
-		libs += [ lib ]
+		libs += lib
+		if static_ibverbs
+			# Workaround static dependency handling miss of meson
+			# See https://github.com/mesonbuild/meson/pull/6393
+			# Build without adding shared libs to Requires.private
+			hidden_deps += lib.partial_dependency(compile_args:true)
+			# Add static lib deps to internal apps and Libs.private
+			ldflags = run_command(pkg_config_static,
+				'lib' + libname, check:true).stdout()
+			ext_deps += declare_dependency(link_args:ldflags.split())
+		else
+			ext_deps += lib
+		endif
 	else
 		build = false
 		reason = 'missing dependency, "' + libname + '"'
@@ -38,7 +51,6 @@ endforeach
 
 if build
 	allow_experimental_apis = true
-	ext_deps += libs
 	sources = files(
 		'mlx4.c',
 		'mlx4_ethdev.c',
diff --git a/drivers/net/mlx5/meson.build b/drivers/net/mlx5/meson.build
index d6b32db794..8ac604abd7 100644
--- a/drivers/net/mlx5/meson.build
+++ b/drivers/net/mlx5/meson.build
@@ -9,6 +9,7 @@ if not is_linux
 endif
 build = true
 
+static_ibverbs = (get_option('ibverbs_link') == 'static')
 pmd_dlopen = (get_option('ibverbs_link') == 'dlopen')
 LIB_GLUE_BASE = 'librte_pmd_mlx5_glue.so'
 LIB_GLUE_VERSION = '19.08.0'
@@ -24,12 +25,24 @@ endif
 libnames = [ 'mlx5', 'ibverbs' ]
 libs = []
 foreach libname:libnames
-	lib = dependency('lib' + libname, required:false)
-	if not lib.found()
+	lib = dependency('lib' + libname, static:static_ibverbs, required:false)
+	if not lib.found() and not static_ibverbs
 		lib = cc.find_library(libname, required:false)
 	endif
 	if lib.found()
-		libs += [ lib ]
+		libs += lib
+		if static_ibverbs
+			# Workaround static dependency handling miss of meson
+			# See https://github.com/mesonbuild/meson/pull/6393
+			# Build without adding shared libs to Requires.private
+			hidden_deps += lib.partial_dependency(compile_args:true)
+			# Add static lib deps to internal apps and Libs.private
+			ldflags = run_command(pkg_config_static,
+				'lib' + libname, check:true).stdout()
+			ext_deps += declare_dependency(link_args:ldflags.split())
+		else
+			ext_deps += lib
+		endif
 	else
 		build = false
 		reason = 'missing dependency, "' + libname + '"'
@@ -39,7 +52,6 @@ endforeach
 if build
 	allow_experimental_apis = true
 	deps += ['hash']
-	ext_deps += libs
 	sources = files(
 		'mlx5.c',
 		'mlx5_ethdev.c',
diff --git a/meson_options.txt b/meson_options.txt
index bc369d06c9..0de16b4fdb 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -12,8 +12,8 @@ option('examples', type: 'string', value: '',
 	description: 'Comma-separated list of examples to build by default')
 option('flexran_sdk', type: 'string', value: '',
 	description: 'Path to FlexRAN SDK optional Libraries for BBDEV device')
-option('ibverbs_link', type: 'combo', choices : ['shared', 'dlopen'], value: 'shared',
-	description: 'Linkage method (shared/dlopen) for Mellanox PMDs with ibverbs dependencies.')
+option('ibverbs_link', type: 'combo', choices : ['static', 'shared', 'dlopen'], value: 'shared',
+	description: 'Linkage method (static/shared/dlopen) for Mellanox PMDs with ibverbs dependencies.')
 option('include_subdir_arch', type: 'string', value: '',
 	description: 'subdirectory where to install arch-dependent headers')
 option('kernel_dir', type: 'string', value: '',
-- 
2.24.1


  parent reply	other threads:[~2020-01-16  7:17 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-16  7:16 [dpdk-dev] [PATCH 0/3] add static ibverbs in meson Thomas Monjalon
2020-01-16  7:16 ` [dpdk-dev] [PATCH 1/3] buildtools: rework static pkg-config script Thomas Monjalon
2020-01-16  7:16 ` [dpdk-dev] [PATCH 2/3] build: allow to hide dependencies from pkg-config Thomas Monjalon
2020-01-17 17:34   ` Bruce Richardson
2020-01-16  7:16 ` Thomas Monjalon [this message]
2020-01-27 15:43 ` [dpdk-dev] [PATCH v2 0/4] add static ibverbs in meson Thomas Monjalon
2020-01-27 15:43   ` [dpdk-dev] [PATCH v2 1/4] net/mlx: add static ibverbs linkage with meson Thomas Monjalon
2020-01-27 15:44   ` [dpdk-dev] [PATCH v2 2/4] buildtools: get static mlx dependencies for meson Thomas Monjalon
2020-01-29 15:37     ` Bruce Richardson
2020-01-29 17:48       ` Thomas Monjalon
2020-01-29 17:50         ` Bruce Richardson
2020-01-29 18:49           ` Thomas Monjalon
2020-01-29 17:48       ` Bruce Richardson
2020-01-27 15:44   ` [dpdk-dev] [PATCH v2 3/4] build: allow hiding dependencies from pkg-config Thomas Monjalon
2020-01-27 15:44   ` [dpdk-dev] [PATCH v2 4/4] net/mlx: workaround static linkage with meson Thomas Monjalon
2020-02-04 11:48   ` [dpdk-dev] [PATCH v2 0/4] add static ibverbs in meson Bruce Richardson
2020-02-04 14:27     ` Thomas Monjalon
2020-02-04 14:33       ` Bruce Richardson
2020-02-04 15:14         ` Thomas Monjalon
2020-02-04 15:20           ` Bruce Richardson
2020-02-11  1:19   ` [dpdk-dev] [PATCH v3 0/5] mlx ibverbs linking " Thomas Monjalon
2020-02-11  1:19     ` [dpdk-dev] [PATCH v3 1/5] net/mlx: add static ibverbs linkage with meson Thomas Monjalon
2020-02-11  1:19     ` [dpdk-dev] [PATCH v3 2/5] buildtools: get static mlx dependencies for meson Thomas Monjalon
2020-02-11  1:19     ` [dpdk-dev] [PATCH v3 3/5] net/mlx: workaround static linkage with meson Thomas Monjalon
2020-02-11 11:29       ` Bruce Richardson
2020-02-11 11:36         ` Thomas Monjalon
2020-02-11 11:43           ` Bruce Richardson
2020-02-11  1:19     ` [dpdk-dev] [PATCH v3 4/5] net/mlx: rename meson variable for dlopen option Thomas Monjalon
2020-02-11  1:19     ` [dpdk-dev] [PATCH v3 5/5] net/mlx: fix overlinking with meson and glue dlopen Thomas Monjalon
2020-02-11 11:32       ` Bruce Richardson
2020-02-11 11:34         ` Thomas Monjalon
2020-02-11 11:33     ` [dpdk-dev] [PATCH v3 0/5] mlx ibverbs linking in meson Bruce Richardson
2020-02-12  1:59 ` [dpdk-dev] [PATCH v4 0/6] " Thomas Monjalon
2020-02-12  1:59   ` [dpdk-dev] [PATCH v4 1/6] drivers: cleanup meson build variable Thomas Monjalon
2020-02-12  9:26     ` Xu, Rosen
2020-02-12  9:32       ` Thomas Monjalon
2020-02-12 15:04         ` [dpdk-dev] [dpdklab] " Jeremy Plsek
2020-02-12 15:18           ` Jeremy Plsek
2020-02-12 16:30             ` Thomas Monjalon
2020-02-12 16:36               ` Jeremy Plsek
2020-02-12 16:42                 ` Thomas Monjalon
2020-02-12 16:46                   ` Jeremy Plsek
2020-02-12 17:38                     ` Thomas Monjalon
2020-02-12 18:03                       ` Jeremy Plsek
2020-02-12  1:59   ` [dpdk-dev] [PATCH v4 2/6] net/mlx: add static ibverbs linkage with meson Thomas Monjalon
2020-02-12  1:59   ` [dpdk-dev] [PATCH v4 3/6] buildtools: get static mlx dependencies for meson Thomas Monjalon
2020-02-12  1:59   ` [dpdk-dev] [PATCH v4 4/6] net/mlx: workaround static linkage with meson Thomas Monjalon
2020-02-12  1:59   ` [dpdk-dev] [PATCH v4 5/6] net/mlx: rename meson variable for dlopen option Thomas Monjalon
2020-02-12  1:59   ` [dpdk-dev] [PATCH v4 6/6] net/mlx: fix overlinking with meson and glue dlopen Thomas Monjalon
2020-02-12  2:08   ` [dpdk-dev] [PATCH v4 0/6] mlx ibverbs linking in meson Thomas Monjalon
2020-02-12 22:07 ` [dpdk-dev] [PATCH v5 " Thomas Monjalon
2020-02-12 22:07   ` [dpdk-dev] [PATCH v5 1/6] drivers: cleanup meson build variable Thomas Monjalon
2020-02-13  0:25     ` Xu, Rosen
2020-02-12 22:07   ` [dpdk-dev] [PATCH v5 2/6] net/mlx: add static ibverbs linkage with meson Thomas Monjalon
2020-02-12 22:07   ` [dpdk-dev] [PATCH v5 3/6] buildtools: get static mlx dependencies for meson Thomas Monjalon
2020-02-12 22:07   ` [dpdk-dev] [PATCH v5 4/6] net/mlx: workaround static linkage with meson Thomas Monjalon
2020-02-12 22:07   ` [dpdk-dev] [PATCH v5 5/6] net/mlx: rename meson variable for dlopen option Thomas Monjalon
2020-02-12 22:07   ` [dpdk-dev] [PATCH v5 6/6] net/mlx: fix overlinking with meson and glue dlopen Thomas Monjalon
2020-02-13 13:57   ` [dpdk-dev] [PATCH v5 0/6] mlx ibverbs linking in meson Raslan Darawsheh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200116071656.1663967-4-thomas@monjalon.net \
    --to=thomas@monjalon.net \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=john.mcnamara@intel.com \
    --cc=marko.kovacevic@intel.com \
    --cc=matan@mellanox.com \
    --cc=shahafs@mellanox.com \
    --cc=viacheslavo@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).