mirror of
https://github.com/espressif/openthread.git
synced 2026-10-13 11:17:39 +00:00
[nexus] add WebAssembly support using Emscripten (#12904)
This commit adds support for building the Nexus simulator for WebAssembly (WASM) using the Emscripten toolchain. This enables the simulator to run in a web browser environment with a JavaScript-based control interface and visualization. Key implementation details: - Introduced `nexus_wasm.cpp` which defines Emscripten bindings (using Embind) for core simulation controls, including stepping time, node creation, topology orchestration, and state manipulation. - Implemented a `WasmObserver` and a global event queue to capture simulation events (node state changes, link updates, packet events) and expose them to JavaScript via a polling mechanism (`pollEvent`). - Updated the CMake build system to support the `EMSCRIPTEN` platform, configuring specific linker options for ES6 module export, modularization, and memory growth. - Enhanced `build.sh` to allow targeting WASM via `emcmake`. - Guarded file-system-dependent operations in `nexus_pcap.cpp` and adjusted `nexus_core.cpp` to handle WASM-specific constraints where standard I/O or multiple observers might not be applicable. - Added `test_wasm_bindings.mjs`, a Node.js-based smoke test that verifies the integrity of the WASM bindings and event pipeline. - Integrated `nexus-wasm-tests` into the GitHub Actions workflow to ensure continuous verification of the WASM build and functionality.
This commit is contained in:
@@ -133,3 +133,33 @@ jobs:
|
||||
- name: Run GRPC Tests
|
||||
run: |
|
||||
cd build/nexus && ./tests/nexus/nexus_grpc
|
||||
|
||||
nexus-wasm-tests:
|
||||
name: nexus-wasm-tests
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e # v2.14.2
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Bootstrap
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get --no-install-recommends install -y ninja-build
|
||||
|
||||
- name: Set up Emscripten
|
||||
uses: mymindstorm/setup-emsdk@v14
|
||||
|
||||
- name: Build Nexus WASM
|
||||
run: |
|
||||
mkdir -p build/nexus
|
||||
top_builddir=build/nexus ./tests/nexus/build.sh wasm
|
||||
|
||||
- name: Run WASM Smoke Test
|
||||
run: |
|
||||
node tests/nexus/test_wasm_bindings.mjs build/nexus/tests/nexus/nexus_live_demo.js
|
||||
|
||||
Reference in New Issue
Block a user