ruvnet/RuView · error · RuntimeError

Failed to compile macOS WiFi utility: {e.stderr.decode('utf-

Error message

Failed to compile macOS WiFi utility: {e.stderr.decode('utf-8')}

What it means

MacosWifiCollector.start() lazily compiles the bundled mac_wifi.swift helper with 'swiftc -O' the first time it runs. swiftc executed but exited nonzero (subprocess.CalledProcessError), and the collector surfaces the compiler's stderr verbatim. This means Xcode tools are installed but the Swift source failed to build against the current SDK, typically after a macOS/Xcode update changed CoreWLAN APIs, or the cached source/binary state is inconsistent.

Source

Thrown at archive/v1/src/sensing/rssi_collector.py:676

    # -- public API ----------------------------------------------------------

    @property
    def sample_rate_hz(self) -> float:
        return self._rate

    def start(self) -> None:
        if self._running:
            return
        
        # Ensure binary exists
        import os
        if not os.path.exists(self.swift_bin):
            logger.info("Compiling mac_wifi.swift to %s", self.swift_bin)
            try:
                subprocess.run(["swiftc", "-O", "-o", self.swift_bin, self.swift_src], check=True, capture_output=True)
            except subprocess.CalledProcessError as e:
                raise RuntimeError(f"Failed to compile macOS WiFi utility: {e.stderr.decode('utf-8')}")
            except FileNotFoundError:
                raise RuntimeError("swiftc is not installed. Please install Xcode Command Line Tools to use native macOS WiFi sensing.")

        self._running = True
        self._thread = threading.Thread(
            target=self._sample_loop, daemon=True, name="mac-rssi-collector"
        )
        self._thread.start()
        logger.info("MacosWifiCollector started at %.1f Hz", self._rate)

    def stop(self) -> None:
        self._running = False
        if self._process:
            self._process.terminate()
            try:
                self._process.wait(timeout=1.0)
            except subprocess.TimeoutExpired:
                self._process.kill()

View on GitHub (pinned to 4685618388)

Solutions

  1. Reproduce manually to see the full error: run 'swiftc -O -o /tmp/mac_wifi <repo>/.../mac_wifi.swift' and read the diagnostics (the raised message already embeds stderr).
  2. Update Xcode Command Line Tools to the latest for your macOS ('softwareupdate --install "Command Line Tools"') and clear the stale compiled binary so it rebuilds.
  3. If the source uses a changed API, patch mac_wifi.swift for the current CoreWLAN surface or pin the Xcode version that matches the source.
  4. Delete the cached swift_bin path so the next start() recompiles cleanly after fixes.

Example fix

# before
collector = MacosWifiCollector(rate=2.0)
collector.start()  # RuntimeError: Failed to compile macOS WiFi utility: <swiftc stderr>

# after
import subprocess, pathlib
src = pathlib.Path('src/sensing/mac_wifi.swift')
subprocess.run(['swiftc', '-O', '-o', '/tmp/mac_wifi', str(src)], check=True)  # surface real diagnostics
collector = MacosWifiCollector(rate=2.0)
collector.start()
Defensive patterns

Strategy: try-catch

Try / catch

try:
    collector.start()
except RuntimeError as exc:
    if 'Failed to compile' in str(exc):
        logger.error('swift compile failed; run swiftc manually for diagnostics: %s', exc)
        # optionally fall back to rebuilding after clearing the cached binary
        raise

Prevention

When it happens

Trigger: First start of MacosWifiCollector on a machine where the swift_bin binary does not yet exist and the swiftc invocation fails: macOS or Xcode Command Line Tools upgraded to a version whose CoreWLAN/AirPort API differs from what mac_wifi.swift uses; Swift language-mode changes rejecting the source; a truncated or missing mac_wifi.swift resource.

Common situations: After yearly macOS/Xcode updates; after switching Xcode versions with xcode-select; moving or repackaging the app so the swift source path resolves but content is stale; CI runners with beta Xcode toolchains.

Related errors


AI-assisted analysis of ruvnet/RuView@4685618388 (2026-08-16). Data as JSON: /api/errors/b1bf586a144d7fb8. Report an issue: GitHub.