xref: /dpdk/doc/guides/windows_gsg/build_dpdk.rst (revision 3da59f30a23f2e795d2315f3d949e1b3e0ce0c3d)
1..  SPDX-License-Identifier: BSD-3-Clause
2    Copyright(c) 2019 Intel Corporation.
3
4Compiling the DPDK Target from Source
5=====================================
6
7System Requirements
8-------------------
9
10Building the DPDK and its applications requires one of the following
11environments:
12
13* LLVM 14.0.0 (or later) and Microsoft MSVC linker.
14* The MinGW-w64 toolchain (either native or cross).
15* Microsoft Visual Studio 2022 (any edition).
16
17  - note Microsoft Visual Studio 2022 does not currently build enough
18    of DPDK to produce a working DPDK application
19    but may be used to validate that changes are portable between toolchains.
20
21The Meson Build system is used to prepare the sources for compilation
22with the Ninja backend.
23The installation of these tools is covered in this section.
24
25
26Option 1. Clang-LLVM C Compiler and Microsoft MSVC Linker
27---------------------------------------------------------
28
29Install the Compiler
30~~~~~~~~~~~~~~~~~~~~
31
32Download and install the clang compiler from
33`LLVM website <http://releases.llvm.org/download.html>`_.
34For example, Clang-LLVM direct download link::
35
36	http://releases.llvm.org/7.0.1/LLVM-7.0.1-win64.exe
37
38
39Install the Linker
40~~~~~~~~~~~~~~~~~~
41
42Download and install the Build Tools for Visual Studio to link and build the
43files on windows,
44from `Microsoft website <https://visualstudio.microsoft.com/downloads>`_.
45When installing build tools, select the "Visual C++ build tools" option
46and ensure the Windows SDK is selected.
47
48
49Option 2. MinGW-w64 Toolchain
50-----------------------------
51
52On Linux, i.e. for cross-compilation, install MinGW-w64 via a package manager.
53Version 4.0.4 for Ubuntu 16.04 cannot be used due to a
54`MinGW-w64 bug <https://sourceforge.net/p/mingw-w64/bugs/562/>`_.
55
56On Windows, obtain the latest version installer from
57`MinGW-w64 repository <https://sourceforge.net/projects/mingw-w64/files/>`_.
58Any thread model (POSIX or Win32) can be chosen, DPDK does not rely on it.
59Install to a folder without spaces in its name, like ``C:\MinGW``.
60This path is assumed for the rest of this guide.
61
62
63Option 3. Microsoft Visual Studio Toolset (MSVC)
64------------------------------------------------
65
66Install any edition of Microsoft Visual Studio 2022
67from the `Visual Studio website <https://visualstudio.microsoft.com/downloads/>`_.
68
69
70Install the Build System
71------------------------
72
73Download and install the build system from
74`Meson website <http://mesonbuild.com/Getting-meson.html>`_.
75A good option to choose is the MSI installer for both meson and ninja together::
76
77	http://mesonbuild.com/Getting-meson.html#installing-meson-and-ninja-with-the-msi-installer%22
78
79Required version is Meson 0.57.
80
81Versions starting from 0.58 are unusable with LLVM toolchain
82because of a `Meson issue <https://github.com/mesonbuild/meson/issues/8981>`_.
83
84
85Install the Backend
86-------------------
87
88If using Ninja, download and install the backend from
89`Ninja website <https://ninja-build.org/>`_ or
90install along with the meson build system.
91
92Build the code
93--------------
94
95The build environment is setup to build the EAL and the helloworld example by
96default.
97
98Option 1. Native Build on Windows using LLVM
99~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100
101When using Clang-LLVM, specifying the compiler might be required to complete
102the meson command:
103
104.. code-block:: console
105
106    set CC=clang
107
108When using MinGW-w64, it is sufficient to have toolchain executables in PATH:
109
110.. code-block:: console
111
112    set PATH=C:\MinGW\mingw64\bin;%PATH%
113
114To compile the examples, the flag ``-Dexamples`` is required.
115
116.. code-block:: console
117
118    cd C:\Users\me\dpdk
119    meson setup -Dexamples=helloworld build
120    meson compile -C build
121
122Option 2. Cross-Compile with MinGW-w64
123~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
124
125The cross-file option must be specified for Meson.
126Depending on the distribution, paths in this file may need adjustments.
127
128.. code-block:: console
129
130    meson setup --cross-file config/x86/cross-mingw -Dexamples=helloworld build
131    ninja -C build
132
133Option 3. Native Build on Windows using MSVC
134~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135
136Open a 'Developer PowerShell for VS 2022' prompt from the start menu.
137The developer prompt will configure the environment
138to select the appropriate compiler, linker and SDK paths
139required to build with Visual Studio 2022.
140
141.. code-block:: console
142
143   cd C:\Users\me\dpdk
144   meson setup -Denable_stdatomic=true build
145   meson compile -C build
146