Skip to contentSkip to conversation

build and install only one library type on Windows

PATCH New Tyler Retzlaff 3 participants 27 messages Mar 14, 2024 – Jun 14, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 build and install only one library type on Windows

MSVC is the only compiler that can produce usable shared libraries for DPDK on Windows because of the use of exported TLS variables.

Disable building of shared libraries with LLVM and MinGW so that remaining __declspec macros needed for the functional libraries built by MSVC can be used without triggering errors in LLVM and MinGW builds.

For Windows only install the default_library type to avoid confusion. Windows builds cannot build both shared and static in a single pass so install only the functional variant

MSVC does not guarantee any kind of compatibility for static libraries so they should not be packaged and instead they should be rebuilt along with the application using the same version of the compiler & linker. Because of this we have chosen to build only one library type at a time instead of compiling twice to produce both types in a single pass.

Tyler Retzlaff (1):
build: build only one library type on Windows

 config/meson.build                    | 20 +++++++
 drivers/meson.build                   | 51 ++++++++++--------
 drivers/net/octeontx/base/meson.build |  2 +-
 lib/meson.build                       | 98 +++++++++++++++++++----------------
 4 files changed, 101 insertions(+), 70 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 build: build only one library type on Windows

MSVC is the only compiler that can produce usable shared libraries for DPDK on Windows because of the use of exported TLS variables.

Disable building of shared libraries with LLVM and MinGW so that remaining __declspec macros needed for the functional libraries built by MSVC can be used without triggering errors in LLVM and MinGW builds.

For Windows only install the default_library type to avoid confusion. Windows builds cannot build both shared and static in a single pass so install only the functional variant.

---
 config/meson.build                    | 20 +++++++
 drivers/meson.build                   | 51 ++++++++++--------
 drivers/net/octeontx/base/meson.build |  2 +-
 lib/meson.build                       | 98 +++++++++++++++++++----------------
 4 files changed, 101 insertions(+), 70 deletions(-)
config/meson.build +20 -0
index 8c8b019..2090846 100644
@@ -516,4 +516,24 @@ if get_option('default_library') == 'both'
  NOTE: DPDK always builds both shared and static libraries.  Please set
  "default_library" to either "static" or "shared" to select default linkage
  for apps and any examples.''')
+elif get_option('default_library') == 'shared' and is_windows and not is_ms_compiler
+    error( '''
+ Unsupported value "shared" for "default_library" option.
+
+ NOTE: DPDK Windows shared is only supported when building with MSVC. Please set
+ "default_library" to either "static" or use MSVC.''')
+endif
+
+if is_windows and not is_ms_compiler
+    is_shared_enabled=false
+else
+    is_shared_enabled=true
+endif
+
+if is_windows
+    install_static = get_option('default_library') == 'static'
+    install_shared = get_option('default_library') == 'shared'
+else
+    install_static=true
+    install_shared=true
 endif
drivers/meson.build +28 -23

93 lines not on this page · raw message

drivers/net/octeontx/base/meson.build +1 -1
index 8e5e8c1..a793c19 100644
@@ -10,7 +10,7 @@ sources = [
 depends = ['ethdev', 'mempool_octeontx']
 static_objs = []
 foreach d: depends
-    if not is_variable('shared_rte_' + d)
+    if not is_variable('static_rte_' + d)
         subdir_done()
     endif
     static_objs += get_variable('static_rte_' + d)
lib/meson.build +52 -46

135 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#7 lore raw

PATCH v2 2/2 buildtools: when building static library use static deps

In reply to Tyler Retzlaff

Use static deps when default_library=static and use shared deps when using default_library=shared.

---
 buildtools/chkincs/meson.build | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
buildtools/chkincs/meson.build +13 -5
index f2dadca..66245a5 100644
@@ -20,11 +20,19 @@ sources += gen_c_files.process(dpdk_chkinc_headers)
 
 # some driver SDK headers depend on these two buses, which are mandatory in build
 # so we always include them in deps list
-deps = [get_variable('shared_rte_bus_vdev'), get_variable('shared_rte_bus_pci')]
-# add the rest of the libs to the dependencies
-foreach l:dpdk_libs_enabled
-    deps += get_variable('shared_rte_' + l)
-endforeach
+if is_shared_enabled
+    deps = [get_variable('shared_rte_bus_vdev'), get_variable('shared_rte_bus_pci')]
+    # add the rest of the libs to the dependencies
+    foreach l:dpdk_libs_enabled
+        deps += get_variable('shared_rte_' + l)
+    endforeach
+else
+    deps = [get_variable('static_rte_bus_vdev'), get_variable('static_rte_bus_pci')]
+    # add the rest of the libs to the dependencies
+    foreach l:dpdk_libs_enabled
+        deps += get_variable('static_rte_' + l)
+    endforeach
+endif
 
 executable('chkincs', sources,
         c_args: cflags,
Signature · 1 line
1.8.3.1
#2 lore raw

v2 cover build and install only one library type on Windows

In reply to Tyler Retzlaff

MSVC is the only compiler that can produce usable shared libraries for DPDK on Windows because of the use of exported TLS variables.

Disable building of shared libraries with LLVM and MinGW so that remaining __declspec macros needed for the functional libraries built by MSVC can be used without triggering errors in LLVM and MinGW builds.

For Windows only install the default_library type to avoid confusion. Windows builds cannot build both shared and static in a single pass so install only the functional variant

MSVC does not guarantee any kind of compatibility for static libraries so they should not be packaged and instead they should be rebuilt along with the application using the same version of the compiler & linker. Because of this we have chosen to build only one library type at a time instead of compiling twice to produce both types in a single pass.

v2:
* add patch to chkings to use static dependencies when building static cross build for windows target with mingw.
* add missing msvc specific ldflags needed for shared builds.
* define RTE_BUILD_SHARED_LIB for shared msvc builds.
* fix is_shared_enabled conditional to check default_library=shared when building with msvc.
* simplify linker flags when building for windows, we only need to provide flags for shared builds when building with msvc.
* stop generating .def file for llvm and mingw builds, since no shared builds are performed the .def files would be unused.

Tyler Retzlaff (2):
build: build only one library type on Windows
buildtools: when building static library use static deps

 app/meson.build                       |  6 +++
 buildtools/chkincs/meson.build        | 18 +++++---
 config/meson.build                    | 27 ++++++++++++
 drivers/meson.build                   | 72 +++++++++++++++----------------
 drivers/net/octeontx/base/meson.build |  2 +-
 examples/meson.build                  |  6 +++
 lib/meson.build                       | 79 +++++++++++++++--------------------
 7 files changed, 121 insertions(+), 89 deletions(-)
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH v2 1/2 build: build only one library type on Windows

MSVC is the only compiler that can produce usable shared libraries for DPDK on Windows because of the use of exported TLS variables.

Disable building of shared libraries with LLVM and MinGW so that remaining __declspec macros needed for the functional libraries built by MSVC can be used without triggering errors in LLVM and MinGW builds.

For Windows only install the default_library type to avoid confusion. Windows builds cannot build both shared and static in a single pass so install only the functional variant.

---
 app/meson.build                       |  6 +++
 config/meson.build                    | 27 ++++++++++++
 drivers/meson.build                   | 72 +++++++++++++++----------------
 drivers/net/octeontx/base/meson.build |  2 +-
 examples/meson.build                  |  6 +++
 lib/meson.build                       | 79 +++++++++++++++--------------------
 6 files changed, 108 insertions(+), 84 deletions(-)
app/meson.build +6 -0
index 21b6da2..f4ed0f1 100644
@@ -46,6 +46,8 @@ default_cflags = machine_args + ['-DALLOW_EXPERIMENTAL_API']
 default_ldflags = []
 if get_option('default_library') == 'static' and not is_windows
     default_ldflags += ['-Wl,--export-dynamic']
+elif get_option('default_library') == 'shared' and is_ms_compiler
+    default_ldflags += ['/experimental:tlsDllInterface']
 endif
 
 foreach app:apps
@@ -104,6 +106,10 @@ foreach app:apps
         link_libs = dpdk_static_libraries + dpdk_drivers
     endif
 
+    if is_windows and is_shared_enabled
+        cflags += '-DRTE_BUILD_SHARED_LIB'
+    endif
+
     exec = executable('dpdk-' + name,
             sources,
             c_args: cflags,
config/meson.build +27 -0
index 8c8b019..dd7971e 100644
@@ -53,6 +53,9 @@ if is_ms_compiler
 
     # enable statement expressions extension
     add_project_arguments('/experimental:statementExpressions', language: 'c')
+
+    # enable export of thread_local variables
+    add_project_arguments('/experimental:tlsDllInterface', language: 'c')
 endif
 
 # set the major version, which might be used by drivers and libraries
@@ -516,4 +519,28 @@ if get_option('default_library') == 'both'
  NOTE: DPDK always builds both shared and static libraries.  Please set
  "default_library" to either "static" or "shared" to select default linkage
  for apps and any examples.''')
+elif get_option('default_library') == 'shared' and is_windows and not is_ms_compiler
+    error( '''
+ Unsupported value "shared" for "default_library" option.
+
+ NOTE: DPDK Windows shared is only supported when building with MSVC. Please set
+ "default_library" to either "static" or use MSVC.''')
+endif
+
+if is_windows
+    if is_ms_compiler and get_option('default_library') == 'shared'
+        is_shared_enabled=true
+    else
+        is_shared_enabled=false
+    endif
+else
+    is_shared_enabled=true
+endif
+
+if is_windows
+    install_static = get_option('default_library') == 'static'
+    install_shared = get_option('default_library') == 'shared'
+else
+    install_static=true
+    install_shared=true
 endif
drivers/meson.build +34 -38

123 lines not on this page · raw message

drivers/net/octeontx/base/meson.build +1 -1
index 8e5e8c1..a793c19 100644
@@ -10,7 +10,7 @@ sources = [
 depends = ['ethdev', 'mempool_octeontx']
 static_objs = []
 foreach d: depends
-    if not is_variable('shared_rte_' + d)
+    if not is_variable('static_rte_' + d)
         subdir_done()
     endif
     static_objs += get_variable('static_rte_' + d)
examples/meson.build +6 -0
index 8e8968a..e08a169 100644
@@ -85,6 +85,8 @@ endif
 default_ldflags = dpdk_extra_ldflags
 if get_option('default_library') == 'static' and not is_windows
     default_ldflags += ['-Wl,--export-dynamic']
+elif is_ms_compiler
+    default_ldflags += ['/experimental:tlsDllInterface']
 endif
 
 foreach example: examples
@@ -121,6 +123,10 @@ foreach example: examples
         continue
     endif
 
+    if is_windows and is_shared_enabled
+        cflags += '-DRTE_BUILD_SHARED_LIB'
+    endif
+
     if allow_experimental_apis
         cflags += '-DALLOW_EXPERIMENTAL_API'
     endif
lib/meson.build +34 -45

121 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#8 lore raw

Re: [PATCH v2 2/2] buildtools: when building static library use static deps

In reply to Tyler Retzlaff
Quoted 25 lines · Tyler Retzlaff

Use static deps when default_library=static and use shared deps when using default_library=shared.

---
 buildtools/chkincs/meson.build | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
buildtools/chkincs/meson.build +4 -5
index f2dadca..66245a5 100644
@@ -20,11 +20,19 @@ sources += gen_c_files.process(dpdk_chkinc_headers)
 
 # some driver SDK headers depend on these two buses, which are mandatory in build
 # so we always include them in deps list
-deps = [get_variable('shared_rte_bus_vdev'), get_variable('shared_rte_bus_pci')]
-# add the rest of the libs to the dependencies
-foreach l:dpdk_libs_enabled
-    deps += get_variable('shared_rte_' + l)
-endforeach
+if is_shared_enabled
+    deps = [get_variable('shared_rte_bus_vdev'), get_variable('shared_rte_bus_pci')]
+    # add the rest of the libs to the dependencies
+    foreach l:dpdk_libs_enabled

buildtools/chkincs/meson.build sources += gen_c_files.process(dpdk_chkinc_headers) · line 36

Quoted 10 lines
buildtools/chkincs/meson.build +9 -0
+        deps += get_variable('shared_rte_' + l)
+    endforeach
+else
+    deps = [get_variable('static_rte_bus_vdev'), get_variable('static_rte_bus_pci')]
+    # add the rest of the libs to the dependencies
+    foreach l:dpdk_libs_enabled
+        deps += get_variable('static_rte_' + l)
+    endforeach
+endif
 

Should the deps checks in lib and driver not be similarly conditional?

Quoted 5 lines
buildtools/chkincs/meson.build +0 -0
 executable('chkincs', sources,
         c_args: cflags,
Signature · 1 line
1.8.3.1
#9 lore raw

Re: [PATCH v2 2/2] buildtools: when building static library use static deps

Quoted 30 lines · Bruce Richardson
Quoted 29 lines · Tyler Retzlaff

Use static deps when default_library=static and use shared deps when using default_library=shared.

---
 buildtools/chkincs/meson.build | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
buildtools/chkincs/meson.build +8 -5
index f2dadca..66245a5 100644
@@ -20,11 +20,19 @@ sources += gen_c_files.process(dpdk_chkinc_headers)
 
 # some driver SDK headers depend on these two buses, which are mandatory in build
 # so we always include them in deps list
-deps = [get_variable('shared_rte_bus_vdev'), get_variable('shared_rte_bus_pci')]
-# add the rest of the libs to the dependencies
-foreach l:dpdk_libs_enabled
-    deps += get_variable('shared_rte_' + l)
-endforeach
+if is_shared_enabled
+    deps = [get_variable('shared_rte_bus_vdev'), get_variable('shared_rte_bus_pci')]
+    # add the rest of the libs to the dependencies
+    foreach l:dpdk_libs_enabled
+        deps += get_variable('shared_rte_' + l)
+    endforeach
+else
+    deps = [get_variable('static_rte_bus_vdev'), get_variable('static_rte_bus_pci')]
Quoted 8 lines

buildtools/chkincs/meson.build sources += gen_c_files.process(dpdk_chkinc_headers) · line 36

Quoted 6 lines
buildtools/chkincs/meson.build +5 -0
+    # add the rest of the libs to the dependencies
+    foreach l:dpdk_libs_enabled
+        deps += get_variable('static_rte_' + l)
+    endforeach
+endif
 

Should the deps checks in lib and driver not be similarly conditional?

i might need more context about what you think is wrong. i think the problem here was that there are not separate variables for shared_deps vs static_deps.

for my changes to lib/meson.build there's already a separate shared_deps and static_deps variables holding the deps that are used with shared_library and static_library respectively.

ty

#10 lore raw

Re: [PATCH v2 2/2] buildtools: when building static library use static deps

Quoted 44 lines · Tyler Retzlaff
Quoted 30 lines · Bruce Richardson
Quoted 29 lines · Tyler Retzlaff

Use static deps when default_library=static and use shared deps when using default_library=shared.

---
 buildtools/chkincs/meson.build | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
buildtools/chkincs/meson.build +8 -5
index f2dadca..66245a5 100644
@@ -20,11 +20,19 @@ sources += gen_c_files.process(dpdk_chkinc_headers)
 
 # some driver SDK headers depend on these two buses, which are mandatory in build
 # so we always include them in deps list
-deps = [get_variable('shared_rte_bus_vdev'), get_variable('shared_rte_bus_pci')]
-# add the rest of the libs to the dependencies
-foreach l:dpdk_libs_enabled
-    deps += get_variable('shared_rte_' + l)
-endforeach
+if is_shared_enabled
+    deps = [get_variable('shared_rte_bus_vdev'), get_variable('shared_rte_bus_pci')]
+    # add the rest of the libs to the dependencies
+    foreach l:dpdk_libs_enabled
+        deps += get_variable('shared_rte_' + l)
+    endforeach
+else
+    deps = [get_variable('static_rte_bus_vdev'), get_variable('static_rte_bus_pci')]
Quoted 8 lines

buildtools/chkincs/meson.build sources += gen_c_files.process(dpdk_chkinc_headers) · line 36

Quoted 6 lines
buildtools/chkincs/meson.build +5 -0
+    # add the rest of the libs to the dependencies
+    foreach l:dpdk_libs_enabled
+        deps += get_variable('static_rte_' + l)
+    endforeach
+endif
 

Should the deps checks in lib and driver not be similarly conditional?

i might need more context about what you think is wrong. i think the problem here was that there are not separate variables for shared_deps vs static_deps.

Quoted 6 lines

for my changes to lib/meson.build there's already a separate shared_deps and static_deps variables holding the deps that are used with shared_library and static_library respectively.

ty

Not sure I know the context of the question myself, but your answer certainly seems reasonable. :-) Thanks.

#4 lore raw

Re: [PATCH v2 1/2] build: build only one library type on Windows

In reply to Tyler Retzlaff
Quoted 7 lines · Tyler Retzlaff

MSVC is the only compiler that can produce usable shared libraries for DPDK on Windows because of the use of exported TLS variables.

Disable building of shared libraries with LLVM and MinGW so that remaining __declspec macros needed for the functional libraries built by MSVC can be used without triggering errors in LLVM and MinGW builds.

Quoted 5 lines

For Windows only install the default_library type to avoid confusion. Windows builds cannot build both shared and static in a single pass so install only the functional variant.

Comments inline below.

/Bruce

Quoted 14 lines
---
 app/meson.build                       |  6 +++
 config/meson.build                    | 27 ++++++++++++
 drivers/meson.build                   | 72 +++++++++++++++----------------
 drivers/net/octeontx/base/meson.build |  2 +-
 examples/meson.build                  |  6 +++
 lib/meson.build                       | 79 +++++++++++++++--------------------
 6 files changed, 108 insertions(+), 84 deletions(-)
app/meson.build +0 -0
index 21b6da2..f4ed0f1 100644

app/meson.build default_cflags = machine_args + ['-DALLOW_EXPERIMENTAL_API'] · line 52

Quoted 7 lines
app/meson.build +2 -0
@@ -46,6 +46,8 @@ default_cflags = machine_args + ['-DALLOW_EXPERIMENTAL_API']
 default_ldflags = []
 if get_option('default_library') == 'static' and not is_windows
     default_ldflags += ['-Wl,--export-dynamic']
+elif get_option('default_library') == 'shared' and is_ms_compiler
+    default_ldflags += ['/experimental:tlsDllInterface']
 endif
 

Is this necessary, given that you add this flag as a project-wide argument below in config/meson.build?

Quoted 38 lines
app/meson.build +4 -0
 foreach app:apps
@@ -104,6 +106,10 @@ foreach app:apps
         link_libs = dpdk_static_libraries + dpdk_drivers
     endif
 
+    if is_windows and is_shared_enabled
+        cflags += '-DRTE_BUILD_SHARED_LIB'
+    endif
+
     exec = executable('dpdk-' + name,
             sources,
             c_args: cflags,
config/meson.build +11 -0
index 8c8b019..dd7971e 100644
@@ -53,6 +53,9 @@ if is_ms_compiler
 
     # enable statement expressions extension
     add_project_arguments('/experimental:statementExpressions', language: 'c')
+
+    # enable export of thread_local variables
+    add_project_arguments('/experimental:tlsDllInterface', language: 'c')
 endif
 
 # set the major version, which might be used by drivers and libraries
@@ -516,4 +519,28 @@ if get_option('default_library') == 'both'
  NOTE: DPDK always builds both shared and static libraries.  Please set
  "default_library" to either "static" or "shared" to select default linkage
  for apps and any examples.''')
+elif get_option('default_library') == 'shared' and is_windows and not is_ms_compiler
+    error( '''
+ Unsupported value "shared" for "default_library" option.
+
+ NOTE: DPDK Windows shared is only supported when building with MSVC. Please set
+ "default_library" to either "static" or use MSVC.''')
+endif
+

config/meson.build if get_option('default_library') == 'both' · line 539

Quoted 10 lines
config/meson.build +10 -0
+if is_windows
+    if is_ms_compiler and get_option('default_library') == 'shared'
+        is_shared_enabled=true
+    else
+        is_shared_enabled=false
+    endif
+else
+    is_shared_enabled=true
+endif
+

This can be shortened to:

is_shared_enabled=true
if is_windows and (not is_ms_compiler or not get_option(...) == 'shared')
is_shared_enabled=false
endif

config/meson.build if get_option('default_library') == 'both' · line 546

Quoted 7 lines
config/meson.build +6 -0
+if is_windows
+    install_static = get_option('default_library') == 'static'
+    install_shared = get_option('default_library') == 'shared'
+else
+    install_static=true
+    install_shared=true
 endif

Might be better merged with the block above:

is_shared_enabled = true
install_static = true
install_shared = true
if is_windows
install_static = get_option('default_library') == 'static' install_shared = get_option('default_library') == 'shared'

if not is_ms_compiler or not install_shared
is_shared_enabled = false
endif
endif

Quoted 34 lines
drivers/meson.build +5 -3
index 66931d4..c8b2d13 100644
@@ -80,7 +80,7 @@ foreach subpath:subdirs
         subdir(class)
         skip_class = false
         foreach d:std_deps
-            if not is_variable('shared_rte_' + d)
+            if not is_variable('static_rte_' + d)
                 skip_class = true
                 reason = 'missing internal dependency, "@0@"'.format(d)
                 if dpdk_libs_deprecated.contains(d)
@@ -173,7 +173,7 @@ foreach subpath:subdirs
                 if not build
                     break
                 endif
-                if not is_variable('shared_rte_' + d)
+                if not is_variable('static_rte_' + d)
                     build = false
                     reason = 'missing internal dependency, "@0@"'.format(d)
                     if dpdk_libs_deprecated.contains(d)
@@ -188,7 +188,9 @@ foreach subpath:subdirs
                                 +'\tPlease enable missing dependency "@0@"'.format(d))
                     endif
                 else
-                    shared_deps += [get_variable('shared_rte_' + d)]
+                    if is_shared_enabled
+                        shared_deps += [get_variable('shared_rte_' + d)]
+                    endif
                     static_deps += [get_variable('static_rte_' + d)]
                 endif
             endforeach

drivers/meson.build foreach subpath:subdirs · line 215

Quoted 6 lines
drivers/meson.build +3 -0
@@ -208,6 +210,9 @@ foreach subpath:subdirs
         enabled_drivers += name
         lib_name = '_'.join(['rte', class, name])
         cflags += '-DRTE_LOG_DEFAULT_LOGTYPE=' + '.'.join([log_prefix, name])
+        if is_windows and is_shared_enabled
+            cflags += '-DRTE_BUILD_SHARED_LIB'
+        endif

Rather than setting this in cflags in the drivers or lib meson.build files, can we set this once as a project-level cflag and be done with it?

Quoted 21 lines
drivers/meson.build +3 -3
         if annotate_locks and cc.get_id() == 'clang' and cc.version().version_compare('>=3.5.0')
             cflags += '-DRTE_ANNOTATE_LOCKS'
             cflags += '-Wthread-safety'
@@ -247,7 +252,7 @@ foreach subpath:subdirs
                 include_directories: includes,
                 dependencies: static_deps,
                 c_args: cflags,
-                install: true)
+                install: install_static)
 
         # now build the shared driver
         version_map = '@0@/@1@/version.map'.format(meson.current_source_dir(), drv_path)
@@ -271,55 +276,46 @@ foreach subpath:subdirs
             endif
         endif
 
-        if is_windows
-            if is_ms_linker
+        if is_shared_enabled
+            if is_ms_compiler
                 def_file = custom_target(lib_name + '_def',

drivers/meson.build foreach subpath:subdirs · line 286

Quoted 10 lines
drivers/meson.build +1 -5
                         command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
                         input: version_map,
                         output: '@0@_exports.def'.format(lib_name))
                 lk_deps += [def_file]
-
-                lk_args = ['-Wl,/def:' + def_file.full_path()]
-                if meson.version().version_compare('<0.54.0')
-                    lk_args += ['-Wl,/implib:drivers\\lib' + lib_name + '.dll.a']
-                endif
+                lk_args = ['/experimental:tlsDllInterface', '/def:' + def_file.full_path()]

Again, the /experimental flag shouldn't be necessary, since it's set as project option in config/meson.build.

Quoted 41 lines
drivers/meson.build +11 -26
             else
-                mingw_map = custom_target(lib_name + '_mingw',
-                        command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
-                        input: version_map,
-                        output: '@0@_mingw.map'.format(lib_name))
-                lk_deps += [mingw_map]
-
-                lk_args = ['-Wl,--version-script=' + mingw_map.full_path()]
+                lk_args = ['-Wl,--version-script=' + version_map]
             endif
-        else
-            lk_args = ['-Wl,--version-script=' + version_map]
         endif
 
-        shared_lib = shared_library(lib_name, sources,
-                objects: objs,
-                include_directories: includes,
-                dependencies: shared_deps,
-                c_args: cflags,
-                link_args: lk_args,
-                link_depends: lk_deps,
-                version: abi_version,
-                soversion: so_version,
-                install: true,
-                install_dir: driver_install_path)
-
-        # create a dependency object and add it to the global dictionary so
-        # testpmd or other built-in apps can find it if necessary
-        shared_dep = declare_dependency(link_with: shared_lib,
-                include_directories: includes,
-                dependencies: shared_deps)
+        if is_shared_enabled
+            shared_lib = shared_library(lib_name, sources,
+                    objects: objs,
+                    include_directories: includes,
+                    dependencies: shared_deps,
+                    c_args: cflags,
+                    link_args: lk_args,
+                    link_depends: lk_deps,
+                    version: abi_version,
+                    soversion: so_version,

drivers/meson.build foreach subpath:subdirs · line 311

Quoted 10 lines
drivers/meson.build +10 -0
+                    install: install_shared,
+                    install_dir: driver_install_path)
+
+            # create a dependency object and add it to the global dictionary so
+            # testpmd or other built-in apps can find it if necessary
+            shared_dep = declare_dependency(link_with: shared_lib,
+                    include_directories: includes,
+                    dependencies: shared_deps)
+
+            set_variable('shared_@0@'.format(lib_name), shared_dep)

Just a thought - could you avoid some of the changes throughout this set, if you add an else-leg to the "is_shared_enabled" check, where, if shared is not enabled, you assign shared_dep to be an empty string, or an empty object or something.

That would mean that you wouldn't need to move the set_variable line as here, you also wouldn't need to put conditionals around all the

Just a thought - could you avoid some of the changes throughout this set, if you add an else-leg to the "is_shared_enabled" check, where, if shared is not enabled, you assign shared_dep to be an empty string, or an empty object or something.

That would mean that you wouldn't need to move the set_variable line as here, you also wouldn't need to put conditionals around all the 'shared_deps +=' lines when processing deps for a component, and lastly, you may not even need to change all the searches for shared_rte_ to static_rte, since the variables would exist for shared - they'd just be empty!

drivers/meson.build foreach subpath:subdirs · line 317

Quoted 6 lines
drivers/meson.build +1 -0
+        endif
         static_dep = declare_dependency(
                 include_directories: includes,
                 dependencies: static_deps)
 
         dpdk_drivers += static_lib

<snip for brevity>

#11 lore raw

Re: [PATCH v2 2/2] buildtools: when building static library use static deps

In reply to Tyler Retzlaff
Quoted 13 lines · Tyler Retzlaff

Use static deps when default_library=static and use shared deps when using default_library=shared.

---
 buildtools/chkincs/meson.build | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
buildtools/chkincs/meson.build +0 -0
index f2dadca..66245a5 100644

buildtools/chkincs/meson.build sources += gen_c_files.process(dpdk_chkinc_headers) · line 27

Quoted 8 lines
buildtools/chkincs/meson.build +0 -5
@@ -20,11 +20,19 @@ sources += gen_c_files.process(dpdk_chkinc_headers)
 
 # some driver SDK headers depend on these two buses, which are mandatory in build
 # so we always include them in deps list
-deps = [get_variable('shared_rte_bus_vdev'), get_variable('shared_rte_bus_pci')]
-# add the rest of the libs to the dependencies
-foreach l:dpdk_libs_enabled
-    deps += get_variable('shared_rte_' + l)
-endforeach

shorter fix might be to use get_option('default_library') in place of the "shared" string, rather than using a condition.

/Bruce

Quoted 19 lines
buildtools/chkincs/meson.build +13 -0
+if is_shared_enabled
+    deps = [get_variable('shared_rte_bus_vdev'), get_variable('shared_rte_bus_pci')]
+    # add the rest of the libs to the dependencies
+    foreach l:dpdk_libs_enabled
+        deps += get_variable('shared_rte_' + l)
+    endforeach
+else
+    deps = [get_variable('static_rte_bus_vdev'), get_variable('static_rte_bus_pci')]
+    # add the rest of the libs to the dependencies
+    foreach l:dpdk_libs_enabled
+        deps += get_variable('static_rte_' + l)
+    endforeach
+endif
 
 executable('chkincs', sources,
         c_args: cflags,
Signature · 1 line
1.8.3.1
#14 lore raw

PATCH v3 1/2 build: build only one library type on Windows

In reply to Tyler Retzlaff

MSVC is the only compiler that can produce usable shared libraries for DPDK on Windows because of the use of exported TLS variables.

Disable building of shared libraries with LLVM and MinGW so that remaining __declspec macros needed for the functional libraries built by MSVC can be used without triggering errors in LLVM and MinGW builds.

For Windows only install the default_library type to avoid confusion. Windows builds cannot build both shared and static in a single pass so install only the functional variant.

---
 app/meson.build                       |  6 +++
 config/meson.build                    | 20 ++++++++++
 drivers/meson.build                   | 64 +++++++++++++++----------------
 drivers/net/octeontx/base/meson.build |  2 +-
 examples/meson.build                  |  6 +++
 lib/meson.build                       | 72 +++++++++++++++--------------------
 6 files changed, 94 insertions(+), 76 deletions(-)
app/meson.build +6 -0
index 21b6da2..f4ed0f1 100644
@@ -46,6 +46,8 @@ default_cflags = machine_args + ['-DALLOW_EXPERIMENTAL_API']
 default_ldflags = []
 if get_option('default_library') == 'static' and not is_windows
     default_ldflags += ['-Wl,--export-dynamic']
+elif get_option('default_library') == 'shared' and is_ms_compiler
+    default_ldflags += ['/experimental:tlsDllInterface']
 endif
 
 foreach app:apps
@@ -104,6 +106,10 @@ foreach app:apps
         link_libs = dpdk_static_libraries + dpdk_drivers
     endif
 
+    if is_windows and is_shared_enabled
+        cflags += '-DRTE_BUILD_SHARED_LIB'
+    endif
+
     exec = executable('dpdk-' + name,
             sources,
             c_args: cflags,
config/meson.build +20 -0
index 8c8b019..e949240 100644
@@ -53,6 +53,9 @@ if is_ms_compiler
 
     # enable statement expressions extension
     add_project_arguments('/experimental:statementExpressions', language: 'c')
+
+    # enable export of thread_local variables
+    add_project_arguments('/experimental:tlsDllInterface', language: 'c')
 endif
 
 # set the major version, which might be used by drivers and libraries
@@ -516,4 +519,21 @@ if get_option('default_library') == 'both'
  NOTE: DPDK always builds both shared and static libraries.  Please set
  "default_library" to either "static" or "shared" to select default linkage
  for apps and any examples.''')
+elif get_option('default_library') == 'shared' and is_windows and not is_ms_compiler
+    error( '''
+ Unsupported value "shared" for "default_library" option.
+
+ NOTE: DPDK Windows shared is only supported when building with MSVC. Please set
+ "default_library" to either "static" or use MSVC.''')
+endif
+
+is_shared_enabled=true
+install_static = true
+install_shared = true
+if is_windows
+    install_static = get_option('default_library') == 'static'
+    install_shared = get_option('default_library') == 'shared'
+    if not is_ms_compiler or not install_shared
+        is_shared_enabled = false
+    endif
 endif
drivers/meson.build +30 -34

91 lines not on this page · raw message

drivers/net/octeontx/base/meson.build +1 -1
index 8e5e8c1..a793c19 100644
@@ -10,7 +10,7 @@ sources = [
 depends = ['ethdev', 'mempool_octeontx']
 static_objs = []
 foreach d: depends
-    if not is_variable('shared_rte_' + d)
+    if not is_variable('static_rte_' + d)
         subdir_done()
     endif
     static_objs += get_variable('static_rte_' + d)
examples/meson.build +6 -0
index 8e8968a..e08a169 100644
@@ -85,6 +85,8 @@ endif
 default_ldflags = dpdk_extra_ldflags
 if get_option('default_library') == 'static' and not is_windows
     default_ldflags += ['-Wl,--export-dynamic']
+elif is_ms_compiler
+    default_ldflags += ['/experimental:tlsDllInterface']
 endif
 
 foreach example: examples
@@ -121,6 +123,10 @@ foreach example: examples
         continue
     endif
 
+    if is_windows and is_shared_enabled
+        cflags += '-DRTE_BUILD_SHARED_LIB'
+    endif
+
     if allow_experimental_apis
         cflags += '-DALLOW_EXPERIMENTAL_API'
     endif
lib/meson.build +31 -41

104 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#13 lore raw

v3 cover build and install only one library type on Windows

In reply to Tyler Retzlaff

MSVC is the only compiler that can produce usable shared libraries for DPDK on Windows because of the use of exported TLS variables.

Disable building of shared libraries with LLVM and MinGW so that remaining __declspec macros needed for the functional libraries built by MSVC can be used without triggering errors in LLVM and MinGW builds.

For Windows only install the default_library type to avoid confusion. Windows builds cannot build both shared and static in a single pass so install only the functional variant

MSVC does not guarantee any kind of compatibility for static libraries so they should not be packaged and instead they should be rebuilt along with the application using the same version of the compiler & linker. Because of this we have chosen to build only one library type at a time instead of compiling twice to produce both types in a single pass.

v3:
* condense library, target and toolchain type logic determining values for is_shared_enabled,install_{static,shared} values.
* define empty shared_dep object to allow unconditional evaluation of shared variables even when is_shared_enabled is false.
* use default_library() string to determine deps for chkincs.

Tyler Retzlaff (2):
build: build only one library type on Windows
buildtools: when building static library use static deps

 app/meson.build                       |  6 +++
 buildtools/chkincs/meson.build        |  5 ++-
 config/meson.build                    | 20 ++++++++++
 drivers/meson.build                   | 64 +++++++++++++++----------------
 drivers/net/octeontx/base/meson.build |  2 +-
 examples/meson.build                  |  6 +++
 lib/meson.build                       | 72 +++++++++++++++--------------------
 7 files changed, 97 insertions(+), 78 deletions(-)
Signature · 1 line
1.8.3.1
#16 lore raw

PATCH v3 2/2 buildtools: when building static library use static deps

Use the value of default_library and use it when building deps instead of always using static deps so we get the correct static or shared deps.

---
 buildtools/chkincs/meson.build | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
buildtools/chkincs/meson.build +3 -2
index f2dadca..5546489 100644
@@ -20,10 +20,11 @@ sources += gen_c_files.process(dpdk_chkinc_headers)
 
 # some driver SDK headers depend on these two buses, which are mandatory in build
 # so we always include them in deps list
-deps = [get_variable('shared_rte_bus_vdev'), get_variable('shared_rte_bus_pci')]
+library_type = get_option('default_library')
+deps = [get_variable(library_type + '_rte_bus_vdev'), get_variable(library_type + '_rte_bus_pci')]
 # add the rest of the libs to the dependencies
 foreach l:dpdk_libs_enabled
-    deps += get_variable('shared_rte_' + l)
+    deps += get_variable(library_type + '_rte_' + l)
 endforeach
 
 executable('chkincs', sources,
Signature · 1 line
1.8.3.1
#12 lore raw

Re: [PATCH v2 2/2] buildtools: when building static library use static deps

In reply to Bruce Richardson
Quoted 15 lines · Bruce Richardson
Quoted 14 lines · Tyler Retzlaff

Use static deps when default_library=static and use shared deps when using default_library=shared.

---
 buildtools/chkincs/meson.build | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
buildtools/chkincs/meson.build +0 -0
index f2dadca..66245a5 100644
@@ -20,11 +20,19 @@ sources += gen_c_files.process(dpdk_chkinc_headers)
 
Quoted 10 lines

buildtools/chkincs/meson.build sources += gen_c_files.process(dpdk_chkinc_headers) · line 27

Quoted 7 lines
buildtools/chkincs/meson.build +0 -5
 # some driver SDK headers depend on these two buses, which are mandatory in build
 # so we always include them in deps list
-deps = [get_variable('shared_rte_bus_vdev'), get_variable('shared_rte_bus_pci')]
-# add the rest of the libs to the dependencies
-foreach l:dpdk_libs_enabled
-    deps += get_variable('shared_rte_' + l)
-endforeach

shorter fix might be to use get_option('default_library') in place of the "shared" string, rather than using a condition.

done in v3.

Quoted 22 lines

/Bruce

Quoted 19 lines
buildtools/chkincs/meson.build +13 -0
+if is_shared_enabled
+    deps = [get_variable('shared_rte_bus_vdev'), get_variable('shared_rte_bus_pci')]
+    # add the rest of the libs to the dependencies
+    foreach l:dpdk_libs_enabled
+        deps += get_variable('shared_rte_' + l)
+    endforeach
+else
+    deps = [get_variable('static_rte_bus_vdev'), get_variable('static_rte_bus_pci')]
+    # add the rest of the libs to the dependencies
+    foreach l:dpdk_libs_enabled
+        deps += get_variable('static_rte_' + l)
+    endforeach
+endif
 
 executable('chkincs', sources,
         c_args: cflags,
Signature · 1 line
1.8.3.1
#5 lore raw

Re: [PATCH v2 1/2] build: build only one library type on Windows

In reply to Bruce Richardson
Quoted 27 lines · Bruce Richardson
Quoted 7 lines · Tyler Retzlaff

MSVC is the only compiler that can produce usable shared libraries for DPDK on Windows because of the use of exported TLS variables.

Disable building of shared libraries with LLVM and MinGW so that remaining __declspec macros needed for the functional libraries built by MSVC can be used without triggering errors in LLVM and MinGW builds.

Quoted 5 lines

For Windows only install the default_library type to avoid confusion. Windows builds cannot build both shared and static in a single pass so install only the functional variant.

Comments inline below.

/Bruce

Quoted 9 lines
---
 app/meson.build                       |  6 +++
 config/meson.build                    | 27 ++++++++++++
 drivers/meson.build                   | 72 +++++++++++++++----------------
 drivers/net/octeontx/base/meson.build |  2 +-
 examples/meson.build                  |  6 +++
 lib/meson.build                       | 79 +++++++++++++++--------------------
 6 files changed, 108 insertions(+), 84 deletions(-)
Quoted 15 lines

app/meson.build default_cflags = machine_args + ['-DALLOW_EXPERIMENTAL_API'] · line 52

Quoted 12 lines
app/meson.build +2 -0
index 21b6da2..f4ed0f1 100644
@@ -46,6 +46,8 @@ default_cflags = machine_args + ['-DALLOW_EXPERIMENTAL_API']
 default_ldflags = []
 if get_option('default_library') == 'static' and not is_windows
     default_ldflags += ['-Wl,--export-dynamic']
+elif get_option('default_library') == 'shared' and is_ms_compiler
+    default_ldflags += ['/experimental:tlsDllInterface']
 endif
 

Is this necessary, given that you add this flag as a project-wide argument below in config/meson.build?

yes, i need to provide tlsDllInterface as an argument to both the compiler and the linker commands. project-wide argument from config/meson.build only adds the argument to the compiler command line but not the linker. there doesn't appear to be a global variable that can be used as the same for the linker so it has been added to the various ldflags/lkflags variables in individual meson.build files.

Quoted 18 lines
Quoted 18 lines
app/meson.build +4 -0
 foreach app:apps
@@ -104,6 +106,10 @@ foreach app:apps
         link_libs = dpdk_static_libraries + dpdk_drivers
     endif
 
+    if is_windows and is_shared_enabled
+        cflags += '-DRTE_BUILD_SHARED_LIB'
+    endif
+
     exec = executable('dpdk-' + name,
             sources,
             c_args: cflags,
config/meson.build +0 -0
index 8c8b019..dd7971e 100644
@@ -53,6 +53,9 @@ if is_ms_compiler
 
Quoted 6 lines

config/meson.build if is_ms_compiler · line 59

Quoted 6 lines
config/meson.build +3 -0
     # enable statement expressions extension
     add_project_arguments('/experimental:statementExpressions', language: 'c')
+
+    # enable export of thread_local variables
+    add_project_arguments('/experimental:tlsDllInterface', language: 'c')
 endif

as per above, this only causes the argument to be added to the compiler not the linker.

Quoted 50 lines
Quoted 14 lines
config/meson.build +8 -0
 # set the major version, which might be used by drivers and libraries
@@ -516,4 +519,28 @@ if get_option('default_library') == 'both'
  NOTE: DPDK always builds both shared and static libraries.  Please set
  "default_library" to either "static" or "shared" to select default linkage
  for apps and any examples.''')
+elif get_option('default_library') == 'shared' and is_windows and not is_ms_compiler
+    error( '''
+ Unsupported value "shared" for "default_library" option.
+
+ NOTE: DPDK Windows shared is only supported when building with MSVC. Please set
+ "default_library" to either "static" or use MSVC.''')
+endif
+

config/meson.build if get_option('default_library') == 'both' · line 539

Quoted 10 lines
config/meson.build +10 -0
+if is_windows
+    if is_ms_compiler and get_option('default_library') == 'shared'
+        is_shared_enabled=true
+    else
+        is_shared_enabled=false
+    endif
+else
+    is_shared_enabled=true
+endif
+

This can be shortened to:

is_shared_enabled=true
if is_windows and (not is_ms_compiler or not get_option(...) == 'shared')
is_shared_enabled=false
endif

config/meson.build if get_option('default_library') == 'both' · line 546

Quoted 7 lines
config/meson.build +6 -0
+if is_windows
+    install_static = get_option('default_library') == 'static'
+    install_shared = get_option('default_library') == 'shared'
+else
+    install_static=true
+    install_shared=true
 endif

Might be better merged with the block above:

is_shared_enabled = true
install_static = true
install_shared = true
if is_windows
install_static = get_option('default_library') == 'static' install_shared = get_option('default_library') == 'shared'

Quoted 4 lines

if not is_ms_compiler or not install_shared
is_shared_enabled = false
endif
endif

done in v3, much nicer thanks.

Quoted 36 lines
Quoted 36 lines
drivers/meson.build +5 -3
index 66931d4..c8b2d13 100644
@@ -80,7 +80,7 @@ foreach subpath:subdirs
         subdir(class)
         skip_class = false
         foreach d:std_deps
-            if not is_variable('shared_rte_' + d)
+            if not is_variable('static_rte_' + d)
                 skip_class = true
                 reason = 'missing internal dependency, "@0@"'.format(d)
                 if dpdk_libs_deprecated.contains(d)
@@ -173,7 +173,7 @@ foreach subpath:subdirs
                 if not build
                     break
                 endif
-                if not is_variable('shared_rte_' + d)
+                if not is_variable('static_rte_' + d)
                     build = false
                     reason = 'missing internal dependency, "@0@"'.format(d)
                     if dpdk_libs_deprecated.contains(d)
@@ -188,7 +188,9 @@ foreach subpath:subdirs
                                 +'\tPlease enable missing dependency "@0@"'.format(d))
                     endif
                 else
-                    shared_deps += [get_variable('shared_rte_' + d)]
+                    if is_shared_enabled
+                        shared_deps += [get_variable('shared_rte_' + d)]
+                    endif
                     static_deps += [get_variable('static_rte_' + d)]
                 endif
             endforeach
@@ -208,6 +210,9 @@ foreach subpath:subdirs
         enabled_drivers += name
Quoted 8 lines

drivers/meson.build foreach subpath:subdirs · line 215

Quoted 5 lines
drivers/meson.build +3 -0
         lib_name = '_'.join(['rte', class, name])
         cflags += '-DRTE_LOG_DEFAULT_LOGTYPE=' + '.'.join([log_prefix, name])
+        if is_windows and is_shared_enabled
+            cflags += '-DRTE_BUILD_SHARED_LIB'
+        endif

Rather than setting this in cflags in the drivers or lib meson.build files, can we set this once as a project-level cflag and be done with it?

i don't think so, there are drivers (notably mellanox) that appear to assume it is not always set by default even with a shared build. i think this one might best be cleaned up and clarified in a separate series.

Quoted 27 lines
Quoted 27 lines
drivers/meson.build +3 -4
         if annotate_locks and cc.get_id() == 'clang' and cc.version().version_compare('>=3.5.0')
             cflags += '-DRTE_ANNOTATE_LOCKS'
             cflags += '-Wthread-safety'
@@ -247,7 +252,7 @@ foreach subpath:subdirs
                 include_directories: includes,
                 dependencies: static_deps,
                 c_args: cflags,
-                install: true)
+                install: install_static)
 
         # now build the shared driver
         version_map = '@0@/@1@/version.map'.format(meson.current_source_dir(), drv_path)
@@ -271,55 +276,46 @@ foreach subpath:subdirs
             endif
         endif
 
-        if is_windows
-            if is_ms_linker
+        if is_shared_enabled
+            if is_ms_compiler
                 def_file = custom_target(lib_name + '_def',
                         command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
                         input: version_map,
                         output: '@0@_exports.def'.format(lib_name))
                 lk_deps += [def_file]
-
Quoted 8 lines

drivers/meson.build foreach subpath:subdirs · line 286

Quoted 5 lines
drivers/meson.build +1 -4
-                lk_args = ['-Wl,/def:' + def_file.full_path()]
-                if meson.version().version_compare('<0.54.0')
-                    lk_args += ['-Wl,/implib:drivers\\lib' + lib_name + '.dll.a']
-                endif
+                lk_args = ['/experimental:tlsDllInterface', '/def:' + def_file.full_path()]

Again, the /experimental flag shouldn't be necessary, since it's set as project option in config/meson.build.

as per above, let me know if what i said seems crazy.

Quoted 66 lines
Quoted 42 lines
drivers/meson.build +11 -26
             else
-                mingw_map = custom_target(lib_name + '_mingw',
-                        command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
-                        input: version_map,
-                        output: '@0@_mingw.map'.format(lib_name))
-                lk_deps += [mingw_map]
-
-                lk_args = ['-Wl,--version-script=' + mingw_map.full_path()]
+                lk_args = ['-Wl,--version-script=' + version_map]
             endif
-        else
-            lk_args = ['-Wl,--version-script=' + version_map]
         endif
 
-        shared_lib = shared_library(lib_name, sources,
-                objects: objs,
-                include_directories: includes,
-                dependencies: shared_deps,
-                c_args: cflags,
-                link_args: lk_args,
-                link_depends: lk_deps,
-                version: abi_version,
-                soversion: so_version,
-                install: true,
-                install_dir: driver_install_path)
-
-        # create a dependency object and add it to the global dictionary so
-        # testpmd or other built-in apps can find it if necessary
-        shared_dep = declare_dependency(link_with: shared_lib,
-                include_directories: includes,
-                dependencies: shared_deps)
+        if is_shared_enabled
+            shared_lib = shared_library(lib_name, sources,
+                    objects: objs,
+                    include_directories: includes,
+                    dependencies: shared_deps,
+                    c_args: cflags,
+                    link_args: lk_args,
+                    link_depends: lk_deps,
+                    version: abi_version,
+                    soversion: so_version,

drivers/meson.build foreach subpath:subdirs · line 311

Quoted 10 lines
drivers/meson.build +10 -0
+                    install: install_shared,
+                    install_dir: driver_install_path)
+
+            # create a dependency object and add it to the global dictionary so
+            # testpmd or other built-in apps can find it if necessary
+            shared_dep = declare_dependency(link_with: shared_lib,
+                    include_directories: includes,
+                    dependencies: shared_deps)
+
+            set_variable('shared_@0@'.format(lib_name), shared_dep)

Just a thought - could you avoid some of the changes throughout this set, if you add an else-leg to the "is_shared_enabled" check, where, if shared is not enabled, you assign shared_dep to be an empty string, or an empty object or something.

That would mean that you wouldn't need to move the set_variable line as here, you also wouldn't need to put conditionals around all the

Just a thought - could you avoid some of the changes throughout this set, if you add an else-leg to the "is_shared_enabled" check, where, if shared is not enabled, you assign shared_dep to be an empty string, or an empty object or something.

Quoted 6 lines

That would mean that you wouldn't need to move the set_variable line as here, you also wouldn't need to put conditionals around all the 'shared_deps +=' lines when processing deps for a component, and lastly, you may not even need to change all the searches for shared_rte_ to static_rte, since the variables would exist for shared - they'd just be empty!

did this in v3, still requires a diff -b to read what actually changed but appears to have worked out as you anticipated. so i think probably it was a good improvement.

Quoted 9 lines

drivers/meson.build foreach subpath:subdirs · line 317

Quoted 7 lines
drivers/meson.build +1 -0
+        endif
         static_dep = declare_dependency(
                 include_directories: includes,
                 dependencies: static_deps)
 
         dpdk_drivers += static_lib

<snip for brevity>

#6 lore raw

Re: [PATCH v2 1/2] build: build only one library type on Windows

Quoted 44 lines · Tyler Retzlaff
Quoted 27 lines · Bruce Richardson
Quoted 7 lines · Tyler Retzlaff

MSVC is the only compiler that can produce usable shared libraries for DPDK on Windows because of the use of exported TLS variables.

Disable building of shared libraries with LLVM and MinGW so that remaining __declspec macros needed for the functional libraries built by MSVC can be used without triggering errors in LLVM and MinGW builds.

Quoted 5 lines

For Windows only install the default_library type to avoid confusion. Windows builds cannot build both shared and static in a single pass so install only the functional variant.

Comments inline below.

/Bruce

Quoted 9 lines
---
 app/meson.build                       |  6 +++
 config/meson.build                    | 27 ++++++++++++
 drivers/meson.build                   | 72 +++++++++++++++----------------
 drivers/net/octeontx/base/meson.build |  2 +-
 examples/meson.build                  |  6 +++
 lib/meson.build                       | 79 +++++++++++++++--------------------
 6 files changed, 108 insertions(+), 84 deletions(-)
Quoted 15 lines

app/meson.build default_cflags = machine_args + ['-DALLOW_EXPERIMENTAL_API'] · line 52

Quoted 12 lines
app/meson.build +2 -0
index 21b6da2..f4ed0f1 100644
@@ -46,6 +46,8 @@ default_cflags = machine_args + ['-DALLOW_EXPERIMENTAL_API']
 default_ldflags = []
 if get_option('default_library') == 'static' and not is_windows
     default_ldflags += ['-Wl,--export-dynamic']
+elif get_option('default_library') == 'shared' and is_ms_compiler
+    default_ldflags += ['/experimental:tlsDllInterface']
 endif
 

Is this necessary, given that you add this flag as a project-wide argument below in config/meson.build?

Quoted 7 lines

yes, i need to provide tlsDllInterface as an argument to both the compiler and the linker commands. project-wide argument from config/meson.build only adds the argument to the compiler command line but not the linker. there doesn't appear to be a global variable that can be used as the same for the linker so it has been added to the various ldflags/lkflags variables in individual meson.build files.

The add_project_link_arguments() function should be what you are looking for, I think.

https://mesonbuild.com/Reference-manual_functions.html#add_project_link_arguments

Quoted 130 lines
Quoted 18 lines
Quoted 18 lines
app/meson.build +4 -0
 foreach app:apps
@@ -104,6 +106,10 @@ foreach app:apps
         link_libs = dpdk_static_libraries + dpdk_drivers
     endif
 
+    if is_windows and is_shared_enabled
+        cflags += '-DRTE_BUILD_SHARED_LIB'
+    endif
+
     exec = executable('dpdk-' + name,
             sources,
             c_args: cflags,
config/meson.build +0 -0
index 8c8b019..dd7971e 100644
@@ -53,6 +53,9 @@ if is_ms_compiler
 
Quoted 6 lines

config/meson.build if is_ms_compiler · line 59

Quoted 6 lines
config/meson.build +3 -0
     # enable statement expressions extension
     add_project_arguments('/experimental:statementExpressions', language: 'c')
+
+    # enable export of thread_local variables
+    add_project_arguments('/experimental:tlsDllInterface', language: 'c')
 endif

as per above, this only causes the argument to be added to the compiler not the linker.

Quoted 50 lines
Quoted 14 lines
config/meson.build +8 -0
 # set the major version, which might be used by drivers and libraries
@@ -516,4 +519,28 @@ if get_option('default_library') == 'both'
  NOTE: DPDK always builds both shared and static libraries.  Please set
  "default_library" to either "static" or "shared" to select default linkage
  for apps and any examples.''')
+elif get_option('default_library') == 'shared' and is_windows and not is_ms_compiler
+    error( '''
+ Unsupported value "shared" for "default_library" option.
+
+ NOTE: DPDK Windows shared is only supported when building with MSVC. Please set
+ "default_library" to either "static" or use MSVC.''')
+endif
+

config/meson.build if get_option('default_library') == 'both' · line 539

Quoted 10 lines
config/meson.build +10 -0
+if is_windows
+    if is_ms_compiler and get_option('default_library') == 'shared'
+        is_shared_enabled=true
+    else
+        is_shared_enabled=false
+    endif
+else
+    is_shared_enabled=true
+endif
+

This can be shortened to:

is_shared_enabled=true
if is_windows and (not is_ms_compiler or not get_option(...) == 'shared')
is_shared_enabled=false
endif

config/meson.build if get_option('default_library') == 'both' · line 546

Quoted 7 lines
config/meson.build +6 -0
+if is_windows
+    install_static = get_option('default_library') == 'static'
+    install_shared = get_option('default_library') == 'shared'
+else
+    install_static=true
+    install_shared=true
 endif

Might be better merged with the block above:

is_shared_enabled = true
install_static = true
install_shared = true
if is_windows
install_static = get_option('default_library') == 'static' install_shared = get_option('default_library') == 'shared'

Quoted 4 lines

if not is_ms_compiler or not install_shared
is_shared_enabled = false
endif
endif

done in v3, much nicer thanks.

Quoted 36 lines
Quoted 36 lines
drivers/meson.build +5 -3
index 66931d4..c8b2d13 100644
@@ -80,7 +80,7 @@ foreach subpath:subdirs
         subdir(class)
         skip_class = false
         foreach d:std_deps
-            if not is_variable('shared_rte_' + d)
+            if not is_variable('static_rte_' + d)
                 skip_class = true
                 reason = 'missing internal dependency, "@0@"'.format(d)
                 if dpdk_libs_deprecated.contains(d)
@@ -173,7 +173,7 @@ foreach subpath:subdirs
                 if not build
                     break
                 endif
-                if not is_variable('shared_rte_' + d)
+                if not is_variable('static_rte_' + d)
                     build = false
                     reason = 'missing internal dependency, "@0@"'.format(d)
                     if dpdk_libs_deprecated.contains(d)
@@ -188,7 +188,9 @@ foreach subpath:subdirs
                                 +'\tPlease enable missing dependency "@0@"'.format(d))
                     endif
                 else
-                    shared_deps += [get_variable('shared_rte_' + d)]
+                    if is_shared_enabled
+                        shared_deps += [get_variable('shared_rte_' + d)]
+                    endif
                     static_deps += [get_variable('static_rte_' + d)]
                 endif
             endforeach
@@ -208,6 +210,9 @@ foreach subpath:subdirs
         enabled_drivers += name
Quoted 8 lines

drivers/meson.build foreach subpath:subdirs · line 215

Quoted 5 lines
drivers/meson.build +3 -0
         lib_name = '_'.join(['rte', class, name])
         cflags += '-DRTE_LOG_DEFAULT_LOGTYPE=' + '.'.join([log_prefix, name])
+        if is_windows and is_shared_enabled
+            cflags += '-DRTE_BUILD_SHARED_LIB'
+        endif

Rather than setting this in cflags in the drivers or lib meson.build files, can we set this once as a project-level cflag and be done with it?

Quoted 4 lines

i don't think so, there are drivers (notably mellanox) that appear to assume it is not always set by default even with a shared build. i think this one might best be cleaned up and clarified in a separate series.

Oh, how does this assumption show itself or what impact has it? Using git grep in the source code for the macro only shows the expected usage in function_versioning header, and in lib/meson.build.

Quoted 111 lines
Quoted 27 lines
Quoted 27 lines
drivers/meson.build +3 -4
         if annotate_locks and cc.get_id() == 'clang' and cc.version().version_compare('>=3.5.0')
             cflags += '-DRTE_ANNOTATE_LOCKS'
             cflags += '-Wthread-safety'
@@ -247,7 +252,7 @@ foreach subpath:subdirs
                 include_directories: includes,
                 dependencies: static_deps,
                 c_args: cflags,
-                install: true)
+                install: install_static)
 
         # now build the shared driver
         version_map = '@0@/@1@/version.map'.format(meson.current_source_dir(), drv_path)
@@ -271,55 +276,46 @@ foreach subpath:subdirs
             endif
         endif
 
-        if is_windows
-            if is_ms_linker
+        if is_shared_enabled
+            if is_ms_compiler
                 def_file = custom_target(lib_name + '_def',
                         command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
                         input: version_map,
                         output: '@0@_exports.def'.format(lib_name))
                 lk_deps += [def_file]
-
Quoted 8 lines

drivers/meson.build foreach subpath:subdirs · line 286

Quoted 5 lines
drivers/meson.build +1 -4
-                lk_args = ['-Wl,/def:' + def_file.full_path()]
-                if meson.version().version_compare('<0.54.0')
-                    lk_args += ['-Wl,/implib:drivers\\lib' + lib_name + '.dll.a']
-                endif
+                lk_args = ['/experimental:tlsDllInterface', '/def:' + def_file.full_path()]

Again, the /experimental flag shouldn't be necessary, since it's set as project option in config/meson.build.

as per above, let me know if what i said seems crazy.

Quoted 66 lines
Quoted 42 lines
drivers/meson.build +11 -26
             else
-                mingw_map = custom_target(lib_name + '_mingw',
-                        command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
-                        input: version_map,
-                        output: '@0@_mingw.map'.format(lib_name))
-                lk_deps += [mingw_map]
-
-                lk_args = ['-Wl,--version-script=' + mingw_map.full_path()]
+                lk_args = ['-Wl,--version-script=' + version_map]
             endif
-        else
-            lk_args = ['-Wl,--version-script=' + version_map]
         endif
 
-        shared_lib = shared_library(lib_name, sources,
-                objects: objs,
-                include_directories: includes,
-                dependencies: shared_deps,
-                c_args: cflags,
-                link_args: lk_args,
-                link_depends: lk_deps,
-                version: abi_version,
-                soversion: so_version,
-                install: true,
-                install_dir: driver_install_path)
-
-        # create a dependency object and add it to the global dictionary so
-        # testpmd or other built-in apps can find it if necessary
-        shared_dep = declare_dependency(link_with: shared_lib,
-                include_directories: includes,
-                dependencies: shared_deps)
+        if is_shared_enabled
+            shared_lib = shared_library(lib_name, sources,
+                    objects: objs,
+                    include_directories: includes,
+                    dependencies: shared_deps,
+                    c_args: cflags,
+                    link_args: lk_args,
+                    link_depends: lk_deps,
+                    version: abi_version,
+                    soversion: so_version,

drivers/meson.build foreach subpath:subdirs · line 311

Quoted 10 lines
drivers/meson.build +10 -0
+                    install: install_shared,
+                    install_dir: driver_install_path)
+
+            # create a dependency object and add it to the global dictionary so
+            # testpmd or other built-in apps can find it if necessary
+            shared_dep = declare_dependency(link_with: shared_lib,
+                    include_directories: includes,
+                    dependencies: shared_deps)
+
+            set_variable('shared_@0@'.format(lib_name), shared_dep)

Just a thought - could you avoid some of the changes throughout this set, if you add an else-leg to the "is_shared_enabled" check, where, if shared is not enabled, you assign shared_dep to be an empty string, or an empty object or something.

That would mean that you wouldn't need to move the set_variable line as here, you also wouldn't need to put conditionals around all the

Just a thought - could you avoid some of the changes throughout this set, if you add an else-leg to the "is_shared_enabled" check, where, if shared is not enabled, you assign shared_dep to be an empty string, or an empty object or something.

Quoted 6 lines

That would mean that you wouldn't need to move the set_variable line as here, you also wouldn't need to put conditionals around all the 'shared_deps +=' lines when processing deps for a component, and lastly, you may not even need to change all the searches for shared_rte_ to static_rte, since the variables would exist for shared - they'd just be empty!

Quoted 4 lines

did this in v3, still requires a diff -b to read what actually changed but appears to have worked out as you anticipated. so i think probably it was a good improvement.

Great, thanks for trying it!

Quoted 9 lines
Quoted 9 lines

drivers/meson.build foreach subpath:subdirs · line 317

Quoted 7 lines
drivers/meson.build +1 -0
+        endif
         static_dep = declare_dependency(
                 include_directories: includes,
                 dependencies: static_deps)
 
         dpdk_drivers += static_lib

<snip for brevity>

#15 lore raw

Re: [PATCH v3 1/2] build: build only one library type on Windows

In reply to Tyler Retzlaff
Quoted 21 lines · Tyler Retzlaff

MSVC is the only compiler that can produce usable shared libraries for DPDK on Windows because of the use of exported TLS variables.

Disable building of shared libraries with LLVM and MinGW so that remaining __declspec macros needed for the functional libraries built by MSVC can be used without triggering errors in LLVM and MinGW builds.

For Windows only install the default_library type to avoid confusion. Windows builds cannot build both shared and static in a single pass so install only the functional variant.

---
 app/meson.build                       |  6 +++
 config/meson.build                    | 20 ++++++++++
 drivers/meson.build                   | 64 +++++++++++++++----------------
 drivers/net/octeontx/base/meson.build |  2 +-
 examples/meson.build                  |  6 +++
 lib/meson.build                       | 72 +++++++++++++++--------------------
 6 files changed, 94 insertions(+), 76 deletions(-)

<snip>

Quoted 18 lines
drivers/meson.build +12 -6
-
-        # create a dependency object and add it to the global dictionary so
-        # testpmd or other built-in apps can find it if necessary
-        shared_dep = declare_dependency(link_with: shared_lib,
-                include_directories: includes,
-                dependencies: shared_deps)
+        if is_shared_enabled
+            shared_lib = shared_library(lib_name, sources,
+                    objects: objs,
+                    include_directories: includes,
+                    dependencies: shared_deps,
+                    c_args: cflags,
+                    link_args: lk_args,
+                    link_depends: lk_deps,
+                    version: abi_version,
+                    soversion: so_version,
+                    install: install_shared,
+                    install_dir: driver_install_path)

drivers/meson.build foreach subpath:subdirs · line 311

Quoted 10 lines
drivers/meson.build +10 -0
+
+            # create a dependency object and add it to the global dictionary so
+            # testpmd or other built-in apps can find it if necessary
+            shared_dep = declare_dependency(link_with: shared_lib,
+                    include_directories: includes,
+                    dependencies: shared_deps)
+
+        else
+            shared_dep = {}
+        endif

Very minor nit, but it's generally easier to follow code where you put the short leg of the condition first, and then the longer leg. Having the short leg (in this case the one-line) first means the reader has no difficulty remembering what the original condition was, once they get to the "else". The longer leg requires more attention and having it last means the reader doesn't need to worry about maintaining the context of the "if" in memory. [To a certain extent this is just user-preference, so feel free to ignore this comment if it's too much work! :-)]

drivers/net/octeontx/base/meson.build sources = [ · line 13

Quoted 13 lines
         static_dep = declare_dependency(
                 include_directories: includes,
                 dependencies: static_deps)
drivers/net/octeontx/base/meson.build +1 -1
index 8e5e8c1..a793c19 100644
@@ -10,7 +10,7 @@ sources = [
 depends = ['ethdev', 'mempool_octeontx']
 static_objs = []
 foreach d: depends
-    if not is_variable('shared_rte_' + d)
+    if not is_variable('static_rte_' + d)

Since we have empty objects defined for the shared vars in the no-shared case, you can drop this change.

Quoted 3 lines
drivers/net/octeontx/base/meson.build +0 -0
         subdir_done()
     endif
     static_objs += get_variable('static_rte_' + d)

<snip>

#20 lore raw

PATCH v4 2/2 buildtools: when building static library use static deps

In reply to Tyler Retzlaff

Use the value of default_library and use it when building deps instead of always using static deps so we get the correct static or shared deps.

---
 buildtools/chkincs/meson.build | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
buildtools/chkincs/meson.build +3 -2
index f2dadca..5546489 100644
@@ -20,10 +20,11 @@ sources += gen_c_files.process(dpdk_chkinc_headers)
 
 # some driver SDK headers depend on these two buses, which are mandatory in build
 # so we always include them in deps list
-deps = [get_variable('shared_rte_bus_vdev'), get_variable('shared_rte_bus_pci')]
+library_type = get_option('default_library')
+deps = [get_variable(library_type + '_rte_bus_vdev'), get_variable(library_type + '_rte_bus_pci')]
 # add the rest of the libs to the dependencies
 foreach l:dpdk_libs_enabled
-    deps += get_variable('shared_rte_' + l)
+    deps += get_variable(library_type + '_rte_' + l)
 endforeach
 
 executable('chkincs', sources,
Signature · 1 line
1.8.3.1
#18 lore raw

v4 cover build and install only one library type on Windows

In reply to Tyler Retzlaff

MSVC is the only compiler that can produce usable shared libraries for DPDK on Windows because of the use of exported TLS variables.

Disable building of shared libraries with LLVM and MinGW so that remaining __declspec macros needed for the functional libraries built by MSVC can be used without triggering errors in LLVM and MinGW builds.

For Windows only install the default_library type to avoid confusion. Windows builds cannot build both shared and static in a single pass so install only the functional variant

MSVC does not guarantee any kind of compatibility for static libraries so they should not be packaged and instead they should be rebuilt along with the application using the same version of the compiler & linker. Because of this we have chosen to build only one library type at a time instead of compiling twice to produce both types in a single pass.

v4:
* use add_project_link_arguments() and move addition of linker and compiler arguments required only dynamic linking to block where it is determined is_shared_enabled=true and don't specify when is_shared_enabled=false.
* unconditionally initialize shared_deps = {} and get rid of else leg of conditional evaluation in drivers/meson.build and lib/meson.build.
* drop change to octeontx meson.build.

v3:
* condense library, target and toolchain type logic determining values for is_shared_enabled,install_{static,shared} values.
* define empty shared_dep object to allow unconditional evaluation of shared variables even when is_shared_enabled is false.
* use default_library() string to determine deps for chkincs.

Tyler Retzlaff (2):
build: build only one library type on Windows
buildtools: when building static library use static deps

 app/meson.build                |  4 +++
 buildtools/chkincs/meson.build |  5 +--
 config/meson.build             | 21 +++++++++++++
 drivers/meson.build            | 62 +++++++++++++++++-------------------
 examples/meson.build           |  4 +++
 lib/meson.build                | 71 ++++++++++++++++++------------------------
 6 files changed, 90 insertions(+), 77 deletions(-)
Signature · 1 line
1.8.3.1
#19 lore raw

PATCH v4 1/2 build: build only one library type on Windows

MSVC is the only compiler that can produce usable shared libraries for DPDK on Windows because of the use of exported TLS variables.

Disable building of shared libraries with LLVM and MinGW so that remaining __declspec macros needed for the functional libraries built by MSVC can be used without triggering errors in LLVM and MinGW builds.

For Windows only install the default_library type to avoid confusion. Windows builds cannot build both shared and static in a single pass so install only the functional variant.

---
 app/meson.build      |  4 +++
 config/meson.build   | 21 ++++++++++++++++
 drivers/meson.build  | 62 +++++++++++++++++++++------------------------
 examples/meson.build |  4 +++
 lib/meson.build      | 71 ++++++++++++++++++++++------------------------------
 5 files changed, 87 insertions(+), 75 deletions(-)
app/meson.build +4 -0
index 21b6da2..d94378e 100644
@@ -104,6 +104,10 @@ foreach app:apps
         link_libs = dpdk_static_libraries + dpdk_drivers
     endif
 
+    if is_windows and is_shared_enabled
+        cflags += '-DRTE_BUILD_SHARED_LIB'
+    endif
+
     exec = executable('dpdk-' + name,
             sources,
             c_args: cflags,
config/meson.build +21 -0
index 8c8b019..c74899e 100644
@@ -516,4 +516,25 @@ if get_option('default_library') == 'both'
  NOTE: DPDK always builds both shared and static libraries.  Please set
  "default_library" to either "static" or "shared" to select default linkage
  for apps and any examples.''')
+elif get_option('default_library') == 'shared' and is_windows and not is_ms_compiler
+    error( '''
+ Unsupported value "shared" for "default_library" option.
+
+ NOTE: DPDK Windows shared is only supported when building with MSVC. Please set
+ "default_library" to either "static" or use MSVC.''')
+endif
+
+is_shared_enabled=true
+install_static = true
+install_shared = true
+if is_windows
+    install_static = get_option('default_library') == 'static'
+    install_shared = get_option('default_library') == 'shared'
+    if not is_ms_compiler or not install_shared
+        is_shared_enabled = false
+    else
+        # enable export / import of thread_local variables
+        add_project_arguments('/experimental:tlsDllInterface', language: 'c')
+        add_project_link_arguments('/experimental:tlsDllInterface', language: 'c')
+    endif
 endif
drivers/meson.build +28 -34

89 lines not on this page · raw message

examples/meson.build +4 -0
index 8e8968a..9ca2cb9 100644
@@ -121,6 +121,10 @@ foreach example: examples
         continue
     endif
 
+    if is_windows and is_shared_enabled
+        cflags += '-DRTE_BUILD_SHARED_LIB'
+    endif
+
     if allow_experimental_apis
         cflags += '-DALLOW_EXPERIMENTAL_API'
     endif
lib/meson.build +30 -41

103 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#24 lore raw

PATCH v5 2/2 buildtools: when building static library use static deps

In reply to Tyler Retzlaff

Use the value of default_library and use it when building deps instead of always using static deps so we get the correct static or shared deps.

---
 buildtools/chkincs/meson.build | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
buildtools/chkincs/meson.build +3 -2
index f2dadca..5546489 100644
@@ -20,10 +20,11 @@ sources += gen_c_files.process(dpdk_chkinc_headers)
 
 # some driver SDK headers depend on these two buses, which are mandatory in build
 # so we always include them in deps list
-deps = [get_variable('shared_rte_bus_vdev'), get_variable('shared_rte_bus_pci')]
+library_type = get_option('default_library')
+deps = [get_variable(library_type + '_rte_bus_vdev'), get_variable(library_type + '_rte_bus_pci')]
 # add the rest of the libs to the dependencies
 foreach l:dpdk_libs_enabled
-    deps += get_variable('shared_rte_' + l)
+    deps += get_variable(library_type + '_rte_' + l)
 endforeach
 
 executable('chkincs', sources,
Signature · 1 line
1.8.3.1
#21 lore raw

v5 cover build and install only one library type on Windows

In reply to Tyler Retzlaff

MSVC is the only compiler that can produce usable shared libraries for DPDK on Windows because of the use of exported TLS variables.

Disable building of shared libraries with LLVM and MinGW so that
remaining __declspec macros needed for the functional libraries built by
MSVC can be used without triggering errors in LLVM and MinGW builds.
For Windows only install the default_library type to avoid confusion.
Windows builds cannot build both shared and static in a single pass so
install only the functional variant

MSVC does not guarantee any kind of compatibility for static libraries so they should not be packaged and instead they should be rebuilt along with the application using the same version of the compiler & linker. Because of this we have chosen to build only one library type at a time instead of compiling twice to produce both types in a single pass.

thanks Bruce for all the discussion/feedback!

v5: set RTE_BUILD_SHARED_LIB in a single location when building with msvc
and is_shared_enabled instead of scattered over various meson.build files.

v4:
* use add_project_link_arguments() and move addition of linker and compiler arguments required only dynamic linking to block where it is determined is_shared_enabled=true and don't specify when is_shared_enabled=false.
* unconditionally initialize shared_deps = {} and get rid of else leg of conditional evaluation in drivers/meson.build and lib/meson.build.
* drop change to octeontx meson.build.

v3:
* condense library, target and toolchain type logic determining values for is_shared_enabled,install_{static,shared} values.
* define empty shared_dep object to allow unconditional evaluation of shared variables even when is_shared_enabled is false.
* use default_library() string to determine deps for chkincs.

Tyler Retzlaff (2):
build: build only one library type on Windows
buildtools: when building static library use static deps

 buildtools/chkincs/meson.build |  5 ++--
 config/meson.build             | 24 +++++++++++++++
 drivers/meson.build            | 59 ++++++++++++++++---------------------
 lib/meson.build                | 67 ++++++++++++++++--------------------------
 4 files changed, 78 insertions(+), 77 deletions(-)
Signature · 1 line
1.8.3.1
#22 lore raw

PATCH v5 1/2 build: build only one library type on Windows

MSVC is the only compiler that can produce usable shared libraries for DPDK on Windows because of the use of exported TLS variables.

Disable building of shared libraries with LLVM and MinGW so that remaining __declspec macros needed for the functional libraries built by MSVC can be used without triggering errors in LLVM and MinGW builds.

For Windows only install the default_library type to avoid confusion. Windows builds cannot build both shared and static in a single pass so install only the functional variant.

---
 config/meson.build  | 24 +++++++++++++++++++
 drivers/meson.build | 59 ++++++++++++++++++++--------------------------
 lib/meson.build     | 67 +++++++++++++++++++++--------------------------------
 3 files changed, 75 insertions(+), 75 deletions(-)
config/meson.build +24 -0
index 8c8b019..9882d33 100644
@@ -516,4 +516,28 @@ if get_option('default_library') == 'both'
  NOTE: DPDK always builds both shared and static libraries.  Please set
  "default_library" to either "static" or "shared" to select default linkage
  for apps and any examples.''')
+elif get_option('default_library') == 'shared' and is_windows and not is_ms_compiler
+    error( '''
+ Unsupported value "shared" for "default_library" option.
+
+ NOTE: DPDK Windows shared is only supported when building with MSVC. Please set
+ "default_library" to either "static" or use MSVC.''')
+endif
+
+is_shared_enabled=true
+install_static = true
+install_shared = true
+if is_windows
+    install_static = get_option('default_library') == 'static'
+    install_shared = get_option('default_library') == 'shared'
+    if not is_ms_compiler or not install_shared
+        is_shared_enabled = false
+    else
+        # building shared libraries
+        dpdk_conf.set('RTE_BUILD_SHARED_LIB', true)
+
+        # enable export / import of thread_local variables
+        add_project_arguments('/experimental:tlsDllInterface', language: 'c')
+        add_project_link_arguments('/experimental:tlsDllInterface', language: 'c')
+    endif
 endif
drivers/meson.build +25 -34

80 lines not on this page · raw message

lib/meson.build +26 -41

93 lines not on this page · raw message

Signature · 1 line
1.8.3.1
Reviewed-by on v5 1/2
#23 lore raw

Re: [PATCH v5 1/2] build: build only one library type on Windows

Quoted 7 lines · Tyler Retzlaff

MSVC is the only compiler that can produce usable shared libraries for DPDK on Windows because of the use of exported TLS variables.

Disable building of shared libraries with LLVM and MinGW so that remaining __declspec macros needed for the functional libraries built by MSVC can be used without triggering errors in LLVM and MinGW builds.

Quoted 6 lines

For Windows only install the default_library type to avoid confusion. Windows builds cannot build both shared and static in a single pass so install only the functional variant.

---

#25 lore raw
In reply to Tyler Retzlaff
Quoted 23 lines · Tyler Retzlaff

MSVC is the only compiler that can produce usable shared libraries for DPDK on Windows because of the use of exported TLS variables.

Disable building of shared libraries with LLVM and MinGW so that
remaining __declspec macros needed for the functional libraries built by
MSVC can be used without triggering errors in LLVM and MinGW builds.
For Windows only install the default_library type to avoid confusion.
Windows builds cannot build both shared and static in a single pass so
install only the functional variant

MSVC does not guarantee any kind of compatibility for static libraries so they should not be packaged and instead they should be rebuilt along with the application using the same version of the compiler & linker. Because of this we have chosen to build only one library type at a time instead of compiling twice to produce both types in a single pass.

thanks Bruce for all the discussion/feedback!

Tyler Retzlaff (2):
build: build only one library type on Windows
buildtools: when building static library use static deps

Quoted 5 lines
 buildtools/chkincs/meson.build |  5 ++--
 config/meson.build             | 24 +++++++++++++++
 drivers/meson.build            | 59 ++++++++++++++++---------------------
 lib/meson.build                | 67 ++++++++++++++++--------------------------
 4 files changed, 78 insertions(+), 77 deletions(-)

Series applied, thanks.

Signature · 1 line
David Marchand
#26 lore raw
Quoted 26 lines · David Marchand
Quoted 23 lines · Tyler Retzlaff

MSVC is the only compiler that can produce usable shared libraries for DPDK on Windows because of the use of exported TLS variables.

Disable building of shared libraries with LLVM and MinGW so that
remaining __declspec macros needed for the functional libraries built by
MSVC can be used without triggering errors in LLVM and MinGW builds.
For Windows only install the default_library type to avoid confusion.
Windows builds cannot build both shared and static in a single pass so
install only the functional variant

MSVC does not guarantee any kind of compatibility for static libraries so they should not be packaged and instead they should be rebuilt along with the application using the same version of the compiler & linker. Because of this we have chosen to build only one library type at a time instead of compiling twice to produce both types in a single pass.

thanks Bruce for all the discussion/feedback!

Tyler Retzlaff (2):
build: build only one library type on Windows
buildtools: when building static library use static deps

Quoted 7 lines
Quoted 5 lines
 buildtools/chkincs/meson.build |  5 ++--
 config/meson.build             | 24 +++++++++++++++
 drivers/meson.build            | 59 ++++++++++++++++---------------------
 lib/meson.build                | 67 ++++++++++++++++--------------------------
 4 files changed, 78 insertions(+), 77 deletions(-)

Series applied, thanks.

Hum, actually no, I dropped this series.
It breaks mingw builds.

dmarchan@dmarchan:~/git/pub/dpdk.org/main$ DPDK_ABI_REF_VERSION=v24.03
DPDK_BUILD_TEST_EXAMPLES=all DPDK_BUILD_TEST_DIR=$HOME/builds/main
./devtools/test-meson-builds.sh
ninja: Entering directory `/home/dmarchan/builds/main/build-gcc-shared'
ninja: no work to do.
ninja: Entering directory `/home/dmarchan/builds/main/build-clang-shared'
ninja: no work to do.
ninja: Entering directory `/home/dmarchan/builds/main/build-x86-generic'
ninja: no work to do.
ninja: Entering directory `/home/dmarchan/builds/main/build-32b'
ninja: no work to do.
DEPRECATION: "pkgconfig" entry is deprecated and should be replaced by
"pkg-config"
The Meson build system
Version: 1.3.2
Source dir: /home/dmarchan/git/pub/dpdk.org/main
Build dir: /home/dmarchan/builds/main/build-x86-mingw
Build type: cross build
Program cat found: YES (/usr/bin/cat)
Project name: DPDK
Project version: 24.07.0-rc0
C compiler for the host machine: ccache x86_64-w64-mingw32-gcc (gcc
13.2.1 "x86_64-w64-mingw32-gcc (GCC) 13.2.1 20230728 (Fedora MinGW
13.2.1-5.fc39)")
C linker for the host machine: x86_64-w64-mingw32-gcc ld.bfd 2.40-4
C compiler for the build machine: ccache cc (gcc 13.3.1 "cc (GCC)
13.3.1 20240522 (Red Hat 13.3.1-1)")
C linker for the build machine: cc ld.bfd 2.40-14
Build machine cpu family: x86_64
Build machine cpu: x86_64
Host machine cpu family: x86_64
Host machine cpu: native
Target machine cpu family: x86_64
Target machine cpu: native
Message: ## Building in Developer Mode ##
Program x86_64-w64-mingw32-pkg-config found: YES
Program check-symbols.sh found: YES
(/home/dmarchan/git/pub/dpdk.org/main/buildtools/check-symbols.sh)
Program options-ibverbs-static.sh found: YES
(/home/dmarchan/git/pub/dpdk.org/main/buildtools/options-ibverbs-static.sh)
Program python3 found: YES (/usr/bin/python3)
Program cat found: YES (/usr/bin/cat)
Compiler for C supports arguments -march=native: YES
Checking for size of "void *" : 8
Checking for size of "void *" : 8
Library m found: YES
Library numa found: NO
Library fdt found: NO
Library execinfo found: NO
Has header "execinfo.h" : NO
Found pkg-config: YES (/usr/bin/x86_64-w64-mingw32-pkg-config) 1.9.5
Run-time dependency libarchive found: NO (tried pkgconfig)
Run-time dependency libbsd found: NO (tried pkgconfig)
Run-time dependency jansson found: NO (tried pkgconfig)
Run-time dependency openssl found: NO (tried pkgconfig)
Run-time dependency libpcap found: NO (tried pkgconfig)
Library wpcap found: NO
Compiler for C supports arguments -Wcast-qual: YES
Compiler for C supports arguments -Wdeprecated: YES
Compiler for C supports arguments -Wformat: YES
Compiler for C supports arguments -Wformat-nonliteral: YES
Compiler for C supports arguments -Wformat-security: YES
Compiler for C supports arguments -Wmissing-declarations: YES
Compiler for C supports arguments -Wmissing-prototypes: YES
Compiler for C supports arguments -Wnested-externs: YES
Compiler for C supports arguments -Wold-style-definition: YES
Compiler for C supports arguments -Wpointer-arith: YES
Compiler for C supports arguments -Wsign-compare: YES
Compiler for C supports arguments -Wstrict-prototypes: YES
Compiler for C supports arguments -Wundef: YES
Compiler for C supports arguments -Wwrite-strings: YES
Compiler for C supports arguments -Wno-address-of-packed-member: YES
Compiler for C supports arguments -Wno-packed-not-aligned: YES
Compiler for C supports arguments -Wno-missing-field-initializers: YES
Compiler for C supports arguments -Wno-zero-length-bounds: YES
Program x86_64-w64-mingw32-objdump found: YES
Compiler for C supports arguments -mavx512f: YES
Checking if "AVX512 checking" compiles: YES
Fetching value of define "__SSE4_2__" : 1
Fetching value of define "__AES__" : 1
Fetching value of define "__AVX__" : 1
Fetching value of define "__AVX2__" : 1
Fetching value of define "__AVX512BW__" : 1
Fetching value of define "__AVX512CD__" : 1
Fetching value of define "__AVX512DQ__" : 1
Fetching value of define "__AVX512F__" : 1
Fetching value of define "__AVX512VL__" : 1
Fetching value of define "__PCLMUL__" : 1
Fetching value of define "__RDRND__" : 1
Fetching value of define "__RDSEED__" : 1
Fetching value of define "__VPCLMULQDQ__" : 1
Compiler for C supports arguments -Wno-format-truncation: YES
Message: lib/log: Defining dependency "log"
Message: lib/kvargs: Defining dependency "kvargs"
Message: lib/argparse: Defining dependency "argparse"
Message: lib/telemetry: Defining dependency "telemetry"
Library dbghelp found: YES
Library setupapi found: YES
Library ws2_32 found: YES
Checking for function "getentropy" : NO
Message: lib/eal: Defining dependency "eal"

lib/meson.build:218:21: ERROR: declare_dependency keyword argument 'dependencies' was of type array[dict] but should have been array[Dependency | InternalDependency]

A full log can be found at /home/dmarchan/builds/main/build-x86-mingw/meson-logs/meson-log.txt

Signature · 1 line
David Marchand