[v4,7/7] buildtools/chkincs: test headers for C++ compatibility

Message ID 20220210154239.587185-8-bruce.richardson@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series Verify C++ compatibility of public headers |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/github-robot: build success github build: passed
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/Intel-compilation warning apply issues
ci/iol-abi-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS

Commit Message

Bruce Richardson Feb. 10, 2022, 3:42 p.m. UTC
  Add support for checking each of our headers for issues when included in
a C++ file.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 .ci/linux-build.sh             |  1 +
 .github/workflows/build.yml    |  2 +-
 buildtools/chkincs/main.cpp    |  4 ++++
 buildtools/chkincs/meson.build | 20 ++++++++++++++++++++
 devtools/test-meson-builds.sh  |  3 ++-
 5 files changed, 28 insertions(+), 2 deletions(-)
 create mode 100644 buildtools/chkincs/main.cpp
  

Comments

Thomas Monjalon Feb. 10, 2022, 9:58 p.m. UTC | #1
10/02/2022 16:42, Bruce Richardson:
> +executable('chkincs-cpp', cpp_sources,
> +        cpp_args: ['-include', 'rte_config.h', cflags],
> +        link_args: dpdk_extra_ldflags,
> +        include_directories: includes,
> +        dependencies: deps,
> +        link_whole: dpdk_static_libraries + dpdk_drivers,
> +        install: false)

devtools/test-meson-builds.sh is failing on build-x86-generic
at link stage:
	/usr/bin/ld: cannot find -lIPSec_MB
That's probably because there is no pkg-config file for this lib,
and it is not installed in a standard directory,
so my setup is adding -L in LDFLAGS.
  
Bruce Richardson Feb. 11, 2022, 10:31 a.m. UTC | #2
On Thu, Feb 10, 2022 at 10:58:37PM +0100, Thomas Monjalon wrote:
> 10/02/2022 16:42, Bruce Richardson:
> > +executable('chkincs-cpp', cpp_sources, +        cpp_args: ['-include',
> > 'rte_config.h', cflags], +        link_args: dpdk_extra_ldflags, +
> > include_directories: includes, +        dependencies: deps, +
> > link_whole: dpdk_static_libraries + dpdk_drivers, +        install:
> > false)
> 
> devtools/test-meson-builds.sh is failing on build-x86-generic at link
> stage: /usr/bin/ld: cannot find -lIPSec_MB That's probably because there
> is no pkg-config file for this lib, and it is not installed in a standard
> directory, so my setup is adding -L in LDFLAGS.
> 
The test-meson-build.sh script works fine for me on my system with the
ipsec_mb libraries being found ok [installed in standard path]. Can you
share how you are adding the extra library paths, is it via environment or
via c_link_args?

/Bruce
  
Bruce Richardson Feb. 11, 2022, 10:57 a.m. UTC | #3
On Fri, Feb 11, 2022 at 10:31:38AM +0000, Bruce Richardson wrote:
> On Thu, Feb 10, 2022 at 10:58:37PM +0100, Thomas Monjalon wrote:
> > 10/02/2022 16:42, Bruce Richardson:
> > > +executable('chkincs-cpp', cpp_sources, +        cpp_args: ['-include',
> > > 'rte_config.h', cflags], +        link_args: dpdk_extra_ldflags, +
> > > include_directories: includes, +        dependencies: deps, +
> > > link_whole: dpdk_static_libraries + dpdk_drivers, +        install:
> > > false)
> > 
> > devtools/test-meson-builds.sh is failing on build-x86-generic at link
> > stage: /usr/bin/ld: cannot find -lIPSec_MB That's probably because there
> > is no pkg-config file for this lib, and it is not installed in a standard
> > directory, so my setup is adding -L in LDFLAGS.
> > 
> The test-meson-build.sh script works fine for me on my system with the
> ipsec_mb libraries being found ok [installed in standard path]. Can you
> share how you are adding the extra library paths, is it via environment or
> via c_link_args?
> 
Actually, I just realised that these chkincs binaries don't need to be
linked with all these libraries at all, since they don't actually call any
functions and are just meant to check includes. Let me test with removing
all the "link_whole:" parameters and if that works, submit it as a new
patch. That might solve your issues here - again depending on how your
environment is set up.

/Bruce
  
Thomas Monjalon Feb. 11, 2022, 5:22 p.m. UTC | #4
11/02/2022 11:57, Bruce Richardson:
> On Fri, Feb 11, 2022 at 10:31:38AM +0000, Bruce Richardson wrote:
> > On Thu, Feb 10, 2022 at 10:58:37PM +0100, Thomas Monjalon wrote:
> > > 10/02/2022 16:42, Bruce Richardson:
> > > > +executable('chkincs-cpp', cpp_sources, +        cpp_args: ['-include',
> > > > 'rte_config.h', cflags], +        link_args: dpdk_extra_ldflags, +
> > > > include_directories: includes, +        dependencies: deps, +
> > > > link_whole: dpdk_static_libraries + dpdk_drivers, +        install:
> > > > false)
> > > 
> > > devtools/test-meson-builds.sh is failing on build-x86-generic at link
> > > stage: /usr/bin/ld: cannot find -lIPSec_MB That's probably because there
> > > is no pkg-config file for this lib, and it is not installed in a standard
> > > directory, so my setup is adding -L in LDFLAGS.
> > > 
> > The test-meson-build.sh script works fine for me on my system with the
> > ipsec_mb libraries being found ok [installed in standard path]. Can you
> > share how you are adding the extra library paths, is it via environment or
> > via c_link_args?
> > 
> Actually, I just realised that these chkincs binaries don't need to be
> linked with all these libraries at all, since they don't actually call any
> functions and are just meant to check includes. Let me test with removing
> all the "link_whole:" parameters and if that works, submit it as a new
> patch. That might solve your issues here - again depending on how your
> environment is set up.

As I said, it is configured via LDFLAGS environment variable:
	export LDFLAGS=-L$aesnidep
  

Patch

diff --git a/.ci/linux-build.sh b/.ci/linux-build.sh
index c10c1a8ab5..67d68535e0 100755
--- a/.ci/linux-build.sh
+++ b/.ci/linux-build.sh
@@ -74,6 +74,7 @@  fi
 
 if [ "$BUILD_32BIT" = "true" ]; then
     OPTS="$OPTS -Dc_args=-m32 -Dc_link_args=-m32"
+    OPTS="$OPTS -Dcpp_args=-m32 -Dcpp_link_args=-m32"
     export PKG_CONFIG_LIBDIR="/usr/lib32/pkgconfig"
 fi
 
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 6cf997d6ee..d30cfd08d7 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -116,7 +116,7 @@  jobs:
           libdw-dev
     - name: Install i386 cross compiling packages
       if: env.BUILD_32BIT == 'true'
-      run: sudo apt install -y gcc-multilib
+      run: sudo apt install -y gcc-multilib g++-multilib
     - name: Install aarch64 cross compiling packages
       if: env.AARCH64 == 'true'
       run: sudo apt install -y gcc-aarch64-linux-gnu libc6-dev-arm64-cross
diff --git a/buildtools/chkincs/main.cpp b/buildtools/chkincs/main.cpp
new file mode 100644
index 0000000000..d25bb8852a
--- /dev/null
+++ b/buildtools/chkincs/main.cpp
@@ -0,0 +1,4 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2021 Intel Corporation
+ */
+int main(void) { return 0; }
diff --git a/buildtools/chkincs/meson.build b/buildtools/chkincs/meson.build
index 5ffca89761..beabcd55d8 100644
--- a/buildtools/chkincs/meson.build
+++ b/buildtools/chkincs/meson.build
@@ -28,3 +28,23 @@  executable('chkincs', sources,
         dependencies: deps,
         link_whole: dpdk_static_libraries + dpdk_drivers,
         install: false)
+
+# run tests for c++ builds also
+if not add_languages('cpp', required: false)
+    subdir_done()
+endif
+
+gen_cpp_files = generator(gen_c_file_for_header,
+        output: '@BASENAME@.cpp',
+        arguments: ['@INPUT@', '@OUTPUT@'])
+
+cpp_sources = files('main.cpp')
+cpp_sources += gen_cpp_files.process(dpdk_chkinc_headers)
+
+executable('chkincs-cpp', cpp_sources,
+        cpp_args: ['-include', 'rte_config.h', cflags],
+        link_args: dpdk_extra_ldflags,
+        include_directories: includes,
+        dependencies: deps,
+        link_whole: dpdk_static_libraries + dpdk_drivers,
+        install: false)
diff --git a/devtools/test-meson-builds.sh b/devtools/test-meson-builds.sh
index 4ed61328b9..c07fd16fdc 100755
--- a/devtools/test-meson-builds.sh
+++ b/devtools/test-meson-builds.sh
@@ -246,7 +246,8 @@  if check_cc_flags '-m32' ; then
 		export PKG_CONFIG_LIBDIR='/usr/lib/pkgconfig'
 	fi
 	target_override='i386-pc-linux-gnu'
-	build build-32b cc ABI -Dc_args='-m32' -Dc_link_args='-m32'
+	build build-32b cc ABI -Dc_args='-m32' -Dc_link_args='-m32' \
+			-Dcpp_args='-m32' -Dcpp_link_args='-m32'
 	target_override=
 	unset PKG_CONFIG_LIBDIR
 fi