feat: WASM modules based simulation in Companion (#6435)

This commit is contained in:
Raphael Coeffic
2026-03-20 12:19:17 +10:00
committed by GitHub
parent 5f8a38bb18
commit 04a2231aee
80 changed files with 3126 additions and 2220 deletions
+5
View File
@@ -0,0 +1,5 @@
# Copy all WASM simulator modules from SRC_DIR to DST_DIR at build time.
# Invoked via cmake -P so the pattern is evaluated on every build.
file(INSTALL "${SRC_DIR}/" DESTINATION "${DST_DIR}"
FILES_MATCHING PATTERN "edgetx-*-simulator.wasm"
MESSAGE_NEVER)
+3 -1
View File
@@ -14,7 +14,9 @@ else()
message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}")
endif()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64")
if(APPLE)
set(RS_DFU_ARCH "universal")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64")
set(RS_DFU_ARCH "x86_64")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64")
set(RS_DFU_ARCH "aarch64")
+63
View File
@@ -0,0 +1,63 @@
# Fetch and configure WAMR (WebAssembly Micro Runtime)
cmake_minimum_required(VERSION 3.14)
include(FetchContent)
# WAMR build configuration
set(WAMR_BUILD_INTERP 1)
set(WAMR_BUILD_FAST_INTERP 0)
set(WAMR_BUILD_AOT 0)
set(WAMR_BUILD_JIT 0)
set(WAMR_BUILD_LIBC_BUILTIN 1)
set(WAMR_BUILD_LIBC_WASI 1)
set(WAMR_BUILD_LIB_WASI_THREADS 1)
set(WAMR_BUILD_SHARED_MEMORY 1)
set(WAMR_BUILD_BULK_MEMORY 1)
set(WAMR_BUILD_REF_TYPES 1)
set(WAMR_BUILD_SIMD 0)
set(WAMR_BUILD_EXCE_HANDLING 1)
set(WAMR_DISABLE_HW_BOUND_CHECK 1)
FetchContent_Declare(
wamr
GIT_REPOSITORY https://github.com/bytecodealliance/wasm-micro-runtime
GIT_TAG WAMR-2.4.4
GIT_SHALLOW TRUE
)
# Populate separately so we can patch before building
FetchContent_GetProperties(wamr)
if(NOT wamr_POPULATED)
FetchContent_Populate(wamr)
# WAMR 2.4.4 win_file.c has trailing backslashes in comments that
# clang treats as line continuations, causing compile errors.
execute_process(
COMMAND git apply "${CMAKE_CURRENT_LIST_DIR}/wamr-fix-win-backslash-comments.patch"
WORKING_DIRECTORY "${wamr_SOURCE_DIR}"
RESULT_VARIABLE _patch_result
)
if(_patch_result)
message(WARNING "WAMR win_file.c patch failed (may already be applied)")
endif()
add_subdirectory("${wamr_SOURCE_DIR}" "${wamr_BINARY_DIR}" EXCLUDE_FROM_ALL)
if(WIN32)
# WAMR unconditionally adds -lm and -ldl as PUBLIC link libraries,
# which don't exist on Windows.
get_target_property(_vmlib_libs vmlib INTERFACE_LINK_LIBRARIES)
if(_vmlib_libs)
list(REMOVE_ITEM _vmlib_libs "-lm" "-ldl")
set_target_properties(vmlib PROPERTIES INTERFACE_LINK_LIBRARIES "${_vmlib_libs}")
endif()
# WAMR headers use __declspec(dllimport/dllexport) on MSVC-compatible
# compilers, but we link vmlib statically. Override both API macros to
# empty for vmlib itself (PUBLIC = PRIVATE + INTERFACE).
target_compile_definitions(vmlib PUBLIC
WASM_RUNTIME_API_EXTERN=
WASM_API_EXTERN=
)
endif()
endif()
+41
View File
@@ -0,0 +1,41 @@
cmake_minimum_required(VERSION 3.14)
set(WASI_SDK_VERSION "25")
set(WASI_SDK_FULL_VERSION "${WASI_SDK_VERSION}.0")
# Determine platform and architecture
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
set(WASI_SDK_PLATFORM "linux")
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
set(WASI_SDK_PLATFORM "macos")
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(WASI_SDK_PLATFORM "windows")
else()
message(FATAL_ERROR "Unsupported platform: ${CMAKE_HOST_SYSTEM_NAME}")
endif()
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64")
set(WASI_SDK_ARCH "x86_64")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64|arm64")
set(WASI_SDK_ARCH "arm64")
else()
message(FATAL_ERROR "Unsupported Linux architecture: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
endif()
set(WASI_SDK_BASE_URL "https://github.com/WebAssembly/wasi-sdk/releases/download")
set(WASI_SDK_FILENAME "wasi-sdk-${WASI_SDK_VERSION}.0-${WASI_SDK_ARCH}-${WASI_SDK_PLATFORM}")
set(WASI_SDK_URL "${WASI_SDK_BASE_URL}/wasi-sdk-${WASI_SDK_VERSION}/${WASI_SDK_FILENAME}.tar.gz")
set(FETCHCONTENT_QUIET FALSE)
include(FetchContent)
FetchContent_Declare(
WasiSDK
URL ${WASI_SDK_URL}
DOWNLOAD_EXTRACT_TIMESTAMP true
FIND_PACKAGE_ARGS
)
FetchContent_MakeAvailable(WasiSDK)
set(WASI_SDK_PATH ${wasisdk_SOURCE_DIR})
+47
View File
@@ -0,0 +1,47 @@
# FindWasiSDK.cmake
# Module to find WASI SDK installation
#
# This module defines the following variables:
# WasiSDK_FOUND - True if WASI SDK is found
# WasiSDK_ROOT_DIR - Root directory of WASI SDK installation
#
# Usage:
# set(WASI_SDK_PATH "/path/to/wasi-sdk")
# find_package(WasiSDK REQUIRED)
cmake_minimum_required(VERSION 3.10)
# Use WASI_SDK_PATH if provided, otherwise try to find it
if(WASI_SDK_PATH)
set(_wasi_sdk_search_paths "${WASI_SDK_PATH}")
else()
# Default search paths for common WASI SDK installations
set(_wasi_sdk_search_paths
"$ENV{WASI_SDK_PATH}"
"/opt/wasi-sdk"
)
endif()
# Find the WASI SDK root directory by looking for the toolchain file
find_path(WasiSDK_ROOT_DIR
NAMES share/cmake/wasi-sdk.cmake
PATHS ${_wasi_sdk_search_paths}
DOC "WASI SDK root directory"
NO_DEFAULT_PATH
)
# Handle find_package arguments
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(WasiSDK
DEFAULT_MSG
WasiSDK_ROOT_DIR
)
# Mark variables as advanced
mark_as_advanced(
WasiSDK_ROOT_DIR
)
if(WasiSDK_FOUND)
set(WASI_SDK_PATH ${WasiSDK_ROOT_DIR})
endif()
+4 -4
View File
@@ -39,24 +39,24 @@ include(FetchGtest)
add_custom_target(tests-radio
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/gtests-radio
DEPENDS gtests-radio
)
)
if(Qt6Core_FOUND AND NOT DISABLE_COMPANION)
add_subdirectory(${COMPANION_SRC_DIRECTORY})
add_custom_target(tests-companion
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/gtests-companion
DEPENDS gtests-companion
)
)
add_custom_target(gtests
DEPENDS gtests-radio gtests-companion
)
)
add_custom_target(tests
DEPENDS tests-radio tests-companion
)
else()
add_custom_target(gtests
DEPENDS gtests-radio
)
)
add_custom_target(tests
DEPENDS tests-radio
)
@@ -0,0 +1,29 @@
diff --git a/core/shared/platform/windows/win_file.c b/core/shared/platform/windows/win_file.c
index 55ea77a..df67705 100644
--- a/core/shared/platform/windows/win_file.c
+++ b/core/shared/platform/windows/win_file.c
@@ -1295,13 +1295,13 @@ os_readlinkat(os_file_handle handle, const char *path, char *buf,
if (wbufsize >= 4 && wbuf[0] == L'\\' && wbuf[1] == L'?'
&& wbuf[2] == L'?' && wbuf[3] == L'\\') {
- // Starts with \??\
+ // Has \??\ prefix
if (wbufsize >= 6
&& ((wbuf[4] >= L'A' && wbuf[4] <= L'Z')
|| (wbuf[4] >= L'a' && wbuf[4] <= L'z'))
&& wbuf[5] == L':' && (wbufsize == 6 || wbuf[6] == L'\\'))
{
- // \??\<drive>:\
+ // \??\<drive>:\ path
wbuf += 4;
wbufsize -= 4;
}
@@ -1310,7 +1310,7 @@ os_readlinkat(os_file_handle handle, const char *path, char *buf,
&& (wbuf[6] == L'C' || wbuf[6] == L'c')
&& wbuf[7] == L'\\')
{
- // \??\UNC\<server>\<share>\ - make sure the final path looks like \\<server>\<share>\
+ // \??\UNC\<server>\<share>\ - make sure the final path looks like \\<server>\<share>\ path
wbuf += 6;
wbuf[0] = L'\\';
wbufsize -= 6;