Skip to main content

How to build QEMU on Windows 10/11

note

The QEMU in this article is all refers to the QEMU provided and maintained by the PolyOS community. When it needs to refer to the original(upstream) QEMU, we will call it 'upstream QEMU'.

We will help you build the QEMU provided and maintained by the PolyOS community in the Windows 10/11 system. QEMU provides neccessary vitural environment for the develop and test of the PolyOS Mobile. You can easily configure and compile QEMU with the help of the MSYS2 environment. Also, by installing MSY2, getting the source code, configuring the compiling optional and conduting compile, you can get a powerful QEME, which can use to run and test PolyOS. Through this article, you can not only successfully the develop environment oof PolyOS and QEMU in the Windows platform, but also know more about the detail of vitural technology.

MSYS2

MSYS2 is a package management system and development tool set that provides a Unix-like environment on the Windows platform. It provides powerful Command Prompt tool and development environment which enables it building and running Unix-like software more easily in Windows system. We can help you easily install GNU tool chain in Windows 10/11 and get a MinGW64 environment.

info

The relationship of MSYS2 and MinGW-w64

MSYS2 and MinGW-w64 is closely related project which construct MSYS2 environment mutually.

  • MSYS2:provide a Unix-like shell environment and package manager, which can use to build Unix-like software in Windows.
  • MinGW-w64:a development tool set supports 64-bit and 32-bit targets on Windows, including GCC compiler, Make build tool etc., for compiling and running C/C++ program.

Alternatively, you can also think of MSYS2 as a management tool for MinGW64、MinGW32、Clang、URCT64 and other toolsets.

Install MSYS2

It is easy to install MSYS2 by following steps:

  1. Open https://www.msys2.org/ and click msys2-x86_64-20230526.exe (usually it is named msys2-x8664-_date.exe) button to access the exe format package, and then install it.
  2. run the installation program and select the installation directory.
  3. After finishing installation, start the MSYS2 terminal.
  4. We will use pacman package manager to install necessary development tools and package in this terminal later.

Build environment

Since the QEMU uses GNU Build System (GNU autotools) and meson to build, we need to prepare an environment which includes GNU Build System、GCC toolchain as well as QEMU dependencies to conduct the actual build. In addition, you also need to ensure that you have the Git tool to access source code since the PolyOS community's QEMU source code is hosted in a Git repository on Gitee.

Configure GCC toolchain

You need to execute the installation command of pacman in MSYS2.

pacman -Sy mingw-w64-x86_64-toolchain

Install QEMU building dependency

You need to ensure following dependencies are successfully installed.

pacman -Sy mingw-w64-x86_64-meson mingw-w64-x86_64-ninja \
mingw-w64-x86_64-python \
mingw-w64-x86_64-python-sphinx \
mingw-w64-x86_64-python-sphinx_rtd_theme \
mingw-w64-x86_64-autotools \
mingw-w64-x86_64-tools-git \
mingw-w64-x86_64-cc \
mingw-w64-x86_64-angleproject \
mingw-w64-x86_64-capstone \
mingw-w64-x86_64-curl \
mingw-w64-x86_64-cyrus-sasl \
mingw-w64-x86_64-expat \
mingw-w64-x86_64-fontconfig \
mingw-w64-x86_64-freetype \
mingw-w64-x86_64-fribidi \
mingw-w64-x86_64-gcc-libs \
mingw-w64-x86_64-gdk-pixbuf2 \
mingw-w64-x86_64-gettext \
mingw-w64-x86_64-glib2 \
mingw-w64-x86_64-gmp \
mingw-w64-x86_64-gnutls \
mingw-w64-x86_64-graphite2 \
mingw-w64-x86_64-gst-plugins-base \
mingw-w64-x86_64-gstreamer \
mingw-w64-x86_64-gtk3 \
mingw-w64-x86_64-harfbuzz \
mingw-w64-x86_64-jbigkit \
mingw-w64-x86_64-lerc \
mingw-w64-x86_64-libc++ \
mingw-w64-x86_64-libdatrie \
mingw-w64-x86_64-libdeflate \
mingw-w64-x86_64-libepoxy \
mingw-w64-x86_64-libffi \
mingw-w64-x86_64-libiconv \
mingw-w64-x86_64-libidn2 \
mingw-w64-x86_64-libjpeg-turbo \
mingw-w64-x86_64-libnfs \
mingw-w64-x86_64-libpng \
mingw-w64-x86_64-libpsl \
mingw-w64-x86_64-libslirp \
mingw-w64-x86_64-libssh \
mingw-w64-x86_64-libssh2 \
mingw-w64-x86_64-libtasn1 \
mingw-w64-x86_64-libthai \
mingw-w64-x86_64-libtiff \
mingw-w64-x86_64-libunistring \
mingw-w64-x86_64-libunwind \
mingw-w64-x86_64-libusb \
mingw-w64-x86_64-libwebp \
mingw-w64-x86_64-libwinpthread-git \
mingw-w64-x86_64-lz4 \
mingw-w64-x86_64-lzo2 \
mingw-w64-x86_64-nettle \
mingw-w64-x86_64-openssl \
mingw-w64-x86_64-opus \
mingw-w64-x86_64-orc \
mingw-w64-x86_64-p11-kit \
mingw-w64-x86_64-pango \
mingw-w64-x86_64-pixman \
mingw-w64-x86_64-SDL2 \
mingw-w64-x86_64-SDL2_image \
mingw-w64-x86_64-snappy \
mingw-w64-x86_64-spice \
mingw-w64-x86_64-usbredir \
mingw-w64-x86_64-xz \
mingw-w64-x86_64-zlib \
mingw-w64-x86_64-zstd

(Optional) Install Git

This section will help you get the latest version of Git tool if you need to install Git.

We recommend you get the latest version of Git from Git official website. In addition, if you prefer to use winget tool, you can also run the following command to install Git in Powershell.

winget install -e --id Git.Git

Get the source code of QEMU (by PolyOS community)

Find the shortcut of MSYS2 MinGW 64 in your desktop or start menu, and then right-click to open a MinGW64 terminal with rights of administrators and use git to check out QEMU repository.

note

You need to ensure the terminal is MinGW64 environment rather than others(MinGW32、Clang32/64、UCRT64 etc.)

You can also switch to the MinGW64 environment by using the following command in a Powershell with rights of administrators.

C:/msys64/msys2_shell.cmd -defterm -here -no-start -mingw64

If you did not install the MSYS2 to default position, you need to replace C:/msys64/msys2_shell.cmd to the right path.

git clone https://gitee.com/TODO-REVIEW-FIXME

Configure QEMU compiling optional

We expect to build a QEMU emulator which supports GTK、SDL and the target platform is riscv64. So we just need to provide simple configuration to get the necessary emulate environment. If you want to get more support, please read Advanced-options.

Firstly, you need to navigate to the source directory of QEMU and create a directory build to store the build cache.

cd /path/to/qemu
mkdir build && cd build

then, we run configure to generate the suitable Makefile.

../configure --target-list=riscv64-softmmu \
--enable-sdl --enable-gtk \
--disable-werror \
--prefix="$USERPROFILE"/bin

We use --target-list=riscv64-softmmu to generate the emulator for the specified schema(riscv64), through --enable-sdl and --enable-gtk to start supported of SDL and GTK, and specify that QEMU is installed in the bin directory under the user directory when executing installation, such as C:\Users\polyos\bin

Compile QEMU

We just need to execute make to complete the build.

make
tip

You can reduce the execution time of make by using multi-threaded builds.

Install QEMU

The QEMU emulator will be installed under %USERPROFILE%\bin by excuting a simple make install.

tip

You can append %USERPROFILE%\bin to the beginning of the environment variable PATH to make it the default emulator.

Run QEMU

You can use the QEMU you build to run through startup scripts of PolyOS.

Set-ExecutionPolicy Bypass -Scope Process -Force;
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://polyos.iscas.ac.cn/scirpts/qemu-launcher.ps1')) --Arg1 updater.img --Arg2 system.img --Arg3 vendor.img --Arg4 userdata.img --Kernel kernel --Initrd initrd.gz

or you can manually execute qemu-system-riscv64.exe.

C:/msys64/msys2_shell.cmd -defterm -here -no-start -mingw64 %USERPROFILE%\bin\qemu-system-riscv64.exe -- # add your parameter

Advanced-options

FAQ