| 1 | |
| 2 | .. _setup-build-env: |
| 3 | |
| 4 | Setup build environment |
| 5 | ======================= |
| 6 | |
| 7 | QEMU uses a lot of dependencies on the host system a large number of |
| 8 | which are optional. At a minimum we expect to have a system C library |
| 9 | (usually glibc but others can work), the glib2 library (used heavily |
| 10 | in the code base) and a few other core libraries for interfacing with |
| 11 | code modules and system build descriptions. |
| 12 | |
| 13 | We use the ``libvirt-ci`` project to handle the mapping of |
| 14 | dependencies to a wide variety output formats including system install |
| 15 | scripts. For example: |
| 16 | |
| 17 | .. code-block:: bash |
| 18 | |
| 19 | # THIS FILE WAS AUTO-GENERATED |
| 20 | # |
| 21 | # $ lcitool buildenvscript debian-13 ./tests/lcitool/projects/qemu-minimal.yml |
| 22 | # |
| 23 | # https://gitlab.com/libvirt/libvirt-ci |
| 24 | |
| 25 | function install_buildenv() { |
| 26 | export DEBIAN_FRONTEND=noninteractive |
| 27 | apt-get update |
| 28 | apt-get dist-upgrade -y |
| 29 | apt-get install --no-install-recommends -y \ |
| 30 | bash \ |
| 31 | bc \ |
| 32 | bison \ |
| 33 | bzip2 \ |
| 34 | ca-certificates \ |
| 35 | ccache \ |
| 36 | findutils \ |
| 37 | flex \ |
| 38 | gcc \ |
| 39 | git \ |
| 40 | libc6-dev \ |
| 41 | libfdt-dev \ |
| 42 | libffi-dev \ |
| 43 | libglib2.0-dev \ |
| 44 | libpixman-1-dev \ |
| 45 | locales \ |
| 46 | make \ |
| 47 | meson \ |
| 48 | ninja-build \ |
| 49 | pkgconf \ |
| 50 | python3 \ |
| 51 | python3-venv \ |
| 52 | sed \ |
| 53 | tar |
| 54 | sed -Ei 's,^# (en_US\.UTF-8 .*)$,\1,' /etc/locale.gen |
| 55 | dpkg-reconfigure locales |
| 56 | rm -f /usr/lib*/python3*/EXTERNALLY-MANAGED |
| 57 | dpkg-query --showformat '${Package}_${Version}_${Architecture}\n' --show > /packages.txt |
| 58 | mkdir -p /usr/libexec/ccache-wrappers |
| 59 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/cc |
| 60 | ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/gcc |
| 61 | } |
| 62 | |
| 63 | export CCACHE_WRAPPERSDIR="/usr/libexec/ccache-wrappers" |
| 64 | export LANG="en_US.UTF-8" |
| 65 | export MAKE="/usr/bin/make" |
| 66 | export NINJA="/usr/bin/ninja" |
| 67 | export PYTHON="/usr/bin/python3" |
| 68 | |
| 69 | If you instead select the ``qemu.yml`` project file you will get all |
| 70 | the dependencies that the project can use. |
| 71 | |
| 72 | Using you system package manager |
| 73 | -------------------------------- |
| 74 | |
| 75 | .. note:: |
| 76 | |
| 77 | Installing dependencies using your package manager build dependencies may |
| 78 | miss out on deps that have been newly introduced in qemu.git. It |
| 79 | also misses deps the distribution has decided to exclude. |
| 80 | |
| 81 | Systems with Package Managers |
| 82 | +++++++++++++++++++++++++++++ |
| 83 | |
| 84 | .. list-table:: Package Manager Commands |
| 85 | :widths: 10 50 40 |
| 86 | :header-rows: 1 |
| 87 | |
| 88 | * - System |
| 89 | - Command |
| 90 | - Notes |
| 91 | * - Fedora |
| 92 | - ``sudo dnf update && sudo dnf builddep qemu`` |
| 93 | - |
| 94 | * - Debian/Ubuntu |
| 95 | - ``sudo apt update && sudo apt build-dep qemu`` |
| 96 | - Must enable `Sources List |
| 97 | <https://wiki.debian.org/SourcesList>`_ first |
| 98 | * - MacOS |
| 99 | - ``brew update && brew install $(brew deps --include-build qemu)`` |
| 100 | - Using `Homebrew <https://brew.sh/>`_. |
| 101 | |
| 102 | Windows |
| 103 | +++++++ |
| 104 | |
| 105 | You first need to install `MSYS2 <https://www.msys2.org/>`_. |
| 106 | MSYS2 offers `different environments <https://www.msys2.org/docs/environments/>`_. |
| 107 | x86_64 environments are based on GCC, while aarch64 is based on Clang. |
| 108 | |
| 109 | We recommend to use MINGW64 for windows-x86_64 and CLANGARM64 for windows-aarch64 |
| 110 | (only available on windows-aarch64 hosts). |
| 111 | |
| 112 | Then, you can open a windows shell, and enter msys2 env using: |
| 113 | |
| 114 | :: |
| 115 | |
| 116 | c:/msys64/msys2_shell.cmd -defterm -here -no-start -mingw64 |
| 117 | # Replace -ucrt64 by -clangarm64 or -ucrt64 for other environments. |
| 118 | |
| 119 | MSYS2 package manager does not offer a built-in way to install build |
| 120 | dependencies. You can start with this list of packages using pacman: |
| 121 | |
| 122 | Note: Dependencies need to be installed again if you use a different MSYS2 |
| 123 | environment. |
| 124 | |
| 125 | :: |
| 126 | |
| 127 | # update MSYS2 itself, you need to reopen your shell at the end. |
| 128 | pacman -Syu |
| 129 | pacman -S \ |
| 130 | base-devel binutils bison diffutils flex git grep make sed \ |
| 131 | ${MINGW_PACKAGE_PREFIX}-toolchain \ |
| 132 | ${MINGW_PACKAGE_PREFIX}-glib2 \ |
| 133 | ${MINGW_PACKAGE_PREFIX}-gtk3 \ |
| 134 | ${MINGW_PACKAGE_PREFIX}-libnfs \ |
| 135 | ${MINGW_PACKAGE_PREFIX}-libssh \ |
| 136 | ${MINGW_PACKAGE_PREFIX}-ninja \ |
| 137 | ${MINGW_PACKAGE_PREFIX}-pixman \ |
| 138 | ${MINGW_PACKAGE_PREFIX}-pkgconf \ |
| 139 | ${MINGW_PACKAGE_PREFIX}-python \ |
| 140 | ${MINGW_PACKAGE_PREFIX}-SDL2 \ |
| 141 | ${MINGW_PACKAGE_PREFIX}-zstd |
| 142 | |
| 143 | If you want to install all dependencies, it's possible to use recipe used to |
| 144 | build QEMU in MSYS2 itself. |
| 145 | |
| 146 | :: |
| 147 | |
| 148 | pacman -S wget base-devel git |
| 149 | wget https://raw.githubusercontent.com/msys2/MINGW-packages/refs/heads/master/mingw-w64-qemu/PKGBUILD |
| 150 | # Some packages may be missing for your environment, installation will still |
| 151 | # be done though. |
| 152 | makepkg --syncdeps --nobuild PKGBUILD || true |
| 153 | |
| 154 | Build on windows-aarch64 |
| 155 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 156 | |
| 157 | When trying to cross compile meson for x86_64 using UCRT64 or MINGW64 env, |
| 158 | configure will run into an error because the cpu detected is not correct. |
| 159 | |
| 160 | Meson detects x86_64 processes emulated, so you need to manually set the cpu, |
| 161 | and force a cross compilation (with empty prefix). |
| 162 | |
| 163 | :: |
| 164 | |
| 165 | ./configure --cpu=x86_64 --cross-prefix= |