xref: /dpdk/doc/guides/prog_guide/build-sdk-meson.rst (revision 909ad7b80e5ede401354f817dc802b68bb9cb4ff)
1c0a775a1SBruce Richardson..  SPDX-License-Identifier: BSD-3-Clause
2c0a775a1SBruce Richardson    Copyright(c) 2018 Intel Corporation.
3c0a775a1SBruce Richardson
4adbeba36SHari Kumar VemulaInstalling DPDK Using the meson build system
5adbeba36SHari Kumar Vemula============================================
6adbeba36SHari Kumar Vemula
7adbeba36SHari Kumar VemulaSummary
8adbeba36SHari Kumar Vemula--------
9adbeba36SHari Kumar VemulaFor many platforms, compiling and installing DPDK should work using the
10adbeba36SHari Kumar Vemulafollowing set of commands::
11adbeba36SHari Kumar Vemula
12adbeba36SHari Kumar Vemula	meson build
13adbeba36SHari Kumar Vemula	cd build
14adbeba36SHari Kumar Vemula	ninja
15adbeba36SHari Kumar Vemula	ninja install
16adbeba36SHari Kumar Vemula
17adbeba36SHari Kumar VemulaThis will compile DPDK in the ``build`` subdirectory, and then install the
18adbeba36SHari Kumar Vemularesulting libraries, drivers and header files onto the system - generally
19adbeba36SHari Kumar Vemulain /usr/local. A package-config file, ``libdpdk.pc``,  for DPDK will also
20adbeba36SHari Kumar Vemulabe installed to allow ease of compiling and linking with applications.
21adbeba36SHari Kumar Vemula
22adbeba36SHari Kumar VemulaAfter installation, to use DPDK, the necessary CFLAG and LDFLAG variables
23adbeba36SHari Kumar Vemulacan be got from pkg-config::
24adbeba36SHari Kumar Vemula
25adbeba36SHari Kumar Vemula	pkg-config --cflags libdpdk
26adbeba36SHari Kumar Vemula	pkg-config --libs libdpdk
27adbeba36SHari Kumar Vemula
28adbeba36SHari Kumar VemulaMore detail on each of these steps can be got from the following sections.
29adbeba36SHari Kumar Vemula
30adbeba36SHari Kumar Vemula
31adbeba36SHari Kumar VemulaGetting the Tools
32adbeba36SHari Kumar Vemula------------------
33adbeba36SHari Kumar Vemula
34adbeba36SHari Kumar VemulaThe ``meson`` tool is used to configure a DPDK build. On most Linux
35adbeba36SHari Kumar Vemuladistributions this can be got using the local package management system,
36adbeba36SHari Kumar Vemulae.g. ``dnf install meson`` or ``apt-get install meson``. If meson is not
37adbeba36SHari Kumar Vemulaavailable as a suitable package, it can also be installed using the Python
38*909ad7b8SBruce Richardson3 ``pip`` tool, e.g. ``pip3 install meson``. Version 0.53.2 or later of meson is
39adbeba36SHari Kumar Vemularequired - if the version packaged is too old, the latest version is
40adbeba36SHari Kumar Vemulagenerally available from "pip".
41adbeba36SHari Kumar Vemula
42adbeba36SHari Kumar VemulaThe other dependency for building is the ``ninja`` tool, which acts similar
43adbeba36SHari Kumar Vemulato make and performs the actual build using information provided by meson.
44adbeba36SHari Kumar VemulaInstalling meson will, in many cases, also install ninja, but, if not
45adbeba36SHari Kumar Vemulaalready installed, it too is generally packaged by most Linux distributions.
46adbeba36SHari Kumar VemulaIf not available as a package, it can be downloaded as source or binary from
47adbeba36SHari Kumar Vemulahttps://ninja-build.org/
48adbeba36SHari Kumar Vemula
49d1355fccSAsaf PensoIt is best advised to go over the following links for the complete dependencies:
50d1355fccSAsaf Penso
51d1355fccSAsaf Penso* :doc:`Linux <../linux_gsg/sys_reqs>`
52d1355fccSAsaf Penso* :doc:`FreeBSD <../freebsd_gsg/build_dpdk>`
53d1355fccSAsaf Penso* :doc:`Windows <../windows_gsg/build_dpdk>`
54d1355fccSAsaf Penso
55adbeba36SHari Kumar Vemula
56adbeba36SHari Kumar VemulaConfiguring the Build
57adbeba36SHari Kumar Vemula----------------------
58adbeba36SHari Kumar Vemula
59adbeba36SHari Kumar VemulaTo configure a build, run the meson tool, passing the path to the directory
60adbeba36SHari Kumar Vemulato be used for the build e.g. ``meson build``, as shown above. If calling
61adbeba36SHari Kumar Vemulameson from somewhere other than the root directory of the DPDK project the
62adbeba36SHari Kumar Vemulapath to the root directory should be passed as the first parameter, and the
63adbeba36SHari Kumar Vemulabuild path as the second. For example, to build DPDK in /tmp/dpdk-build::
64adbeba36SHari Kumar Vemula
65adbeba36SHari Kumar Vemula	user@host:/tmp$ meson ~user/dpdk dpdk-build
66adbeba36SHari Kumar Vemula
67adbeba36SHari Kumar VemulaMeson will then configure the build based on settings in the project's
68adbeba36SHari Kumar Vemulameson.build files, and by checking the build environment for e.g. compiler
69adbeba36SHari Kumar Vemulaproperties or the presence of dependencies, such as libpcap, or openssl
70adbeba36SHari Kumar Vemulalibcrypto libraries. Once done, meson writes a ``build.ninja`` file in the
71adbeba36SHari Kumar Vemulabuild directory to be used to do the build itself when ninja is called.
72adbeba36SHari Kumar Vemula
73adbeba36SHari Kumar VemulaTuning of the build is possible, both as part of the original meson call,
74adbeba36SHari Kumar Vemulaor subsequently using ``meson configure`` command (``mesonconf`` in some
75adbeba36SHari Kumar Vemulaolder versions). Some options, such as ``buildtype``, or ``werror`` are
76adbeba36SHari Kumar Vemulabuilt into meson, while others, such as ``max_lcores``, or the list of
77adbeba36SHari Kumar Vemulaexamples to build, are DPDK-specific. To have a list of all options
78adbeba36SHari Kumar Vemulaavailable run ``meson configure`` in the build directory.
79adbeba36SHari Kumar Vemula
80adbeba36SHari Kumar VemulaExamples of adjusting the defaults when doing initial meson configuration.
81adbeba36SHari Kumar VemulaProject-specific options are passed used -Doption=value::
82adbeba36SHari Kumar Vemula
83adbeba36SHari Kumar Vemula	meson --werror werrorbuild  # build with warnings as errors
84adbeba36SHari Kumar Vemula
85adbeba36SHari Kumar Vemula	meson --buildtype=debug debugbuild  # build for debugging
86adbeba36SHari Kumar Vemula
87adbeba36SHari Kumar Vemula	meson -Dexamples=l3fwd,l2fwd fwdbuild  # build some examples as
88adbeba36SHari Kumar Vemula					# part of the normal DPDK build
89adbeba36SHari Kumar Vemula
90adbeba36SHari Kumar Vemula	meson -Dmax_lcores=8 smallbuild  # scale build for smaller systems
91adbeba36SHari Kumar Vemula
92adbeba36SHari Kumar Vemula	meson -Denable_docs=true fullbuild  # build and install docs
93adbeba36SHari Kumar Vemula
949cd9c570SJuraj Linkeš	meson -Dcpu_instruction_set=generic  # use builder-independent baseline -march
95adbeba36SHari Kumar Vemula
96adbeba36SHari Kumar Vemula	meson -Ddisable_drivers=event/*,net/tap  # disable tap driver and all
97adbeba36SHari Kumar Vemula					# eventdev PMDs for a smaller build
98adbeba36SHari Kumar Vemula
9927db82c7SJerin Jacob	meson -Denable_trace_fp=true tracebuild # build with fast path traces
10027db82c7SJerin Jacob					# enabled
10127db82c7SJerin Jacob
102adbeba36SHari Kumar VemulaExamples of setting some of the same options using meson configure::
103adbeba36SHari Kumar Vemula
104adbeba36SHari Kumar Vemula	meson configure -Dwerror=true
105adbeba36SHari Kumar Vemula
106adbeba36SHari Kumar Vemula	meson configure -Dbuildtype=debug
107adbeba36SHari Kumar Vemula
108adbeba36SHari Kumar Vemula	meson configure -Dexamples=l3fwd,l2fwd
109adbeba36SHari Kumar Vemula
110adbeba36SHari Kumar Vemula	meson configure -Dmax_lcores=8
111adbeba36SHari Kumar Vemula
11227db82c7SJerin Jacob	meson configure -Denable_trace_fp=true
11327db82c7SJerin Jacob
1141509ef93SBruce Richardson.. note::
1151509ef93SBruce Richardson
1161509ef93SBruce Richardson        once meson has been run to configure a build in a directory, it
117adbeba36SHari Kumar Vemula        cannot be run again on the same directory. Instead ``meson configure``
118adbeba36SHari Kumar Vemula        should be used to change the build settings within the directory, and when
119adbeba36SHari Kumar Vemula        ``ninja`` is called to do the build itself, it will trigger the necessary
120adbeba36SHari Kumar Vemula        re-scan from meson.
121adbeba36SHari Kumar Vemula
1221509ef93SBruce Richardson.. note::
1239cd9c570SJuraj Linkeš
1249cd9c570SJuraj Linkeš   cpu_instruction_set=generic uses an instruction set that works on
1259cd9c570SJuraj Linkeš   all supported architectures regardless of the capabilities of the machine
1269cd9c570SJuraj Linkeš   where the build is happening.
1279cd9c570SJuraj Linkeš
1289cd9c570SJuraj Linkeš.. note::
1299cd9c570SJuraj Linkeš
1309cd9c570SJuraj Linkeš   cpu_instruction_set is not used in Arm builds, as setting the instruction set
1319cd9c570SJuraj Linkeš   without other parameters leads to inferior builds.
1329cd9c570SJuraj Linkeš   The way to tailor Arm builds is to build for a SoC using -Dplatform=<SoC>.
133adbeba36SHari Kumar Vemula
134adbeba36SHari Kumar VemulaAs well as those settings taken from ``meson configure``, other options
135adbeba36SHari Kumar Vemulasuch as the compiler to use can be passed via environment variables. For
136adbeba36SHari Kumar Vemulaexample::
137adbeba36SHari Kumar Vemula
138adbeba36SHari Kumar Vemula	CC=clang meson clang-build
139adbeba36SHari Kumar Vemula
1401509ef93SBruce Richardson.. note::
1411509ef93SBruce Richardson
1421509ef93SBruce Richardson        for more comprehensive overriding of compilers or other environment
143adbeba36SHari Kumar Vemula        settings, the tools for cross-compilation may be considered. However, for
144adbeba36SHari Kumar Vemula        basic overriding of the compiler etc., the above form works as expected.
145adbeba36SHari Kumar Vemula
146adbeba36SHari Kumar Vemula
147adbeba36SHari Kumar VemulaPerforming the Build
148adbeba36SHari Kumar Vemula---------------------
149adbeba36SHari Kumar Vemula
150adbeba36SHari Kumar VemulaUse ``ninja`` to perform the actual build inside the build folder
151adbeba36SHari Kumar Vemulapreviously configured. In most cases no arguments are necessary.
152adbeba36SHari Kumar Vemula
153adbeba36SHari Kumar VemulaNinja accepts a number of flags which are similar to make. For example, to
154adbeba36SHari Kumar Vemulacall ninja from outside the build folder, you can use ``ninja -C build``.
155adbeba36SHari Kumar VemulaNinja also runs parallel builds by default, but you can limit this using
156adbeba36SHari Kumar Vemulathe ``-j`` flag, e.g. ``ninja -j1 -v`` to do the build one step at a time,
157adbeba36SHari Kumar Vemulaprinting each command on a new line as it runs.
158adbeba36SHari Kumar Vemula
159adbeba36SHari Kumar Vemula
160adbeba36SHari Kumar VemulaInstalling the Compiled Files
161adbeba36SHari Kumar Vemula------------------------------
162adbeba36SHari Kumar Vemula
163adbeba36SHari Kumar VemulaUse ``ninja install`` to install the required DPDK files onto the system.
164adbeba36SHari Kumar VemulaThe install prefix defaults to ``/usr/local`` but can be used as with other
165adbeba36SHari Kumar Vemulaoptions above. The environment variable ``DESTDIR`` can be used to adjust
166adbeba36SHari Kumar Vemulathe root directory for the install, for example when packaging.
167adbeba36SHari Kumar Vemula
168adbeba36SHari Kumar VemulaWith the base install directory, the individual directories for libraries
169adbeba36SHari Kumar Vemulaand headers are configurable. By default, the following will be the
170adbeba36SHari Kumar Vemulainstalled layout::
171adbeba36SHari Kumar Vemula
172adbeba36SHari Kumar Vemula	headers -> /usr/local/include
173adbeba36SHari Kumar Vemula	libraries -> /usr/local/lib64
174adbeba36SHari Kumar Vemula	drivers -> /usr/local/lib64/dpdk/drivers
175adbeba36SHari Kumar Vemula	libdpdk.pc -> /usr/local/lib64/pkgconfig
176adbeba36SHari Kumar Vemula
177adbeba36SHari Kumar VemulaFor the drivers, these will also be symbolically linked into the library
178adbeba36SHari Kumar Vemulainstall directory, so that ld.so can find them in cases where one driver may
179adbeba36SHari Kumar Vemuladepend on another, e.g. a NIC PMD depending upon the PCI bus driver. Within
180adbeba36SHari Kumar Vemulathe EAL, the default search path for drivers will be set to the configured
181adbeba36SHari Kumar Vemuladriver install path, so dynamically-linked applications can be run without
182adbeba36SHari Kumar Vemulahaving to pass in ``-d /path/to/driver`` options for standard drivers.
183adbeba36SHari Kumar Vemula
184adbeba36SHari Kumar Vemula
185adbeba36SHari Kumar VemulaCross Compiling DPDK
186adbeba36SHari Kumar Vemula--------------------
187adbeba36SHari Kumar Vemula
188adbeba36SHari Kumar VemulaTo cross-compile DPDK on a desired target machine we can use the following
189adbeba36SHari Kumar Vemulacommand::
190adbeba36SHari Kumar Vemula
191adbeba36SHari Kumar Vemula	meson cross-build --cross-file <target_machine_configuration>
192adbeba36SHari Kumar Vemula
193adbeba36SHari Kumar VemulaFor example if the target machine is arm64 we can use the following
194adbeba36SHari Kumar Vemulacommand::
195adbeba36SHari Kumar Vemula
196adbeba36SHari Kumar Vemula        meson arm-build --cross-file config/arm/arm64_armv8_linux_gcc
197adbeba36SHari Kumar Vemula
198adbeba36SHari Kumar Vemulawhere config/arm/arm64_armv8_linux_gcc contains settings for the compilers
199adbeba36SHari Kumar Vemulaand other build tools to be used, as well as characteristics of the target
200adbeba36SHari Kumar Vemulamachine.
201adbeba36SHari Kumar Vemula
202adbeba36SHari Kumar VemulaUsing the DPDK within an Application
203adbeba36SHari Kumar Vemula-------------------------------------
204adbeba36SHari Kumar Vemula
205adbeba36SHari Kumar VemulaTo compile and link against DPDK within an application, pkg-config should
206adbeba36SHari Kumar Vemulabe used to query the correct parameters. Examples of this are given in the
207adbeba36SHari Kumar Vemulamakefiles for the example applications included with DPDK. They demonstrate
208adbeba36SHari Kumar Vemulahow to link either against the DPDK shared libraries, or against the static
209adbeba36SHari Kumar Vemulaversions of the same.
210adbeba36SHari Kumar Vemula
211adbeba36SHari Kumar VemulaFrom examples/helloworld/Makefile::
212adbeba36SHari Kumar Vemula
213adbeba36SHari Kumar Vemula	PC_FILE := $(shell pkg-config --path libdpdk)
214adbeba36SHari Kumar Vemula	CFLAGS += -O3 $(shell pkg-config --cflags libdpdk)
215adbeba36SHari Kumar Vemula	LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk)
2168549295dSBruce Richardson	LDFLAGS_STATIC = $(shell pkg-config --static --libs libdpdk)
217adbeba36SHari Kumar Vemula
218adbeba36SHari Kumar Vemula	build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build
219adbeba36SHari Kumar Vemula		$(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
220adbeba36SHari Kumar Vemula
221adbeba36SHari Kumar Vemula	build/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build
222adbeba36SHari Kumar Vemula		$(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_STATIC)
223adbeba36SHari Kumar Vemula
224adbeba36SHari Kumar Vemula	build:
225adbeba36SHari Kumar Vemula		@mkdir -p $@
226