Skip to content

fix(cpn): set correct WAMR build target per slice in macOS universal builds - #7946

Merged
pfeerick merged 4 commits into
mainfrom
fix/wamr-macos-universal
Oct 25, 2026
Merged

pfeerick merged 4 commits into
mainfrom
fix/wamr-macos-universal

Conversation

@pfeerick

@pfeerick pfeerick commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Fixes #7660

Problem

The macOS Companion CI job runs on macos-15-arm64 with CMAKE_OSX_ARCHITECTURES=x86_64;arm64. WAMR derives a single WAMR_BUILD_TARGET from CMAKE_SYSTEM_PROCESSOR, so it picks AARCH64 and adds -DBUILD_TARGET_AARCH64 to both slices.

WAMR's assembly is universal-aware (invokeNative_osx_universal.s picks em64 or aarch64 via __aarch64__), but its C side is not. In wasm_runtime_common.c, MAX_REG_INTS is 8 under BUILD_TARGET_AARCH64, so the x86_64 slice packs native-call argv with 8 integer slots. invokeNative_em64.s expects 6 and reads stack args from argv + 64+48. Any host or WASI call that passes arguments on the stack (e.g. path_open, 9 args) gets garbage. The simulator then stalls after edgeTxInit, and a reload shows out of bounds memory access.

Arm64 is unaffected, and local Intel builds work because they aren't universal and detect x86_64.

Fix

For universal macOS builds, override the target define per slice on vmlib with -Xarch_x86_64 / -Xarch_arm64 -U/-D flags. Compile options come after the directory -D definitions on the command line, so the overrides win.

Also: the WAMR win_file.c patch is now idempotent and skipped when already applied (git apply --reverse --check), so repeat configures no longer print a "patch does not apply" error and warning.

Also fixes the v16 simulator link failure introduced by #7496 (getSystemCurrent, getIntModuleCurrent, getExtModuleVoltage, getExtModuleCurrent undefined in the WASM build), by adding zero-value CSD203 stubs to targets/simu/adc_driver.cpp. And adds cmake/FetchWamr.cmake / cmake/wamr-*.patch to the Companion workflow path filters.

Testing

  • Local universal build of vmlib on Apple Silicon: the compile line shows the overrides after -DBUILD_TARGET_AARCH64, and libiwasm.a is x86_64 arm64.
  • Probe compile with the same flags: x86_64 slice sees only BUILD_TARGET_X86_64, arm64 only BUILD_TARGET_AARCH64. Without the flags, the x86_64 slice has BUILD_TARGET_AARCH64.
  • Linux build in the edgetx-dev docker image: unaffected (no -Xarch flags emitted).
  • Docker: fresh clone applies the patch once; two further configures print no patch error/warning, source stays patched.
  • Docker: FLAVOR=v16 tools/build-wasm-modules.sh now links edgetx-v16-simulator.wasm.
  • Run the CI macOS artifact on an Intel Mac and start the Simulator.
  • Run the CI macOS artifact on an Apple Silicon Mac and start the Simulator.

🤖 Generated with Claude Code

…builds

WAMR derives a single BUILD_TARGET_* from the host CPU. On the arm64 CI
runner a universal (x86_64;arm64) build therefore compiles the x86_64
slice with BUILD_TARGET_AARCH64, so wasm_runtime_invoke_native lays out
8 integer register slots while invokeNative_em64.s expects 6. Native and
WASI calls passing stack arguments (e.g. path_open) receive garbage and
the simulator hangs on Intel Macs.

Override the target define per architecture with -Xarch_ flags.

Fixes #7660

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pfeerick pfeerick added this to the 3.0 milestone Oct 25, 2026
@pfeerick pfeerick added simulator (sim) bug/regression ↩️ A new version of EdgeTX broke something labels Oct 25, 2026
pfeerick and others added 3 commits October 25, 2026 18:19
The patch was re-applied on every configure against the cached WAMR
source, failing with "patch does not apply" and a warning on repeat
runs. Check with git apply --reverse --check first and skip if present.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FetchWamr.cmake and its patches affect the Companion simulator build but were not in the workflow path filters, so changes to them did not trigger CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#7496 added CSD203 module/system current and voltage readouts to the
module setup page and charge UI, but the getters only exist in the STM32
csd203_sensor driver, so the v16 WASM simulator failed to link.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pfeerick
pfeerick force-pushed the fix/wamr-macos-universal branch from 35b6d71 to 59f3803 Compare October 25, 2026 10:15
@pfeerick
pfeerick marked this pull request as ready for review October 25, 2026 11:17
@pfeerick
pfeerick merged commit a6c9920 into main Oct 25, 2026
53 checks passed
@pfeerick
pfeerick deleted the fix/wamr-macos-universal branch October 25, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug/regression ↩️ A new version of EdgeTX broke something simulator (sim)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simulator on intel-based MacOS fails for main branch

1 participant