DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tyler Retzlaff <roretzla@linux.microsoft.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>,
	Harman Kalra <hkalra@marvell.com>,
	Tyler Retzlaff <roretzla@linux.microsoft.com>
Subject: [PATCH v3 1/2] build: build only one library type on Windows
Date: Fri, 12 Apr 2024 15:52:12 -0700	[thread overview]
Message-ID: <1712962333-14355-2-git-send-email-roretzla@linux.microsoft.com> (raw)
In-Reply-To: <1712962333-14355-1-git-send-email-roretzla@linux.microsoft.com>

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.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 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(-)

diff --git a/app/meson.build b/app/meson.build
index 21b6da2..f4ed0f1 100644
--- a/app/meson.build
+++ b/app/meson.build
@@ -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,
diff --git a/config/meson.build b/config/meson.build
index 8c8b019..e949240 100644
--- a/config/meson.build
+++ b/config/meson.build
@@ -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
diff --git a/drivers/meson.build b/drivers/meson.build
index 66931d4..751a295 100644
--- a/drivers/meson.build
+++ b/drivers/meson.build
@@ -208,6 +208,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
         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 +250,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,48 +274,41 @@ 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]
-
-                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()]
             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,
+                    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)
+
+        else
+            shared_dep = {}
+        endif
         static_dep = declare_dependency(
                 include_directories: includes,
                 dependencies: static_deps)
diff --git a/drivers/net/octeontx/base/meson.build b/drivers/net/octeontx/base/meson.build
index 8e5e8c1..a793c19 100644
--- a/drivers/net/octeontx/base/meson.build
+++ b/drivers/net/octeontx/base/meson.build
@@ -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)
diff --git a/examples/meson.build b/examples/meson.build
index 8e8968a..e08a169 100644
--- a/examples/meson.build
+++ b/examples/meson.build
@@ -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
diff --git a/lib/meson.build b/lib/meson.build
index 179a272..3b0f632 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -235,6 +235,10 @@ foreach l:libraries
         cflags += '-Wthread-safety'
     endif
 
+    if is_windows and is_shared_enabled
+        cflags += '-DRTE_BUILD_SHARED_LIB'
+    endif
+
     # first build static lib
     static_lib = static_library(libname,
             sources,
@@ -242,11 +246,13 @@ foreach l:libraries
             c_args: cflags,
             dependencies: static_deps,
             include_directories: includes,
-            install: true)
+            install: install_static)
     static_dep = declare_dependency(
             include_directories: includes,
             dependencies: static_deps)
 
+    dpdk_static_libraries = [static_lib] + dpdk_static_libraries
+
     if not use_function_versioning or is_windows
         # use pre-build objects to build shared lib
         sources = []
@@ -260,33 +266,14 @@ foreach l:libraries
     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_shared_enabled
         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
-        if is_windows
-            mingw_map = custom_target(libname + '_mingw',
+            def_file = custom_target(libname + '_def',
                     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()]
+                    output: '@0@_exports.def'.format(libname))
+            lk_deps += [def_file]
+            lk_args = ['/experimental:tlsDllInterface', '/def:' + def_file.full_path()]
         else
             lk_args = ['-Wl,--version-script=' + version_map]
         endif
@@ -304,23 +291,26 @@ foreach l:libraries
                 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)
+    if is_shared_enabled
+        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: install_shared)
+        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
+    else
+        shared_dep = {}
+    endif
 
     set_variable('shared_rte_' + name, shared_dep)
     set_variable('static_rte_' + name, static_dep)
-- 
1.8.3.1


  reply	other threads:[~2024-04-12 22:52 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-14 19:44 [PATCH] build and install " Tyler Retzlaff
2024-03-14 19:44 ` [PATCH] build: build " Tyler Retzlaff
2024-03-15  6:30 ` [PATCH v2 0/2] build and install " Tyler Retzlaff
2024-03-15  6:30   ` [PATCH v2 1/2] build: build " Tyler Retzlaff
2024-04-12 13:00     ` Bruce Richardson
2024-04-12 23:04       ` Tyler Retzlaff
2024-04-15  9:42         ` Bruce Richardson
2024-03-15  6:30   ` [PATCH v2 2/2] buildtools: when building static library use static deps Tyler Retzlaff
2024-03-15  8:28     ` Bruce Richardson
2024-04-04 18:47       ` Tyler Retzlaff
2024-04-05  9:11         ` Bruce Richardson
2024-04-12 14:09     ` Bruce Richardson
2024-04-12 22:52       ` Tyler Retzlaff
2024-04-12 22:52 ` [PATCH v3 0/2] build and install only one library type on Windows Tyler Retzlaff
2024-04-12 22:52   ` Tyler Retzlaff [this message]
2024-04-15  9:55     ` [PATCH v3 1/2] build: build " Bruce Richardson
2024-04-12 22:52   ` [PATCH v3 2/2] buildtools: when building static library use static deps Tyler Retzlaff
2024-04-15  9:56     ` Bruce Richardson
2024-04-15 16:45 ` [PATCH v4 0/2] build and install only one library type on Windows Tyler Retzlaff
2024-04-15 16:45   ` [PATCH v4 1/2] build: build " Tyler Retzlaff
2024-04-15 16:45   ` [PATCH v4 2/2] buildtools: when building static library use static deps Tyler Retzlaff
2024-04-15 17:12 ` [PATCH v5 0/2] build and install only one library type on Windows Tyler Retzlaff
2024-04-15 17:12   ` [PATCH v5 1/2] build: build " Tyler Retzlaff
2024-04-15 17:24     ` Bruce Richardson
2024-04-15 17:12   ` [PATCH v5 2/2] buildtools: when building static library use static deps Tyler Retzlaff

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=1712962333-14355-2-git-send-email-roretzla@linux.microsoft.com \
    --to=roretzla@linux.microsoft.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=hkalra@marvell.com \
    /path/to/YOUR_REPLY

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

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