From 60837a8708cecfcec8423cc29d61fdf6d465a9a6 Mon Sep 17 00:00:00 2001 From: MonchiLin <3960879+MonchiLin@users.noreply.github.com> Date: Wed, 2 Dec 2026 11:30:14 +0800 Subject: [PATCH] Enable USB redirection in the Windows QEMU build --- docs/qemu.md | 8 +++++--- scripts/install-ctl.sh | 8 ++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/qemu.md b/docs/qemu.md index 7b493833a..4f55aaed1 100644 --- a/docs/qemu.md +++ b/docs/qemu.md @@ -1259,8 +1259,8 @@ where it runs from no checkout, brings MSYS2's packages up to date CLANG64 shell. That installs its MSYS2 packages with pacman and, where there is no rustup, rustup with the `x86_64-pc-windows-gnullvm` host, whose builds link with CLANG64's clang and lld; it builds the library's dist tree -and QEMU (WHPX, GTK, slirp, libusb, no guest agent), copies the CLANG64 -DLLs QEMU and qemu-img load beside them, and installs reims-ctl and +and QEMU (WHPX, GTK, slirp, libusb and usbredir, no guest agent), copies the +CLANG64 DLLs QEMU and qemu-img load beside them, and installs reims-ctl and reims-util into `%USERPROFILE%\.cargo\bin`. `install.toml` records the MSYS2 bash the install ran in, and `reims-ctl update` runs the script there, with `MSYSTEM=CLANG64`. Whatever rustup's default host, the script builds @@ -1269,7 +1269,9 @@ with `rust-toolchain.toml`'s channel for the `x86_64-pc-windows-gnullvm` host where it is missing, leaving the user's default as it was: with Windows' usual default host, `x86_64-pc-windows-msvc`, xtask, the build scripts, reims-ctl and reims-util would build for MSVC, which links only with Visual -Studio's `link.exe`. +Studio's `link.exe`. QEMU's `usb-redir` device connects a guest USB port +to a chardev speaking the usbredir protocol. The Windows build gets the +parser from MSYS2's `mingw-w64-clang-x86_64-usbredir` package. With `REIMS_INSTALL_SKIP_HOST_CHECKS=1` in its environment, install.ps1 skips the hypervisor platform's step, its check and its turning on, and diff --git a/scripts/install-ctl.sh b/scripts/install-ctl.sh index d5f323590..05bc456e2 100755 --- a/scripts/install-ctl.sh +++ b/scripts/install-ctl.sh @@ -134,7 +134,7 @@ case "$OS/$ARCH" in # guest agent, which reims-ctl does not use and whose Windows build needs # windmc, which none of the packages below provides. QEMU_CONFIGURE=(--target-list=x86_64-softmmu --enable-whpx --disable-sdl --enable-gtk --enable-slirp - --enable-libusb --disable-guest-agent --bindir=bin) + --enable-libusb --enable-usb-redir --disable-guest-agent --bindir=bin) QEMU_BINARIES=(qemu-system-x86_64.exe) ;; Darwin/arm64) @@ -392,7 +392,7 @@ dnf_pkgs=(gcc gcc-c++ make git curl ca-certificates pkgconf-pkg-config python3 n # build tools and the libraries it links; and libva and Mesa, whose VA-API driver # on Direct3D 12 (vaon12) decodes the reims-graphics device's video. msys2_pkgs=(git curl diffutils make - mingw-w64-clang-x86_64-{clang,lld,pkgconf,meson,ninja,cmake,python,glib2,pixman,libslirp,gtk3,libusb,zstd,libva,mesa}) + mingw-w64-clang-x86_64-{clang,lld,pkgconf,meson,ninja,cmake,python,glib2,pixman,libslirp,gtk3,libusb,usbredir,zstd,libva,mesa}) case "$OS $distro_id $distro_like " in Darwin*) ;; MINGW* | MSYS*) @@ -795,6 +795,10 @@ if [[ $SKIP_QEMU == 0 ]]; then ldd "/clang64/bin/$dll.dll" | awk '$3 ~ "^/clang64/" { print $3 }' done } | sort -u | while read -r dll; do cp "$dll" "$STAGE$PREFIX/bin/"; done + # Run with the DLLs in the staged install, as QEMU starts outside MSYS2. + if ! PATH= "$STAGE$PREFIX/bin/$QEMU_BINARY" -device help | grep -F '"usb-redir"' >/dev/null; then + die "the staged Windows QEMU cannot load its usb-redir device" + fi else DESTDIR="$STAGE" ninja -C "$BUILD" install >/dev/null cp "$DIST/bin/$HELPER" "$STAGE$PREFIX/bin/"