Skip to content

Use cached ESP QEMU for esp32/esp32c3 emulators #1737

@luoliwoshang

Description

@luoliwoshang

Background

Running the esp32 and esp32c3 emulators currently depends on qemu-system-* being available in the environment.

In practice, this means users usually need to prepare QEMU manually before running commands such as:

  • llgo run -target=esp32 -emulator
  • llgo run -target=esp32c3-basic -emulator

and before running embedded emulator-based tests.

This is inconsistent with the current esp-clang experience. When esp-clang is missing, llgo can automatically download the correct host-platform package and cache it under the crosscompile cache. ESP QEMU should follow the same model.

Problem

At the moment, ESP emulator support is still environment-dependent:

  • local users need to install or prepare QEMU themselves
  • CI installs ESP QEMU explicitly and injects it into PATH

This is not the intended long-term behavior.

Proposal

When an ESP emulator is actually needed, llgo should automatically detect whether the required ESP QEMU binaries are available in the crosscompile cache. If not, it should download the correct package for the current host platform and extract it into:

  • crosscompile/esp-qemu-<version>

Subsequent runs should reuse the cached directory.

Scope

This change is intentionally limited to ESP emulator workflows only.

Supported emulator commands:

  • qemu-system-riscv32
  • qemu-system-xtensa

Supported target scenarios:

  • esp32c3-basic
  • esp32

Supported host platforms for the first implementation:

  • macOS amd64
  • macOS arm64
  • Linux amd64
  • Linux arm64

Out of scope for now:

  • Windows support
  • non-ESP QEMU targets
  • changing target JSON definitions

Requirements

  • Keep existing target JSON emulator fields unchanged. They should continue to use qemu-system-*.
  • Only trigger automatic download when the ESP emulator is actually needed.
  • Store the downloaded toolchain in:
    • crosscompile/esp-qemu-<version>
  • The downloaded package itself should still be selected based on the current host platform.
  • Reuse the cache on later runs instead of downloading again.
  • Handle concurrent access safely to avoid duplicate downloads or corrupted cache state.
  • Follow the existing style and behavior of the esp-clang download/cache flow as much as possible.

Expected Behavior

If a user runs an ESP emulator command in a clean environment without preinstalled QEMU, llgo should:

  1. detect that the required ESP QEMU binaries are missing
  2. determine the correct package for the current host platform
  3. download and extract it into crosscompile/esp-qemu-<version>
  4. execute the emulator using the cached binaries

No manual QEMU installation should be required.

Current State

CI still installs ESP QEMU explicitly before running embedded emulator tests. This confirms that ESP QEMU has not yet been integrated into llgo's own crosscompile/toolchain acquisition flow.

Acceptance Criteria

  • Remove the explicit ESP QEMU installation step from CI.
  • CI still passes for existing ESP emulator coverage.
  • Both of the following work in a clean environment without preinstalled QEMU:
    • esp32c3-basic emulator runs
    • esp32 emulator runs
  • First run downloads automatically.
  • Later runs reuse the cache without re-downloading.
  • Existing target JSON emulator definitions remain unchanged.
  • Automatic download is only triggered for esp32/esp32c3 emulator scenarios, not for normal build/install flows.

Notes

This issue is not about generalizing automatic download for every QEMU-based target. The goal is to first make the ESP emulator experience consistent with the existing esp-clang auto-download behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions