build: support MinGW-w64 with Meson

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>
Tested-by: William Tu <u9012063@gmail.com>
Tested-by: Pallavi Kadam <pallavi.kadam@intel.com>
This commit is contained in:
Dmitry Kozlyuk 2020-02-27 07:25:34 +03:00 committed by Thomas Monjalon
parent f3874012c6
commit 4816484bab
3 changed files with 62 additions and 11 deletions

View File

@ -14,6 +14,10 @@ foreach env:supported_exec_envs
set_variable('is_' + env, exec_env == env)
endforeach
# MS linker requires special treatment.
# TODO: 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('.')
@ -247,6 +251,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')

View File

@ -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,18 @@ 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.
Version 4.0.4 for Ubuntu 16.04 cannot be used due to a
`MinGW-w64 bug <https://sourceforge.net/p/mingw-w64/bugs/562/>`_.
Install the Build System
------------------------
@ -43,6 +62,8 @@ 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
Recommended version is either Meson 0.47.1 (baseline) or the latest release.
Install the Backend
-------------------
@ -56,23 +77,30 @@ 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
Run the helloworld example
==========================
@ -87,3 +115,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).

View File

@ -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