DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v2 0/7] MinGW-w64 support
@ 2020-02-06  6:44 Dmitry Kozlyuk
  2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 1/7] eal: introduce portable format attribute Dmitry Kozlyuk
                   ` (7 more replies)
  0 siblings, 8 replies; 12+ messages in thread
From: Dmitry Kozlyuk @ 2020-02-06  6:44 UTC (permalink / raw)
  To: dev
  Cc: Dmitry Kozlyuk, Bruce Richardson, Thomas Monjalon, Olivier Matz,
	Harini Ramakrishnan, Omar Cardona, Pallavi Kadam, Ranjit Menon,
	John McNamara, Marko Kovacevic

This patch series add support for building DPDK using MinGW-w64.

MinGW-w64 provides GNU toolchain and independent platform SDK on
Windows. It also supports cross-compilation to Windows from POSIX
systems by providing cross tollchains and libraries [0]. It does NOT
emulate a full POSIX environment, like Cygwin or MSYS do.

There are advantages in using MinGW-w64 in addition to Clang:

1. Cross-compilation out-of-the-box. MinGW-w64 is provides a pthread
   implementation, GNU getopt, and Windows platform SDK.

2. Easier porting of POSIX applications using DPDK to Windows, because
   application code can use the same benefits as mentioned above.

3. Having both primary compilers enabled on Windows provides more
   diagnostics and generally prevents non-portable code.

[0]: http://mingw-w64.org

v2 Changes:

    Add patch to use lowercase system header filenames.
    Move Meson cross-file for x86 to arch directory.
    Change wording in comments.
    Add Meson version warning in documentation.

Dmitry Kozlyuk (7):
  eal: introduce portable format attribute
  eal: use portable format attribute
  cmdline: use portable format attribute
  eal/windows: use lowercase filenames for system headers
  build: MinGW-w64 support for Meson
  build: add cross-file for MinGW-w64
  doc: guide for Windows build using MinGW-w64

 config/meson.build                          | 14 +++++
 config/x86/meson_mingw.txt                  | 14 +++++
 doc/guides/windows_gsg/build_dpdk.rst       | 65 ++++++++++++++++++---
 lib/librte_cmdline/cmdline.h                |  4 +-
 lib/librte_eal/common/include/rte_common.h  | 17 +++++-
 lib/librte_eal/common/include/rte_debug.h   |  2 +-
 lib/librte_eal/common/include/rte_devargs.h |  2 +-
 lib/librte_eal/common/include/rte_log.h     |  4 +-
 lib/librte_eal/meson.build                  |  3 +
 lib/librte_eal/windows/eal/include/rte_os.h |  4 +-
 lib/meson.build                             |  8 ++-
 11 files changed, 118 insertions(+), 19 deletions(-)
 create mode 100644 config/x86/meson_mingw.txt

-- 
2.25.0


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

* [dpdk-dev] [PATCH v2 1/7] eal: introduce portable format attribute
  2020-02-06  6:44 [dpdk-dev] [PATCH v2 0/7] MinGW-w64 support Dmitry Kozlyuk
@ 2020-02-06  6:44 ` Dmitry Kozlyuk
  2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 2/7] eal: use " Dmitry Kozlyuk
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Dmitry Kozlyuk @ 2020-02-06  6:44 UTC (permalink / raw)
  To: dev; +Cc: Dmitry Kozlyuk

When using __attribute__((format(...)) on functions, GCC on Windows
assumes MS-specific format string by default, even if the underlying
stdio implementation is ANSI-compliant (either MS Unicersal CRT
or MinGW implementation). Wrap attribute into a macro that forces
GNU-specific format string when using GCC.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_eal/common/include/rte_common.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index 4b5f3a31f..2f086bb9c 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -89,6 +89,21 @@ typedef uint16_t unaligned_uint16_t;
  */
 #define RTE_SET_USED(x) (void)(x)
 
+/**
+ * Check format string and its arguments at compile-time.
+ *
+ * GCC on Windows assumes MS-specific format string by default,
+ * even if the underlying stdio implementation is ANSI-compliant,
+ * so this must be overridden.
+ */
+#if defined(RTE_TOOLCHAIN_GCC)
+#define __rte_format(archetype, format_index, first_arg) \
+	__attribute__((format(gnu_##archetype, format_index, first_arg)))
+#else
+#define __rte_format(archetype, format_index, first_arg) \
+	__attribute__((format(archetype, format_index, first_arg)))
+#endif
+
 #define RTE_PRIORITY_LOG 101
 #define RTE_PRIORITY_BUS 110
 #define RTE_PRIORITY_CLASS 120
-- 
2.25.0


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

* [dpdk-dev] [PATCH v2 2/7] eal: use portable format attribute
  2020-02-06  6:44 [dpdk-dev] [PATCH v2 0/7] MinGW-w64 support Dmitry Kozlyuk
  2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 1/7] eal: introduce portable format attribute Dmitry Kozlyuk
@ 2020-02-06  6:44 ` Dmitry Kozlyuk
  2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 3/7] cmdline: " Dmitry Kozlyuk
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Dmitry Kozlyuk @ 2020-02-06  6:44 UTC (permalink / raw)
  To: dev; +Cc: Dmitry Kozlyuk

Use portable format attribute for logging and panic messages.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_eal/common/include/rte_common.h  | 2 +-
 lib/librte_eal/common/include/rte_debug.h   | 2 +-
 lib/librte_eal/common/include/rte_devargs.h | 2 +-
 lib/librte_eal/common/include/rte_log.h     | 4 ++--
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index 2f086bb9c..dc406ce27 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -799,7 +799,7 @@ rte_str_to_size(const char *str)
 void
 rte_exit(int exit_code, const char *format, ...)
 	__attribute__((noreturn))
-	__attribute__((format(printf, 2, 3)));
+	__rte_format(printf, 2, 3);
 
 #ifdef __cplusplus
 }
diff --git a/lib/librte_eal/common/include/rte_debug.h b/lib/librte_eal/common/include/rte_debug.h
index 748d32c80..c47c6bcdc 100644
--- a/lib/librte_eal/common/include/rte_debug.h
+++ b/lib/librte_eal/common/include/rte_debug.h
@@ -73,7 +73,7 @@ void __rte_panic(const char *funcname , const char *format, ...)
 #endif
 #endif
 	__attribute__((noreturn))
-	__attribute__((format(printf, 2, 3)));
+	__rte_format(printf, 2, 3);
 
 #ifdef __cplusplus
 }
diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h
index 882dfa0ab..4418e02f2 100644
--- a/lib/librte_eal/common/include/rte_devargs.h
+++ b/lib/librte_eal/common/include/rte_devargs.h
@@ -137,7 +137,7 @@ rte_devargs_parse(struct rte_devargs *da, const char *dev);
 int
 rte_devargs_parsef(struct rte_devargs *da,
 		   const char *format, ...)
-__attribute__((format(printf, 2, 0)));
+__rte_format(printf, 2, 0);
 
 /**
  * Insert an rte_devargs in the global list.
diff --git a/lib/librte_eal/common/include/rte_log.h b/lib/librte_eal/common/include/rte_log.h
index 1bb0e6694..823efea4e 100644
--- a/lib/librte_eal/common/include/rte_log.h
+++ b/lib/librte_eal/common/include/rte_log.h
@@ -282,7 +282,7 @@ int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
 	__attribute__((cold))
 #endif
 #endif
-	__attribute__((format(printf, 3, 4)));
+	__rte_format(printf, 3, 4);
 
 /**
  * Generates a log message.
@@ -311,7 +311,7 @@ int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
  *   - Negative on error.
  */
 int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
-	__attribute__((format(printf,3,0)));
+	__rte_format(printf, 3, 0);
 
 /**
  * Generates a log message.
-- 
2.25.0


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

* [dpdk-dev] [PATCH v2 3/7] cmdline: use portable format attribute
  2020-02-06  6:44 [dpdk-dev] [PATCH v2 0/7] MinGW-w64 support Dmitry Kozlyuk
  2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 1/7] eal: introduce portable format attribute Dmitry Kozlyuk
  2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 2/7] eal: use " Dmitry Kozlyuk
@ 2020-02-06  6:44 ` Dmitry Kozlyuk
  2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 4/7] eal/windows: use lowercase filenames for system headers Dmitry Kozlyuk
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Dmitry Kozlyuk @ 2020-02-06  6:44 UTC (permalink / raw)
  To: dev; +Cc: Dmitry Kozlyuk, Olivier Matz

Use portable format attribute for output strings.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_cmdline/cmdline.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/librte_cmdline/cmdline.h b/lib/librte_cmdline/cmdline.h
index 27d2effdf..952a50829 100644
--- a/lib/librte_cmdline/cmdline.h
+++ b/lib/librte_cmdline/cmdline.h
@@ -7,6 +7,8 @@
 #ifndef _CMDLINE_H_
 #define _CMDLINE_H_
 
+#include <rte_common.h>
+
 #include <termios.h>
 #include <cmdline_rdline.h>
 #include <cmdline_parse.h>
@@ -34,7 +36,7 @@ struct cmdline *cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_
 void cmdline_set_prompt(struct cmdline *cl, const char *prompt);
 void cmdline_free(struct cmdline *cl);
 void cmdline_printf(const struct cmdline *cl, const char *fmt, ...)
-	__attribute__((format(printf,2,3)));
+	__rte_format(printf, 2, 3);
 int cmdline_in(struct cmdline *cl, const char *buf, int size);
 int cmdline_write_char(struct rdline *rdl, char c);
 
-- 
2.25.0


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

* [dpdk-dev] [PATCH v2 4/7] eal/windows: use lowercase filenames for system headers
  2020-02-06  6:44 [dpdk-dev] [PATCH v2 0/7] MinGW-w64 support Dmitry Kozlyuk
                   ` (2 preceding siblings ...)
  2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 3/7] cmdline: " Dmitry Kozlyuk
@ 2020-02-06  6:44 ` Dmitry Kozlyuk
  2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 5/7] build: MinGW-w64 support for Meson Dmitry Kozlyuk
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Dmitry Kozlyuk @ 2020-02-06  6:44 UTC (permalink / raw)
  To: dev
  Cc: Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Harini Ramakrishnan,
	Omar Cardona, Pallavi Kadam, Ranjit Menon

Mixed case in Windows header names causes errors when cross-compiling
from Linux with case-sensitive filesystem using MinGW, because MinGW
distribution provides all platform SDK headers in lowercase. The change
does not affect Windows native builds on case-insensitive filesystems
(NTFS default).

Reported-by: Narcisa Ana Maria Vasile <Narcisa.Vasile@microsoft.com>
Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_eal/windows/eal/include/rte_os.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/librte_eal/windows/eal/include/rte_os.h b/lib/librte_eal/windows/eal/include/rte_os.h
index fdeae0c8f..79d41f6a9 100644
--- a/lib/librte_eal/windows/eal/include/rte_os.h
+++ b/lib/librte_eal/windows/eal/include/rte_os.h
@@ -15,8 +15,8 @@
 extern "C" {
 #endif
 
-#include <Windows.h>
-#include <BaseTsd.h>
+#include <windows.h>
+#include <basetsd.h>
 #include <pthread.h>
 
 #define strerror_r(a, b, c) strerror_s(b, c, a)
-- 
2.25.0


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

* [dpdk-dev] [PATCH v2 5/7] build: MinGW-w64 support for Meson
  2020-02-06  6:44 [dpdk-dev] [PATCH v2 0/7] MinGW-w64 support Dmitry Kozlyuk
                   ` (3 preceding siblings ...)
  2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 4/7] eal/windows: use lowercase filenames for system headers Dmitry Kozlyuk
@ 2020-02-06  6:44 ` Dmitry Kozlyuk
  2020-02-06 11:38   ` Bruce Richardson
  2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 6/7] build: add cross-file for MinGW-w64 Dmitry Kozlyuk
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 12+ messages in thread
From: Dmitry Kozlyuk @ 2020-02-06  6:44 UTC (permalink / raw)
  To: dev; +Cc: Dmitry Kozlyuk, Bruce Richardson, Thomas Monjalon

MinGW-w64 linker does not mimic MS linker options, so the build system
must differentiate between linkers on Windows. Use GNU linker options
with GCC and MS linker options with Clang.

MinGW-w64 by default uses MSVCRT stdio, which does not comply to ANSI,
most notably its formatting and string handling functions. MinGW-w64
support for the Universal CRT (UCRT) is ongoing, but the toolchain
provides its own standard-complying implementation of stdio. The latter
is used in the patch to support formatting in DPDK.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 config/meson.build         | 14 ++++++++++++++
 lib/librte_eal/meson.build |  3 +++
 lib/meson.build            |  8 ++++++--
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/config/meson.build b/config/meson.build
index 28a57f56f..9b955f9ef 100644
--- a/config/meson.build
+++ b/config/meson.build
@@ -14,6 +14,10 @@ foreach env:supported_exec_envs
 	set_variable('is_' + env, exec_env == env)
 endforeach
 
+# MS linker requires special treatment.
+# FIXME: use cc.get_linker_id() with Meson >= 0.54
+is_ms_linker = is_windows and (cc.get_id() == 'clang')
+
 # set the major version, which might be used by drivers and libraries
 # depending on the configuration options
 pver = meson.project_version().split('.')
@@ -241,6 +245,16 @@ if is_freebsd
 	add_project_arguments('-D__BSD_VISIBLE', language: 'c')
 endif
 
+if is_windows
+	# Minimum supported API is Windows 7.
+	add_project_arguments('-D_WIN32_WINNT=0x0601', language: 'c')
+
+	# Use MinGW-w64 stdio, because DPDK assumes ANSI-compliant formatting.
+	if cc.get_id() == 'gcc'
+		add_project_arguments('-D__USE_MINGW_ANSI_STDIO', language: 'c')
+	endif
+endif
+
 if get_option('b_lto')
 	if cc.has_argument('-ffat-lto-objects')
 		add_project_arguments('-ffat-lto-objects', language: 'c')
diff --git a/lib/librte_eal/meson.build b/lib/librte_eal/meson.build
index 4be5118ce..eae8c2ba8 100644
--- a/lib/librte_eal/meson.build
+++ b/lib/librte_eal/meson.build
@@ -20,6 +20,9 @@ endif
 if cc.has_function('getentropy', prefix : '#include <unistd.h>')
 	cflags += '-DRTE_LIBEAL_USE_GETENTROPY'
 endif
+if cc.get_id() == 'gcc'
+	cflags += '-D__USE_MINGW_ANSI_STDIO'
+endif
 sources = common_sources + env_sources
 objs = common_objs + env_objs
 headers = common_headers + env_headers
diff --git a/lib/meson.build b/lib/meson.build
index 0af3efab2..9c3cc55d5 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -148,12 +148,16 @@ foreach l:libraries
 				command: [map_to_def_cmd, '@INPUT@', '@OUTPUT@'],
 				input: version_map,
 				output: 'rte_@0@_exports.def'.format(name))
-			lk_deps = [version_map, def_file]
-			if is_windows
+
+			if is_ms_linker
 				lk_args = ['-Wl,/def:' + def_file.full_path(),
 					'-Wl,/implib:lib\\' + implib]
 			else
 				lk_args = ['-Wl,--version-script=' + version_map]
+			endif
+
+			lk_deps = [version_map, def_file]
+			if not is_windows
 				# on unix systems check the output of the
 				# experimental syms script, using it as a
 				# dependency of the .so build
-- 
2.25.0


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

* [dpdk-dev] [PATCH v2 6/7] build: add cross-file for MinGW-w64
  2020-02-06  6:44 [dpdk-dev] [PATCH v2 0/7] MinGW-w64 support Dmitry Kozlyuk
                   ` (4 preceding siblings ...)
  2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 5/7] build: MinGW-w64 support for Meson Dmitry Kozlyuk
@ 2020-02-06  6:44 ` Dmitry Kozlyuk
  2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 7/7] doc: guide for Windows build using MinGW-w64 Dmitry Kozlyuk
  2020-02-06 20:22 ` [dpdk-dev] [PATCH v2 0/7] MinGW-w64 support William Tu
  7 siblings, 0 replies; 12+ messages in thread
From: Dmitry Kozlyuk @ 2020-02-06  6:44 UTC (permalink / raw)
  To: dev; +Cc: Dmitry Kozlyuk, Bruce Richardson, Thomas Monjalon

Add Meson configuration to cross-compile for Windows using MinGW-w64.
It may require adjustments in some cases, but at least it provides
the foundation.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 config/x86/meson_mingw.txt | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
 create mode 100644 config/x86/meson_mingw.txt

diff --git a/config/x86/meson_mingw.txt b/config/x86/meson_mingw.txt
new file mode 100644
index 000000000..80f04343a
--- /dev/null
+++ b/config/x86/meson_mingw.txt
@@ -0,0 +1,14 @@
+[binaries]
+c = '/usr/bin/x86_64-w64-mingw32-gcc'
+cpp = '/usr/bin/x86_64-w64-mingw32-g++'
+ld = '/usr/bin/x86_64-w64-mingw32-ld' # Meson 0.53.0
+c_ld = '/usr/bin/x86_64-w64-mingw32-ld'
+ar = '/usr/bin/x86_64-w64-mingw32-ar'
+strip = '/usr/bin/x86_64-w64-mingw32-strip'
+pkgconfig = '/usr/bin/x86_64-w64-mingw32-pkg-config'
+
+[host_machine]
+system = 'windows'
+cpu_family = 'x86_64'
+cpu = 'native'
+endian = 'little'
-- 
2.25.0


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

* [dpdk-dev] [PATCH v2 7/7] doc: guide for Windows build using MinGW-w64
  2020-02-06  6:44 [dpdk-dev] [PATCH v2 0/7] MinGW-w64 support Dmitry Kozlyuk
                   ` (5 preceding siblings ...)
  2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 6/7] build: add cross-file for MinGW-w64 Dmitry Kozlyuk
@ 2020-02-06  6:44 ` Dmitry Kozlyuk
  2020-02-06 20:22 ` [dpdk-dev] [PATCH v2 0/7] MinGW-w64 support William Tu
  7 siblings, 0 replies; 12+ messages in thread
From: Dmitry Kozlyuk @ 2020-02-06  6:44 UTC (permalink / raw)
  To: dev
  Cc: Dmitry Kozlyuk, Harini Ramakrishnan, Omar Cardona, Pallavi Kadam,
	Ranjit Menon, John McNamara, Marko Kovacevic

Instructions for different toolchains presented as options on the
corresponging steps of the guide, so that common parts may be reused.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 doc/guides/windows_gsg/build_dpdk.rst | 65 +++++++++++++++++++++++----
 1 file changed, 56 insertions(+), 9 deletions(-)

diff --git a/doc/guides/windows_gsg/build_dpdk.rst b/doc/guides/windows_gsg/build_dpdk.rst
index 6711e07e2..6d093d235 100644
--- a/doc/guides/windows_gsg/build_dpdk.rst
+++ b/doc/guides/windows_gsg/build_dpdk.rst
@@ -7,15 +7,22 @@ Compiling the DPDK Target from Source
 System Requirements
 -------------------
 
-The DPDK and its applications require the Clang-LLVM C compiler
-and Microsoft MSVC linker.
+Building the DPDK and its applications requires one of the following
+environments:
+
+* The Clang-LLVM C compiler and Microsoft MSVC linker.
+* The MinGW-w64 toolchain (either native or cross).
+
 The Meson Build system is used to prepare the sources for compilation
 with the Ninja backend.
 The installation of these tools is covered in this section.
 
 
+Option 1. Clang-LLVM C Compiler and Microsoft MSVC Linker
+---------------------------------------------------------
+
 Install the Compiler
---------------------
+~~~~~~~~~~~~~~~~~~~~
 
 Download and install the clang compiler from
 `LLVM website <http://releases.llvm.org/download.html>`_.
@@ -25,7 +32,7 @@ For example, Clang-LLVM direct download link::
 
 
 Install the Linker
-------------------
+~~~~~~~~~~~~~~~~~~
 
 Download and install the Build Tools for Visual Studio to link and build the
 files on windows,
@@ -34,6 +41,15 @@ When installing build tools, select the "Visual C++ build tools" option
 and ensure the Windows SDK is selected.
 
 
+Option 2. MinGW-w64 Toolchain
+-----------------------------
+
+Obtain the latest version from
+`MinGW-w64 website <http://mingw-w64.org/doku.php/download>`_.
+On Windows, install to a folder without spaces in its name, like ``C:\MinGW``.
+This path is assumed for the rest of this guide.
+
+
 Install the Build System
 ------------------------
 
@@ -43,6 +59,14 @@ A good option to choose is the MSI installer for both meson and ninja together::
 
 	http://mesonbuild.com/Getting-meson.html#installing-meson-and-ninja-with-the-msi-installer%22
 
+.. warning::
+
+    Meson 0.53 has `issue #6431 <https://github.com/mesonbuild/meson/issues/6431>`_
+    that prevents cross-compilation and another linker issue with Clang
+    (`workaround patch <https://github.com/mesonbuild/meson/pull/6483>`_).
+    Meson 0.47.1 is recommended, Meson 0.52 can also be used if new features
+    are required.
+
 Install the Backend
 -------------------
 
@@ -56,23 +80,41 @@ Build the code
 The build environment is setup to build the EAL and the helloworld example by
 default.
 
-Using the ninja backend
-~~~~~~~~~~~~~~~~~~~~~~~~
+Option 1. Native Build on Windows
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-Specifying the compiler might be required to complete the meson command.
+When using Clang-LLVM, specifying the compiler might be required to complete
+the meson command:
 
 .. code-block:: console
 
     set CC=clang
 
+When using MinGW-w64, it is sufficient to have toolchain executables in PATH:
+
+.. code-block:: console
+
+    set PATH=C:\MinGW\mingw64\bin;%PATH%
+
 To compile the examples, the flag ``-Dexamples`` is required.
 
 .. code-block:: console
 
     cd C:\Users\me\dpdk
     meson -Dexamples=helloworld build
-    cd build
-    ninja
+    ninja -C build
+
+Option 2. Cross-Compile with MinGW-w64
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The cross-file option must be specified for Meson.
+Depending on the distribution, paths in this file may need adjustments.
+
+.. code-block:: console
+
+    meson --cross-file config/x86/meson_mingw.txt -Dexamples=helloworld build
+    ninja -C build
+
 
 Run the helloworld example
 ==========================
@@ -87,3 +129,8 @@ Navigate to the examples in the build directory and run `dpdk-helloworld.exe`.
     hello from core 3
     hello from core 0
     hello from core 2
+
+Note for MinGW-w64: applications are linked to ``libwinpthread-1.dll``
+by default. To run the example, either add toolchain executables directory
+to the PATH or copy the library to the working directory.
+Alternatively, static linking may be used (mind the LGPLv2.1 license).
-- 
2.25.0


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

* Re: [dpdk-dev] [PATCH v2 5/7] build: MinGW-w64 support for Meson
  2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 5/7] build: MinGW-w64 support for Meson Dmitry Kozlyuk
@ 2020-02-06 11:38   ` Bruce Richardson
  0 siblings, 0 replies; 12+ messages in thread
From: Bruce Richardson @ 2020-02-06 11:38 UTC (permalink / raw)
  To: Dmitry Kozlyuk; +Cc: dev, Thomas Monjalon

On Thu, Feb 06, 2020 at 09:44:24AM +0300, Dmitry Kozlyuk wrote:
> MinGW-w64 linker does not mimic MS linker options, so the build system
> must differentiate between linkers on Windows. Use GNU linker options
> with GCC and MS linker options with Clang.
> 
> MinGW-w64 by default uses MSVCRT stdio, which does not comply to ANSI,
> most notably its formatting and string handling functions. MinGW-w64
> support for the Universal CRT (UCRT) is ongoing, but the toolchain
> provides its own standard-complying implementation of stdio. The latter
> is used in the patch to support formatting in DPDK.
> 
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---
>  config/meson.build         | 14 ++++++++++++++
>  lib/librte_eal/meson.build |  3 +++
>  lib/meson.build            |  8 ++++++--
>  3 files changed, 23 insertions(+), 2 deletions(-)
> 
> diff --git a/config/meson.build b/config/meson.build
> index 28a57f56f..9b955f9ef 100644
> --- a/config/meson.build
> +++ b/config/meson.build
> @@ -14,6 +14,10 @@ foreach env:supported_exec_envs
>  	set_variable('is_' + env, exec_env == env)
>  endforeach
>  
> +# MS linker requires special treatment.
> +# FIXME: use cc.get_linker_id() with Meson >= 0.54
> +is_ms_linker = is_windows and (cc.get_id() == 'clang')
> +
>  # set the major version, which might be used by drivers and libraries
>  # depending on the configuration options
>  pver = meson.project_version().split('.')
> @@ -241,6 +245,16 @@ if is_freebsd
>  	add_project_arguments('-D__BSD_VISIBLE', language: 'c')
>  endif
>  
> +if is_windows
> +	# Minimum supported API is Windows 7.
> +	add_project_arguments('-D_WIN32_WINNT=0x0601', language: 'c')
> +
> +	# Use MinGW-w64 stdio, because DPDK assumes ANSI-compliant formatting.
> +	if cc.get_id() == 'gcc'
> +		add_project_arguments('-D__USE_MINGW_ANSI_STDIO', language: 'c')
> +	endif
> +endif
> +
>  if get_option('b_lto')
>  	if cc.has_argument('-ffat-lto-objects')
>  		add_project_arguments('-ffat-lto-objects', language: 'c')
> diff --git a/lib/librte_eal/meson.build b/lib/librte_eal/meson.build
> index 4be5118ce..eae8c2ba8 100644
> --- a/lib/librte_eal/meson.build
> +++ b/lib/librte_eal/meson.build
> @@ -20,6 +20,9 @@ endif
>  if cc.has_function('getentropy', prefix : '#include <unistd.h>')
>  	cflags += '-DRTE_LIBEAL_USE_GETENTROPY'
>  endif
> +if cc.get_id() == 'gcc'
> +	cflags += '-D__USE_MINGW_ANSI_STDIO'
> +endif

Is this snippet still needed, given you add this as a project arg above?


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

* Re: [dpdk-dev] [PATCH v2 0/7] MinGW-w64 support
  2020-02-06  6:44 [dpdk-dev] [PATCH v2 0/7] MinGW-w64 support Dmitry Kozlyuk
                   ` (6 preceding siblings ...)
  2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 7/7] doc: guide for Windows build using MinGW-w64 Dmitry Kozlyuk
@ 2020-02-06 20:22 ` William Tu
  2020-02-07 10:24   ` Dmitry Kozliuk
  7 siblings, 1 reply; 12+ messages in thread
From: William Tu @ 2020-02-06 20:22 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: dev, Bruce Richardson, Thomas Monjalon, Olivier Matz,
	Harini Ramakrishnan, Omar Cardona, Pallavi Kadam, Ranjit Menon,
	John McNamara, Marko Kovacevic

On Wed, Feb 5, 2020 at 10:44 PM Dmitry Kozlyuk <dmitry.kozliuk@gmail.com> wrote:
>
> This patch series add support for building DPDK using MinGW-w64.
>
> MinGW-w64 provides GNU toolchain and independent platform SDK on
> Windows. It also supports cross-compilation to Windows from POSIX
> systems by providing cross tollchains and libraries [0]. It does NOT
> emulate a full POSIX environment, like Cygwin or MSYS do.
>
> There are advantages in using MinGW-w64 in addition to Clang:
>
> 1. Cross-compilation out-of-the-box. MinGW-w64 is provides a pthread
>    implementation, GNU getopt, and Windows platform SDK.
>
> 2. Easier porting of POSIX applications using DPDK to Windows, because
>    application code can use the same benefits as mentioned above.
>
> 3. Having both primary compilers enabled on Windows provides more
>    diagnostics and generally prevents non-portable code.
>
> [0]: http://mingw-w64.org
>
> v2 Changes:
>
>     Add patch to use lowercase system header filenames.
>     Move Meson cross-file for x86 to arch directory.
>     Change wording in comments.
>     Add Meson version warning in documentation.
>
> Dmitry Kozlyuk (7):
>   eal: introduce portable format attribute
>   eal: use portable format attribute
>   cmdline: use portable format attribute
>   eal/windows: use lowercase filenames for system headers
>   build: MinGW-w64 support for Meson
>   build: add cross-file for MinGW-w64
>   doc: guide for Windows build using MinGW-w64
>
>  config/meson.build                          | 14 +++++
>  config/x86/meson_mingw.txt                  | 14 +++++
>  doc/guides/windows_gsg/build_dpdk.rst       | 65 ++++++++++++++++++---
>  lib/librte_cmdline/cmdline.h                |  4 +-
>  lib/librte_eal/common/include/rte_common.h  | 17 +++++-
>  lib/librte_eal/common/include/rte_debug.h   |  2 +-
>  lib/librte_eal/common/include/rte_devargs.h |  2 +-
>  lib/librte_eal/common/include/rte_log.h     |  4 +-
>  lib/librte_eal/meson.build                  |  3 +
>  lib/librte_eal/windows/eal/include/rte_os.h |  4 +-
>  lib/meson.build                             |  8 ++-
>  11 files changed, 118 insertions(+), 19 deletions(-)
>  create mode 100644 config/x86/meson_mingw.txt
>
> --
> 2.25.0
>
Hi Dmitry,

I applied your v2 patch and I did a native build on windows 10.
Hit an error showing
../lib/librte_eal/windows/eal/eal_lcore.c:54:2: error: 'for' loop
initial declarations are only allowed in C99 mode
  for (unsigned int socket = 0; socket <
  ^
../lib/librte_eal/windows/eal/eal_lcore.c:54:2: note: use option
-std=c99 or -std=gnu99 to compile your code

Then I fixed them by having separate declaration out side for loop.
then
$ ninja -C build
works

However the output looks weird:
C:\dpdk\build\examples>dpdk-helloworld.exe
EAL: Detected 2 lcore(s)
EAL: Detected 1 NUMA nodes
hehello fllo frorom cm core 1
ore 0

Regards,
William

--- more detailed ---
C:\dpdk>meson -v
0.53.999

C:\dpdk>gcc -v
Reading specs from c:/mingw-w64/bin/../lib64/gcc/x86_64-w64-mingw32/4.8.3/specs
COLLECT_GCC=gcc


C:\dpdk>meson --reconfigure -Dexamples=helloworld build
The Meson build system
Version: 0.53.999
Source dir: C:\dpdk
Build dir: C:\dpdk\build
Build type: native build
Program cat found: NO
Program more found: YES (C:\WINDOWS\system32\more.COM)
Project name: DPDK
Project version: 20.02.0-rc2
C compiler for the host machine: cc (gcc 4.8.3 "cc (GCC) 4.8.3")
C linker for the host machine: cc GNU ld.bfd 2.24
Host machine cpu family: x86_64
Host machine cpu: x86_64
Program cat found: NO
Program more found: YES (C:\WINDOWS\system32\more.COM)
Program ../buildtools/symlink-drivers-solibs.sh found: YES (sh
C:\dpdk\config\../buildtools/symlink-drivers-so
libs.sh)
Checking for size of "void *" : 8
Library m found: YES
Library numa found: NO
Found pkg-config: C:\mingw-w64\bin\pkg-config.EXE (0.25)

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

* Re: [dpdk-dev] [PATCH v2 0/7] MinGW-w64 support
  2020-02-06 20:22 ` [dpdk-dev] [PATCH v2 0/7] MinGW-w64 support William Tu
@ 2020-02-07 10:24   ` Dmitry Kozliuk
  2020-02-07 17:47     ` William Tu
  0 siblings, 1 reply; 12+ messages in thread
From: Dmitry Kozliuk @ 2020-02-07 10:24 UTC (permalink / raw)
  To: William Tu
  Cc: dev, Bruce Richardson, Thomas Monjalon, Olivier Matz,
	Harini Ramakrishnan, Omar Cardona, Pallavi Kadam, Ranjit Menon,
	John McNamara, Marko Kovacevic

Hi William,

I applied your v2 patch and I did a native build on windows 10.
> Hit an error showing
> ../lib/librte_eal/windows/eal/eal_lcore.c:54:2: error: 'for' loop
> initial declarations are only allowed in C99 mode
>

Thanks, will fix in v3.

However the output looks weird:
> C:\dpdk\build\examples>dpdk-helloworld.exe
> EAL: Detected 2 lcore(s)
> EAL: Detected 1 NUMA nodes
> hehello fllo frorom cm core 1
> ore 0
>

It looks like your stdout is unbuffered (default is line-buffered). What
terminal are you using (cmd, Power Shell, Terminal App, conemu, etc)?

C compiler for the host machine: cc (gcc 4.8.3 "cc (GCC) 4.8.3")
>

GCC 4.8.3 is quite outdated, MinGW-w64 ships GCC 8 nowadays. Do we need to
support it for Windows (I doubt MinGW-w64 does)?

--
Dmitry Kozlyuk

>

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

* Re: [dpdk-dev] [PATCH v2 0/7] MinGW-w64 support
  2020-02-07 10:24   ` Dmitry Kozliuk
@ 2020-02-07 17:47     ` William Tu
  0 siblings, 0 replies; 12+ messages in thread
From: William Tu @ 2020-02-07 17:47 UTC (permalink / raw)
  To: Dmitry Kozliuk
  Cc: dev, Bruce Richardson, Thomas Monjalon, Olivier Matz,
	Harini Ramakrishnan, Omar Cardona, Pallavi Kadam, Ranjit Menon,
	John McNamara, Marko Kovacevic

Hi Dmitry,

Thanks for your reply.

On Fri, Feb 7, 2020 at 2:24 AM Dmitry Kozliuk <dmitry.kozliuk@gmail.com> wrote:
>
> Hi William,
>
>> I applied your v2 patch and I did a native build on windows 10.
>> Hit an error showing
>> ../lib/librte_eal/windows/eal/eal_lcore.c:54:2: error: 'for' loop
>> initial declarations are only allowed in C99 mode
>
>
> Thanks, will fix in v3.
>
>> However the output looks weird:
>> C:\dpdk\build\examples>dpdk-helloworld.exe
>> EAL: Detected 2 lcore(s)
>> EAL: Detected 1 NUMA nodes
>> hehello fllo frorom cm core 1
>> ore 0
>
>
> It looks like your stdout is unbuffered (default is line-buffered). What terminal are you using (cmd, Power Shell, Terminal App, conemu, etc)?
>
I'm using the "Command Prompt" from windows 10

>> C compiler for the host machine: cc (gcc 4.8.3 "cc (GCC) 4.8.3")
>
>
> GCC 4.8.3 is quite outdated, MinGW-w64 ships GCC 8 nowadays. Do we need to support it for Windows (I doubt MinGW-w64 does)?
>
Oh, I download a pretty old version (mingw-w64 3.3.0).
Let me update.

BTW, I also tested cross-compile using my Ubuntu Box and everything works!
William

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

end of thread, other threads:[~2020-02-07 17:47 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-06  6:44 [dpdk-dev] [PATCH v2 0/7] MinGW-w64 support Dmitry Kozlyuk
2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 1/7] eal: introduce portable format attribute Dmitry Kozlyuk
2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 2/7] eal: use " Dmitry Kozlyuk
2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 3/7] cmdline: " Dmitry Kozlyuk
2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 4/7] eal/windows: use lowercase filenames for system headers Dmitry Kozlyuk
2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 5/7] build: MinGW-w64 support for Meson Dmitry Kozlyuk
2020-02-06 11:38   ` Bruce Richardson
2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 6/7] build: add cross-file for MinGW-w64 Dmitry Kozlyuk
2020-02-06  6:44 ` [dpdk-dev] [PATCH v2 7/7] doc: guide for Windows build using MinGW-w64 Dmitry Kozlyuk
2020-02-06 20:22 ` [dpdk-dev] [PATCH v2 0/7] MinGW-w64 support William Tu
2020-02-07 10:24   ` Dmitry Kozliuk
2020-02-07 17:47     ` William Tu

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