DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH v1 0/1] allow libraries with no sources
@ 2024-03-06 22:17 Paul Szczepanek
  2024-03-06 22:17 ` [PATCH v1 1/1] lib: " Paul Szczepanek
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Szczepanek @ 2024-03-06 22:17 UTC (permalink / raw)
  To: thomas; +Cc: dev, Paul Szczepanek

I want to add library which is header only.
Attempting to build such a a library causes errors during checks.
This skips over building libraries while retaining other library
functionality.
The added lines are the first and last 5. The rest is indentation.

Paul Szczepanek (1):
  lib: allow libraries with no sources

 lib/meson.build | 176 +++++++++++++++++++++++++-----------------------
 1 file changed, 91 insertions(+), 85 deletions(-)

--
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v1 1/1] lib: allow libraries with no sources
  2024-03-06 22:17 [PATCH v1 0/1] allow libraries with no sources Paul Szczepanek
@ 2024-03-06 22:17 ` Paul Szczepanek
  2024-03-07 10:46   ` David Marchand
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Szczepanek @ 2024-03-06 22:17 UTC (permalink / raw)
  To: thomas; +Cc: dev, Paul Szczepanek, Dhruv Tripathi

Allow header only libraries.

Signed-off-by: Paul Szczepanek <paul.szczepanek@arm.com>
Reviewed-by: Dhruv Tripathi <Dhruv.Tripathi@arm.com>

---
 lib/meson.build | 176 +++++++++++++++++++++++++-----------------------
 1 file changed, 91 insertions(+), 85 deletions(-)

diff --git a/lib/meson.build b/lib/meson.build
index 4fb01f059b..0fcf3336d1 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -220,105 +220,111 @@ foreach l:libraries
     includes += include_directories(l)
     dpdk_includes += include_directories(l)

-    if developer_mode and is_windows and use_function_versioning
-        message('@0@: Function versioning is not supported by Windows.'.format(name))
-    endif
+    if sources.length() != 0
+        if developer_mode and is_windows and use_function_versioning
+            message('@0@: Function versioning is not supported by Windows.'.format(name))
+        endif

-    if use_function_versioning
-        cflags += '-DRTE_USE_FUNCTION_VERSIONING'
-    endif
-    cflags += '-DRTE_LOG_DEFAULT_LOGTYPE=lib.' + l
-    if annotate_locks and cc.get_id() == 'clang' and cc.version().version_compare('>=3.5.0')
-        cflags += '-DRTE_ANNOTATE_LOCKS'
-        cflags += '-Wthread-safety'
-    endif
+        if use_function_versioning
+            cflags += '-DRTE_USE_FUNCTION_VERSIONING'
+        endif
+        cflags += '-DRTE_LOG_DEFAULT_LOGTYPE=lib.' + l
+        if annotate_locks and cc.get_id() == 'clang' and cc.version().version_compare('>=3.5.0')
+            cflags += '-DRTE_ANNOTATE_LOCKS'
+            cflags += '-Wthread-safety'
+        endif

-    # first build static lib
-    static_lib = static_library(libname,
-            sources,
-            objects: objs,
-            c_args: cflags,
-            dependencies: static_deps,
-            include_directories: includes,
-            install: true)
-    static_dep = declare_dependency(
-            include_directories: includes,
-            dependencies: static_deps)
+        # first build static lib
+        static_lib = static_library(libname,
+                sources,
+                objects: objs,
+                c_args: cflags,
+                dependencies: static_deps,
+                include_directories: includes,
+                install: true)
+        static_dep = declare_dependency(
+                include_directories: includes,
+                dependencies: static_deps)

-    if not use_function_versioning or is_windows
-        # use pre-build objects to build shared lib
-        sources = []
-        objs += static_lib.extract_all_objects(recursive: false)
-    else
-        # for compat we need to rebuild with
-        # RTE_BUILD_SHARED_LIB defined
-        cflags += '-DRTE_BUILD_SHARED_LIB'
-    endif
+        if not use_function_versioning or is_windows
+            # use pre-build objects to build shared lib
+            sources = []
+            objs += static_lib.extract_all_objects(recursive: false)
+        else
+            # for compat we need to rebuild with
+            # RTE_BUILD_SHARED_LIB defined
+            cflags += '-DRTE_BUILD_SHARED_LIB'
+        endif

-    version_map = '@0@/@1@/version.map'.format(meson.current_source_dir(), l)
-    lk_deps = [version_map]
+        version_map = '@0@/@1@/version.map'.format(meson.current_source_dir(), l)
+        lk_deps = [version_map]

-    if is_ms_linker
-        def_file = custom_target(libname + '_def',
-                command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
-                input: version_map,
-                output: '@0@_exports.def'.format(libname))
-        lk_deps += [def_file]
+        if is_ms_linker
+            def_file = custom_target(libname + '_def',
+                    command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
+                    input: version_map,
+                    output: '@0@_exports.def'.format(libname))
+            lk_deps += [def_file]

-        if is_ms_compiler
-            lk_args = ['/def:' + def_file.full_path()]
-            if meson.version().version_compare('<0.54.0')
-                lk_args += ['/implib:lib\\librte_' + l + '.dll.a']
+            if is_ms_compiler
+                lk_args = ['/def:' + def_file.full_path()]
+                if meson.version().version_compare('<0.54.0')
+                    lk_args += ['/implib:lib\\librte_' + l + '.dll.a']
+                endif
+            else
+                lk_args = ['-Wl,/def:' + def_file.full_path()]
+                if meson.version().version_compare('<0.54.0')
+                    lk_args += ['-Wl,/implib:lib\\librte_' + l + '.dll.a']
+                endif
             endif
         else
-            lk_args = ['-Wl,/def:' + def_file.full_path()]
-            if meson.version().version_compare('<0.54.0')
-                lk_args += ['-Wl,/implib:lib\\librte_' + l + '.dll.a']
+            if is_windows
+                mingw_map = custom_target(libname + '_mingw',
+                        command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
+                        input: version_map,
+                        output: '@0@_mingw.map'.format(libname))
+                lk_deps += [mingw_map]
+
+                lk_args = ['-Wl,--version-script=' + mingw_map.full_path()]
+            else
+                lk_args = ['-Wl,--version-script=' + version_map]
             endif
         endif
-    else
-        if is_windows
-            mingw_map = custom_target(libname + '_mingw',
-                    command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
-                    input: version_map,
-                    output: '@0@_mingw.map'.format(libname))
-            lk_deps += [mingw_map]

-            lk_args = ['-Wl,--version-script=' + mingw_map.full_path()]
-        else
-            lk_args = ['-Wl,--version-script=' + version_map]
+        if developer_mode and not is_windows
+            # on unix systems check the output of the
+            # check-symbols.sh script, using it as a
+            # dependency of the .so build
+            lk_deps += custom_target(name + '.sym_chk',
+                    command: [check_symbols,
+                        version_map, '@INPUT@'],
+                    capture: true,
+                    input: static_lib,
+                    output: name + '.sym_chk')
         endif
-    endif
-
-    if developer_mode and not is_windows
-        # on unix systems check the output of the
-        # check-symbols.sh script, using it as a
-        # dependency of the .so build
-        lk_deps += custom_target(name + '.sym_chk',
-                command: [check_symbols,
-                    version_map, '@INPUT@'],
-                capture: true,
-                input: static_lib,
-                output: name + '.sym_chk')
-    endif

-    shared_lib = shared_library(libname,
-            sources,
-            objects: objs,
-            c_args: cflags,
-            dependencies: shared_deps,
-            include_directories: includes,
-            link_args: lk_args,
-            link_depends: lk_deps,
-            version: abi_version,
-            soversion: so_version,
-            install: true)
-    shared_dep = declare_dependency(link_with: shared_lib,
-            include_directories: includes,
-            dependencies: shared_deps)
+        shared_lib = shared_library(libname,
+                sources,
+                objects: objs,
+                c_args: cflags,
+                dependencies: shared_deps,
+                include_directories: includes,
+                link_args: lk_args,
+                link_depends: lk_deps,
+                version: abi_version,
+                soversion: so_version,
+                install: true)
+        shared_dep = declare_dependency(link_with: shared_lib,
+                include_directories: includes,
+                dependencies: shared_deps)

-    dpdk_libraries = [shared_lib] + dpdk_libraries
-    dpdk_static_libraries = [static_lib] + dpdk_static_libraries
+        dpdk_libraries = [shared_lib] + dpdk_libraries
+        dpdk_static_libraries = [static_lib] + dpdk_static_libraries
+    else # sources.length() == 0
+        # if no C files, just set a dependency on header path
+        shared_dep = declare_dependency(include_directories: includes)
+        static_dep = shared_dep
+    endif

     set_variable('shared_rte_' + name, shared_dep)
     set_variable('static_rte_' + name, static_dep)
--
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1 1/1] lib: allow libraries with no sources
  2024-03-06 22:17 ` [PATCH v1 1/1] lib: " Paul Szczepanek
@ 2024-03-07 10:46   ` David Marchand
  2024-03-07 11:42     ` Bruce Richardson
  0 siblings, 1 reply; 4+ messages in thread
From: David Marchand @ 2024-03-07 10:46 UTC (permalink / raw)
  To: Paul Szczepanek; +Cc: thomas, dev, Dhruv Tripathi, Bruce Richardson

On Wed, Mar 6, 2024 at 11:17 PM Paul Szczepanek <paul.szczepanek@arm.com> wrote:
>
> Allow header only libraries.
>
> Signed-off-by: Paul Szczepanek <paul.szczepanek@arm.com>
> Reviewed-by: Dhruv Tripathi <Dhruv.Tripathi@arm.com>

Don't forget to Cc: Bruce, he is the build system maintainer.


>
> ---
>  lib/meson.build | 176 +++++++++++++++++++++++++-----------------------
>  1 file changed, 91 insertions(+), 85 deletions(-)

Copy/pasting git show -w, it is easier to review:


> diff --git a/lib/meson.build b/lib/meson.build
> index 179a272932..293d65385d 100644
> --- a/lib/meson.build
> +++ b/lib/meson.build
> @@ -222,6 +222,7 @@ foreach l:libraries
>      includes += include_directories(l)
>      dpdk_includes += include_directories(l)
>
> +    if sources.length() != 0
>          if developer_mode and is_windows and use_function_versioning
>              message('@0@: Function versioning is not supported by Windows.'.format(name))
>          endif
> @@ -321,6 +322,11 @@ foreach l:libraries
>
>          dpdk_libraries = [shared_lib] + dpdk_libraries
>          dpdk_static_libraries = [static_lib] + dpdk_static_libraries
> +    else # sources.length() == 0
> +        # if no C files, just set a dependency on header path
> +        shared_dep = declare_dependency(include_directories: includes)

In the hypothetical case that such a header only library would depend
on some external library, I suspect we would need to pass external
dependencies here.
Like:

-        shared_dep = declare_dependency(include_directories: includes)
+        shared_dep = declare_dependency(include_directories: includes,
+                dependencies: shared_deps)


> +        static_dep = shared_dep
> +    endif
>
>      set_variable('shared_rte_' + name, shared_dep)
>      set_variable('static_rte_' + name, static_dep)



-- 
David Marchand


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1 1/1] lib: allow libraries with no sources
  2024-03-07 10:46   ` David Marchand
@ 2024-03-07 11:42     ` Bruce Richardson
  0 siblings, 0 replies; 4+ messages in thread
From: Bruce Richardson @ 2024-03-07 11:42 UTC (permalink / raw)
  To: David Marchand; +Cc: Paul Szczepanek, thomas, dev, Dhruv Tripathi

On Thu, Mar 07, 2024 at 11:46:51AM +0100, David Marchand wrote:
> On Wed, Mar 6, 2024 at 11:17 PM Paul Szczepanek <paul.szczepanek@arm.com> wrote:
> >
> > Allow header only libraries.
> >
> > Signed-off-by: Paul Szczepanek <paul.szczepanek@arm.com>
> > Reviewed-by: Dhruv Tripathi <Dhruv.Tripathi@arm.com>
> 
> Don't forget to Cc: Bruce, he is the build system maintainer.
> 
> 
> >
> > ---
> >  lib/meson.build | 176 +++++++++++++++++++++++++-----------------------
> >  1 file changed, 91 insertions(+), 85 deletions(-)
> 
> Copy/pasting git show -w, it is easier to review:
> 
> 
> > diff --git a/lib/meson.build b/lib/meson.build
> > index 179a272932..293d65385d 100644
> > --- a/lib/meson.build
> > +++ b/lib/meson.build
> > @@ -222,6 +222,7 @@ foreach l:libraries
> >      includes += include_directories(l)
> >      dpdk_includes += include_directories(l)
> >
> > +    if sources.length() != 0
> >          if developer_mode and is_windows and use_function_versioning
> >              message('@0@: Function versioning is not supported by Windows.'.format(name))
> >          endif
> > @@ -321,6 +322,11 @@ foreach l:libraries
> >
> >          dpdk_libraries = [shared_lib] + dpdk_libraries
> >          dpdk_static_libraries = [static_lib] + dpdk_static_libraries
> > +    else # sources.length() == 0
> > +        # if no C files, just set a dependency on header path
> > +        shared_dep = declare_dependency(include_directories: includes)
> 
> In the hypothetical case that such a header only library would depend
> on some external library, I suspect we would need to pass external
> dependencies here.
> Like:
> 
> -        shared_dep = declare_dependency(include_directories: includes)
> +        shared_dep = declare_dependency(include_directories: includes,
> +                dependencies: shared_deps)
> 
> 
> > +        static_dep = shared_dep
> > +    endif
> >
> >      set_variable('shared_rte_' + name, shared_dep)
> >      set_variable('static_rte_' + name, static_dep)
> 

This is very similar to what was done previously in DPDK, but that
was done with the limitations of what early versions of meson supported.
Since meson 0.49 release we have now got "break" and "continue" keywords,
so rather than having to indent everything inside the if statement, I think
it would be better to invert "sources.length()" check at the start, handle
the len == 0 case, and then use "continue" to move on to the next library.
There should only be the need to duplicate a couple of lines in that case.

Thanks,
/Bruce

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-07 11:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-06 22:17 [PATCH v1 0/1] allow libraries with no sources Paul Szczepanek
2024-03-06 22:17 ` [PATCH v1 1/1] lib: " Paul Szczepanek
2024-03-07 10:46   ` David Marchand
2024-03-07 11:42     ` Bruce Richardson

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).