diff --git a/NOTICE.md b/NOTICE.md index 859133f..e2b953d 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -6,7 +6,7 @@ It includes or downloads the following software, each under its own licence: | Component | Licence | How it is used | Source | |---|---|---|---| -| QEMU | GPL-2.0 (some parts GPL-2.0-or-later, LGPL, BSD) | Bundled in `Contents/Helpers` and run as a separate program, with its libraries from Homebrew (glib, pixman, libslirp and others, under their own licences) | https://www.qemu.org/download/ (the version is in `Contents/Resources/qemu/QEMU-VERSION`) | +| QEMU | GPL-2.0 (some parts GPL-2.0-or-later, LGPL, BSD) | Bundled in `Contents/Helpers` and run as a separate program, built from source with SDL audio, with its libraries from Homebrew (glib, pixman, libslirp, SDL and others, under their own licences) | https://www.qemu.org/download/ (the version is in `Contents/Resources/qemu/QEMU-VERSION`) | | EDK II (edk2-aarch64-code.fd) | BSD-2-Clause-Patent | UEFI firmware for the virtual machine | https://github.com/tianocore/edk2 | | scrcpy server 5.0.1 | Apache-2.0 | Bundled as `scrcpy-server.jar` and run inside Android for app windows | https://github.com/Genymobile/scrcpy | | LineageOS | Apache-2.0, GPL-2.0 (Linux kernel) and others | Downloaded on first launch as the Android image | https://github.com/LineageOS | diff --git a/apple/Subsystem/Model/VirtualMachine.swift b/apple/Subsystem/Model/VirtualMachine.swift index 44b4211..4a9c011 100644 --- a/apple/Subsystem/Model/VirtualMachine.swift +++ b/apple/Subsystem/Model/VirtualMachine.swift @@ -162,7 +162,8 @@ final class VirtualMachine: @unchecked Sendable { "-qmp", "unix:\(QMPClient.socketURL.path),server=on,wait=off", "-device", "virtio-serial", "-serial", "file:\(consoleURL.path)", - "-audiodev", "coreaudio,id=audio0", + // QEMU's Core Audio backend can't record (max_voices_in = 0); SDL can, and plays too. + "-audiodev", c.microphone ? "sdl,id=audio0" : "coreaudio,id=audio0", "-device", "intel-hda", "-device", c.microphone ? "hda-duplex,audiodev=audio0" : "hda-output,audiodev=audio0", // The main display only hosts Android's own launcher; app windows use virtual displays. diff --git a/core/scripts/bundle-qemu.sh b/core/scripts/bundle-qemu.sh index 01770b7..35b6468 100755 --- a/core/scripts/bundle-qemu.sh +++ b/core/scripts/bundle-qemu.sh @@ -1,22 +1,42 @@ #!/bin/bash -# Bundle QEMU for the Mac app: Homebrew's qemu-system-aarch64 and qemu-img, their -# libraries (install names rewritten to point inside the app), and the arm64 UEFI -# firmware. Output: build/payload/qemu/{Helpers,Frameworks/qemu,share} +# Bundle QEMU for the Mac app: qemu-system-aarch64 and qemu-img built from source +# with SDL audio, their libraries (install names rewritten to point inside the +# app), and the arm64 UEFI firmware. Output: build/payload/qemu/{Helpers,Frameworks/qemu,share} # # core/scripts/bundle-qemu.sh # -# Run on an Apple-silicon Mac (or macOS runner) with Homebrew. QEMU runs as its -# own process, so its GPLv2 licence sits beside the app's GPLv3 one; NOTICE.md -# says where its source comes from. +# Built rather than taken from Homebrew because Homebrew's QEMU has no SDL, and +# QEMU's Core Audio backend can only play (max_voices_in = 0): the microphone +# needs `-audiodev sdl`. Run on an Apple-silicon Mac (or macOS runner) with +# Homebrew. QEMU runs as its own process, so its GPLv2 licence sits beside the +# app's GPLv3 one; NOTICE.md says where its source comes from. set -euo pipefail +QEMU_VERSION=11.1.2 ROOT="$(cd "$(dirname "$0")/../.." && pwd)" OUT="${ROOT}/build/payload/qemu" +SRC="${ROOT}/build/qemu-${QEMU_VERSION}" +QEMU="${ROOT}/build/qemu-install" command -v brew >/dev/null || { echo "Homebrew is required"; exit 1; } -brew list --formula qemu >/dev/null 2>&1 || brew install qemu -brew list --formula dylibbundler >/dev/null 2>&1 || brew install dylibbundler -QEMU="$(brew --prefix qemu)" +brew install --quiet meson ninja pkgconf glib pixman libslirp dtc capstone zstd sdl2 dylibbundler + +if [ ! -x "${QEMU}/bin/qemu-system-aarch64" ]; then + mkdir -p "${ROOT}/build" + if [ ! -d "${SRC}" ]; then + curl -fL "https://download.qemu.org/qemu-${QEMU_VERSION}.tar.xz" | tar -xJ -C "${ROOT}/build" + fi + # Homebrew's flags (Formula/q/qemu.rb), trimmed to the one target, plus SDL. + (cd "${SRC}" && ./configure --prefix="${QEMU}" \ + --target-list=aarch64-softmmu \ + --disable-docs --disable-guest-agent --disable-bsd-user \ + --disable-pvg --disable-gtk --enable-cocoa --enable-sdl \ + --enable-slirp --enable-capstone --enable-fdt=system --enable-zstd \ + --audio-drv-list=coreaudio,sdl \ + --extra-cflags="-I$(brew --prefix)/include" --extra-ldflags="-L$(brew --prefix)/lib" \ + && make -j"$(sysctl -n hw.ncpu)" install) +fi +"${QEMU}/bin/qemu-system-aarch64" -audiodev help | grep -qx sdl || { echo "QEMU built without SDL audio"; exit 1; } echo "Bundling $(${QEMU}/bin/qemu-system-aarch64 --version | head -1)" rm -rf "${OUT}" @@ -31,11 +51,16 @@ dylibbundler --overwrite-files --bundle-deps --create-dir \ --dest-dir "${OUT}/Frameworks/qemu" \ --install-path "@executable_path/../Frameworks/qemu/" \ --search-path "$(brew --prefix)/lib" +# Homebrew's SDL2 is sdl2-compat, which dlopens SDL3 from beside itself; without it, +# QEMU hangs on an error dialog at start. +cp "$(brew --prefix sdl3)/lib/libSDL3.0.dylib" "${OUT}/Frameworks/qemu/libSDL3.dylib" +chmod u+w "${OUT}/Frameworks/qemu/libSDL3.dylib" +install_name_tool -id "@loader_path/libSDL3.dylib" "${OUT}/Frameworks/qemu/libSDL3.dylib" 2>/dev/null +codesign --force --sign - "${OUT}/Frameworks/qemu/libSDL3.dylib" cp "${QEMU}/share/qemu/edk2-aarch64-code.fd" "${OUT}/share/" # QEMU's licence travels with it. -cp "${QEMU}/share/doc/qemu/LICENSE" "${OUT}/share/QEMU-LICENSE" 2>/dev/null \ - || cp "${QEMU}/LICENSE" "${OUT}/share/QEMU-LICENSE" 2>/dev/null || true +cp "${SRC}/LICENSE" "${OUT}/share/QEMU-LICENSE" 2>/dev/null || true "${QEMU}/bin/qemu-system-aarch64" --version | head -1 > "${OUT}/share/QEMU-VERSION" du -sh "${OUT}" diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 8067637..6c02f66 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -24,7 +24,7 @@ - **Mac Android Subsystem.app** is an agent (`LSUIElement`) with a menu bar item. It owns QEMU, keeps one ADB connection, and writes `status.json` (off / starting / running / failed, the ADB port). - **Each Android app** has a launcher bundle in `~/Applications/Android Apps`. Its executable is a copy of `AndroidAppHost`; its `Info.plist` names the Android package (`MSAPackageName`). Separate processes give each Android app its own Dock icon, ⌘-Tab entry and menu bar. -- **QEMU** runs as a child process of the Subsystem: `-machine virt -accel hvf -cpu host`, UEFI from `edk2-aarch64-code.fd`, virtio-blk disks, user-mode networking with `hostfwd=tcp:127.0.0.1:58526-:5555`, `intel-hda` through Core Audio, `-display none`. +- **QEMU** runs as a child process of the Subsystem: `-machine virt -accel hvf -cpu host`, UEFI from `edk2-aarch64-code.fd`, virtio-blk disks, user-mode networking with `hostfwd=tcp:127.0.0.1:58526-:5555`, `intel-hda` through Core Audio (`hda-output`), or through SDL (`hda-duplex`) when the microphone is on, since QEMU's Core Audio backend can't record, `-display none`. ## Starting Android