chore: cleanup WASM builds (#7196)

This commit is contained in:
Raphael Coeffic
2026-03-21 20:30:58 +10:00
committed by GitHub
parent 769e559837
commit 4c4cb2c31b
11 changed files with 184 additions and 83 deletions
+2 -2
View File
@@ -1,5 +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)
MESSAGE_NEVER
FILES_MATCHING PATTERN "edgetx-*-simulator.wasm")
+28 -2
View File
@@ -80,7 +80,7 @@ function(GenerateDatacopy source output)
add_custom_command(
OUTPUT ${output}
COMMAND ${GEN_DATACOPY_CMD} > ${output}
DEPENDS ${GEN_DATACOPY_DEPEND}
DEPENDS ${GEN_DATACOPY_DEPEND} ${CMAKE_BINARY_DIR}/CMakeCache.txt
)
endfunction()
@@ -128,7 +128,8 @@ function(AddHWGenTarget input template output)
add_custom_command(OUTPUT ${output}
COMMAND ${GEN_JSON} > ${output}
DEPENDS ${INPUT_JSON} ${TEMPLATE} ${GEN_PY_DEPS})
DEPENDS ${INPUT_JSON} ${TEMPLATE} ${GEN_PY_DEPS} ${CMAKE_BINARY_DIR}/CMakeCache.txt
)
endfunction()
macro(AddHeadersSources)
@@ -146,3 +147,28 @@ macro(AddHeadersSources)
)
endforeach()
endmacro()
# Collect all user-specified command-line cache variables into a list
# suitable for forwarding to ExternalProject or sub-project cmake invocations.
# Optional EXCLUDE parameter: regex to skip matching variable names.
function(CollectCommandLineArgs out_var)
cmake_parse_arguments(_cla "" "EXCLUDE" "" ${ARGN})
set(_args "")
get_cmake_property(_cache_vars CACHE_VARIABLES)
foreach(_var ${_cache_vars})
if(_cla_EXCLUDE AND _var MATCHES "${_cla_EXCLUDE}")
continue()
endif()
get_property(_help CACHE ${_var} PROPERTY HELPSTRING)
if(_help STREQUAL "No help, variable specified on the command line.")
get_property(_type CACHE ${_var} PROPERTY TYPE)
if(_type STREQUAL "UNINITIALIZED")
set(_type)
else()
set(_type :${_type})
endif()
list(APPEND _args "-D${_var}${_type}=${${_var}}")
endif()
endforeach()
set(${out_var} ${_args} PARENT_SCOPE)
endfunction()
+1 -1
View File
@@ -48,7 +48,7 @@ if(Qt6_FOUND)
list(APPEND APP_COMMON_DEFINES -D__STDC_LIMIT_MACROS)
endif()
if(APP_CUSTOM_DBG_HANDLER)
# provide full qDebug log context to our custom handler. This may also affect libsimulator, which is why it is here
# provide full qDebug log context to our custom handler.
list(APPEND APP_COMMON_DEFINES -DQT_MESSAGELOGCONTEXT)
list(APPEND APP_COMMON_DEFINES -DAPP_DBG_HANDLER_ENABLE=1)
if(APP_CUSTOM_DBG_LEVEL GREATER -1 AND APP_CUSTOM_DBG_LEVEL LESS 5)
+20
View File
@@ -0,0 +1,20 @@
# Wrapper around wasi-sdk's pthread toolchain that uses the non-deprecated
# wasm32-wasip1-threads triple (compatible with SDK 25+).
# Propagate WASI_SDK_PREFIX into try_compile sub-projects (used during ABI detection)
list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES WASI_SDK_PREFIX)
if(NOT WASI_SDK_PREFIX)
if(DEFINED ENV{WASI_SDK_PATH})
set(WASI_SDK_PREFIX $ENV{WASI_SDK_PATH})
elseif(EXISTS "/opt/wasi-sdk")
set(WASI_SDK_PREFIX "/opt/wasi-sdk")
endif()
endif()
include(${WASI_SDK_PREFIX}/share/cmake/wasi-sdk-pthread.cmake)
set(triple wasm32-wasip1-threads)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER_TARGET ${triple})
set(CMAKE_ASM_COMPILER_TARGET ${triple})
+48
View File
@@ -0,0 +1,48 @@
# Standalone CMake project for building WASM simulator modules.
# Invoked on-demand by the superbuild's wasi-module target so that
# the WASI SDK is only fetched when WASM targets are actually built.
#
# Usage from superbuild:
# cmake -S . -B build -DPCB=X10 -DPCBREV=TX16S
# cmake --build build --target wasi-module
cmake_minimum_required(VERSION 3.21)
project(EdgeTX-WASM NONE) # NONE = no compiler check (we set a toolchain below)
# Inherit the module path from the main project
list(APPEND CMAKE_MODULE_PATH "${EDGETX_SOURCE_DIR}/cmake")
# Collect command-line args to forward, excluding EDGETX_* (consumed here)
include(Macros)
CollectCommandLineArgs(_forwarded_args EXCLUDE "^EDGETX_")
# Fetch / find WASI SDK
include(FetchWasiSDK)
find_package(WasiSDK REQUIRED)
include(ExternalProject)
ExternalProject_Add(wasm
SOURCE_DIR ${EDGETX_SOURCE_DIR}
BINARY_DIR ${CMAKE_BINARY_DIR}/wasm-build
CMAKE_ARGS
${_forwarded_args}
-Wno-dev
-DCMAKE_BUILD_TYPE=${EDGETX_BUILD_TYPE}
-DWASI_SDK_PREFIX=${WASI_SDK_PATH}
-DCMAKE_TOOLCHAIN_FILE=${EDGETX_SOURCE_DIR}/cmake/toolchain/wasi-threads.cmake
CMAKE_CACHE_ARGS
-DEdgeTX_SUPERBUILD:BOOL=0
-DNATIVE_BUILD:BOOL=1
-DDISABLE_COMPANION:BOOL=1
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target wasi-module
INSTALL_COMMAND ""
)
# Copy .wasm files up after build
ExternalProject_Add_Step(wasm copy-wasm
DEPENDEES build
COMMAND ${CMAKE_COMMAND}
-DSRC_DIR=${CMAKE_BINARY_DIR}/wasm-build -DDST_DIR=${CMAKE_BINARY_DIR}
-P ${EDGETX_SOURCE_DIR}/cmake/CopyWasmModules.cmake
)