Skip to content

ui_app_setup: drop HAL_PLATFORM_SDL guard so emulator builds#48

Merged
eggfly merged 4 commits into
masterfrom
fix/hal-decouple-setup-and-emu-guards
Jun 2, 2026
Merged

ui_app_setup: drop HAL_PLATFORM_SDL guard so emulator builds#48
eggfly merged 4 commits into
masterfrom
fix/hal-decouple-setup-and-emu-guards

Conversation

@eggfly

@eggfly eggfly commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Make UISetupPage compile on the emulator (macOS / SDL Linux / Web) so the SETTING page is actually reachable from APPLaunch.

Problem

ui_app_launch.cpp:144:67: error: 'UISetupPage' was not declared in this scope
                              img_path("setting_100.png"), page_v<UISetupPage>);
                                                                  ^~~~~~~~~~~

ui_app_setup.hpp is currently wrapped in #if !defined(HAL_PLATFORM_SDL), which excludes it from emu builds — but ui_app_launch.cpp registers page_v<UISetupPage> unconditionally, so the build is structurally broken under HAL_PLATFORM_SDL.

This breaks the M5CardputerZero-Emulator CI on every platform.

Fix

Drop the SDL guard. The class is already HAL-clean for the parts the emu actually exercises:

  • ✅ Uses HAL: hal_wifi_*, hal_battery_*, hal_volume_*, hal_bt_*, hal_backlight_* — all have stubs in hal/sdl/.
  • ✅ i2c ioctl / <linux/i2c.h> includes — already inside #ifdef __linux__.
  • ⚠️ Residual unguarded raw syscalls (popen, system, /sys/class/power_supply walk):
    • These are POSIX, compile fine on macOS/Linux hosts.
    • They're only triggered when the user navigates to specific sub-pages (Account / Ethernet / Update / Set RTC) and confirms an action — flows the emulator user can't reach without explicit input. So compiling them in isn't a runtime hazard either.
    • Follow-up: route them through hal_account_info() / hal_eth_status() / hal_system_update_*(). Out of scope for this PR.

Test

Local macOS arm64 (with M5CardputerZero-Emulator submodule pointing at this branch):

$ make -C build -j10
[100%] Built target cardputer-emu
$ file build/cardputer-emu
build/cardputer-emu: Mach-O 64-bit executable arm64
$ ./build/cardputer-emu  # opens, SETTING page now reachable

Companion PR

This unblocks CardputerZero/emulator#2 — once this merges, that PR drops the corresponding workaround in cmake/patches/apply_vendor_workarounds.cmake and bumps the launcher submodule.

eggfly added 2 commits June 2, 2026 22:41
The class was wrapped in `#if !defined(HAL_PLATFORM_SDL)`, which excluded
it from emulator builds — but ui_app_launch.cpp registers
`page_v<UISetupPage>` unconditionally, causing a fatal compile error
on emu ("'UISetupPage' was not declared").

Removing the guard is safe:

- The UI implementation already uses HAL functions (hal_wifi_*,
  hal_battery_*, hal_volume_*, hal_bt_*, hal_backlight_*) that have
  emulator stubs in hal/sdl/.
- Residual raw syscalls (i2c ioctl, sys/class/power_supply DIR walk,
  popen for ip/whoami/hostname, sudo date, apt update) all sit either
  inside an existing `#ifdef __linux__` block, or in code paths that
  only fire on user actions the emulator never performs (e.g. the
  user must navigate into the WiFi/Update sub-pages and confirm).
- Both popen() and system() are POSIX and compile fine on macOS/Linux
  hosts. Windows static builds of APPLaunch are a separate concern
  (already broken before this change due to gethostname/_popen).

This unblocks the M5CardputerZero-Emulator multi-arch CI.
GCC on MinGW (Windows MSYS2) errors with 'snprintf was not declared in
this scope'. The implicit transitive include via <string.h>/<stdlib.h>
holds on glibc/libc++ but not on MSYS2's headers. Other HAL files in the
same directory already include <stdio.h>; this one was an oversight.
eggfly added a commit to CardputerZero/emulator that referenced this pull request Jun 2, 2026
…orkaround

Two follow-ups discovered after the previous CI round:

1. src/emu_launcher_stubs.c — provides LV_EVENT_BATTERY,
   LV_EVENT_WIFI_INFO, g_launch_thread_pool. Launcher's own main.cpp
   defines these globals on device, but the emulator runs its own
   src/main.cpp. The Unix shared-library path resolves them at dlopen
   time via dynamic_lookup; static-linked targets (Windows + Web) need
   real storage. Linked into both windows and web targets only.

2. cmake/patches: workaround #3 — hal_filesystem_sdl.cpp is missing
   <stdio.h> for snprintf. Compiles on glibc/libc++ where <string.h>
   transitively pulls it in, fails on MSYS2. Trivial header patch
   tracked by Launcher PR #48; will self-skip once that lands.

Tracking PR (Launcher): CardputerZero/launcher#48
eggfly added 2 commits June 2, 2026 23:28
Forgot to drop the matching `#else` branch that provided a stub
UISetupPage for HAL_PLATFORM_SDL builds. With the outer guard gone,
the orphan `#else` produced 'else without if' on every platform
and a class redefinition error.

Now the file has a single, unconditional class definition.
Declared in hal_settings.h but never implemented for SDL — caused a
link error on Windows / Web emulator builds (UISetupPage's WiFi menu
calls it). Returns 0 (success no-op) for the emulator.

Linux native and macOS link paths used dynamic_lookup so they didn't
notice the missing symbol; the static-link targets do.
@eggfly eggfly merged commit 92d4434 into master Jun 2, 2026
6 checks passed
@eggfly eggfly deleted the fix/hal-decouple-setup-and-emu-guards branch June 2, 2026 16:13
eggfly added a commit to CardputerZero/emulator that referenced this pull request Jun 3, 2026
…orkaround

Two follow-ups discovered after the previous CI round:

1. src/emu_launcher_stubs.c — provides LV_EVENT_BATTERY,
   LV_EVENT_WIFI_INFO, g_launch_thread_pool. Launcher's own main.cpp
   defines these globals on device, but the emulator runs its own
   src/main.cpp. The Unix shared-library path resolves them at dlopen
   time via dynamic_lookup; static-linked targets (Windows + Web) need
   real storage. Linked into both windows and web targets only.

2. cmake/patches: workaround #3 — hal_filesystem_sdl.cpp is missing
   <stdio.h> for snprintf. Compiles on glibc/libc++ where <string.h>
   transitively pulls it in, fails on MSYS2. Trivial header patch
   tracked by Launcher PR #48; will self-skip once that lands.

Tracking PR (Launcher): CardputerZero/launcher#48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant