Harden LinuxCNC wasm and native probe workflows
This commit is contained in:
@@ -3,7 +3,13 @@ project(cnc_sim_wasm_core LANGUAGES CXX)
|
||||
|
||||
option(CNC_SIM_ENABLE_LINUXCNC_BRIDGE "Build the experimental LinuxCNC canon bridge" OFF)
|
||||
option(CNC_SIM_ENABLE_LINUXCNC_RS274_BACKEND "Build the native LinuxCNC librs274 backend" OFF)
|
||||
option(CNC_SIM_ENABLE_LINUXCNC_WASM_SAFE_PROBE "Compile the browser-safe subset of LinuxCNC rs274 sources" OFF)
|
||||
set(CNC_SIM_LINUXCNC_ROOT "" CACHE PATH "LinuxCNC source root for the experimental bridge")
|
||||
set(CNC_SIM_LINUXCNC_WASM_SOURCE_MANIFEST
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../linuxcnc-rs274-wasm-source-files.txt"
|
||||
CACHE FILEPATH
|
||||
"Manifest that partitions LinuxCNC rs274 sources into wasm-safe core and blocked groups"
|
||||
)
|
||||
|
||||
set(cnc_sim_core_sources
|
||||
src/canon_event_sink.cpp
|
||||
@@ -28,6 +34,137 @@ if(CNC_SIM_ENABLE_LINUXCNC_RS274_BACKEND)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CNC_SIM_ENABLE_LINUXCNC_WASM_SAFE_PROBE)
|
||||
if(NOT CNC_SIM_LINUXCNC_ROOT)
|
||||
message(FATAL_ERROR "Set CNC_SIM_LINUXCNC_ROOT to the LinuxCNC source root")
|
||||
endif()
|
||||
get_filename_component(CNC_SIM_LINUXCNC_ROOT_ABS
|
||||
"${CNC_SIM_LINUXCNC_ROOT}"
|
||||
ABSOLUTE
|
||||
BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.."
|
||||
)
|
||||
if(NOT IS_DIRECTORY "${CNC_SIM_LINUXCNC_ROOT_ABS}")
|
||||
message(FATAL_ERROR "LinuxCNC source root does not exist: ${CNC_SIM_LINUXCNC_ROOT_ABS}")
|
||||
endif()
|
||||
if(NOT EXISTS "${CNC_SIM_LINUXCNC_WASM_SOURCE_MANIFEST}")
|
||||
message(FATAL_ERROR "Missing LinuxCNC wasm source manifest: ${CNC_SIM_LINUXCNC_WASM_SOURCE_MANIFEST}")
|
||||
endif()
|
||||
if(IS_DIRECTORY "${CNC_SIM_LINUXCNC_WASM_SOURCE_MANIFEST}")
|
||||
message(FATAL_ERROR "LinuxCNC wasm source manifest is not a file: ${CNC_SIM_LINUXCNC_WASM_SOURCE_MANIFEST}")
|
||||
endif()
|
||||
|
||||
set(linuxcnc_wasm_safe_probe_sources)
|
||||
set(linuxcnc_wasm_blocked_sources)
|
||||
file(STRINGS "${CNC_SIM_LINUXCNC_WASM_SOURCE_MANIFEST}" linuxcnc_wasm_manifest_lines)
|
||||
foreach(manifest_line IN LISTS linuxcnc_wasm_manifest_lines)
|
||||
string(STRIP "${manifest_line}" manifest_line)
|
||||
if(manifest_line STREQUAL "" OR manifest_line MATCHES "^#")
|
||||
continue()
|
||||
endif()
|
||||
if(NOT manifest_line MATCHES "^([^:]+):([^:]+):(.*)$")
|
||||
message(FATAL_ERROR "Bad LinuxCNC wasm source manifest line: ${manifest_line}")
|
||||
endif()
|
||||
|
||||
set(manifest_group "${CMAKE_MATCH_1}")
|
||||
set(manifest_path "${CMAKE_MATCH_2}")
|
||||
if(NOT manifest_group STREQUAL "core" AND NOT manifest_group STREQUAL "blocked")
|
||||
message(FATAL_ERROR "Unknown LinuxCNC wasm source manifest group: ${manifest_group}")
|
||||
endif()
|
||||
|
||||
set(manifest_source "${CNC_SIM_LINUXCNC_ROOT_ABS}/${manifest_path}")
|
||||
if(NOT EXISTS "${manifest_source}")
|
||||
message(FATAL_ERROR "LinuxCNC wasm manifest source does not exist: ${manifest_source}")
|
||||
endif()
|
||||
if(IS_DIRECTORY "${manifest_source}")
|
||||
message(FATAL_ERROR "LinuxCNC wasm manifest source is not a file: ${manifest_source}")
|
||||
endif()
|
||||
|
||||
if(manifest_group STREQUAL "core")
|
||||
list(APPEND linuxcnc_wasm_safe_probe_sources "${manifest_source}")
|
||||
else()
|
||||
list(APPEND linuxcnc_wasm_blocked_sources "${manifest_source}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
list(LENGTH linuxcnc_wasm_safe_probe_sources linuxcnc_wasm_safe_probe_source_count)
|
||||
list(LENGTH linuxcnc_wasm_blocked_sources linuxcnc_wasm_blocked_source_count)
|
||||
if(linuxcnc_wasm_safe_probe_source_count EQUAL 0)
|
||||
message(FATAL_ERROR "LinuxCNC wasm source manifest has no core entries")
|
||||
endif()
|
||||
if(linuxcnc_wasm_blocked_source_count EQUAL 0)
|
||||
message(FATAL_ERROR "LinuxCNC wasm source manifest has no blocked entries")
|
||||
endif()
|
||||
message(STATUS "LinuxCNC wasm-safe core sources: ${linuxcnc_wasm_safe_probe_source_count}")
|
||||
message(STATUS "LinuxCNC wasm blocked sources: ${linuxcnc_wasm_blocked_source_count}")
|
||||
|
||||
set(linuxcnc_wasm_safe_probe_shims
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims/dlfcn.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims/emc_status_shim.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims/gettext_shim.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims/linuxcnc_runtime_shim.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims/python_c_api_shim.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims/rtapi_compat.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims/tooldata/tooldata_mmap_backend.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims/tooldata/tooldata_runtime_stubs.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims/pythonplugin/python_plugin.cc
|
||||
)
|
||||
|
||||
add_library(linuxcnc_rs274_wasm_safe_probe_objects OBJECT
|
||||
${linuxcnc_wasm_safe_probe_shims}
|
||||
${linuxcnc_wasm_safe_probe_sources}
|
||||
)
|
||||
target_compile_features(linuxcnc_rs274_wasm_safe_probe_objects PUBLIC cxx_std_20)
|
||||
target_compile_definitions(linuxcnc_rs274_wasm_safe_probe_objects PRIVATE ULAPI)
|
||||
target_compile_options(linuxcnc_rs274_wasm_safe_probe_objects PRIVATE -include wctype.h)
|
||||
target_include_directories(linuxcnc_rs274_wasm_safe_probe_objects
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims
|
||||
${CNC_SIM_LINUXCNC_ROOT_ABS}/src
|
||||
${CNC_SIM_LINUXCNC_ROOT_ABS}/src/emc
|
||||
${CNC_SIM_LINUXCNC_ROOT_ABS}/src/emc/nml_intf
|
||||
${CNC_SIM_LINUXCNC_ROOT_ABS}/src/emc/rs274ngc
|
||||
${CNC_SIM_LINUXCNC_ROOT_ABS}/src/emc/motion
|
||||
${CNC_SIM_LINUXCNC_ROOT_ABS}/include
|
||||
)
|
||||
|
||||
set(linuxcnc_rs274_wasm_safe_probe_project_sources
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/canon_event_sink.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/linuxcnc_canon_bridge.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/linuxcnc_tooldata_fixture.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/rtcp_kinematics.cpp
|
||||
)
|
||||
|
||||
add_executable(linuxcnc_rs274_wasm_safe_probe EXCLUDE_FROM_ALL
|
||||
$<TARGET_OBJECTS:linuxcnc_rs274_wasm_safe_probe_objects>
|
||||
${linuxcnc_rs274_wasm_safe_probe_project_sources}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims/rs274ngc_pre_probe_main.cc
|
||||
)
|
||||
target_compile_features(linuxcnc_rs274_wasm_safe_probe PRIVATE cxx_std_20)
|
||||
target_compile_definitions(linuxcnc_rs274_wasm_safe_probe PRIVATE ULAPI)
|
||||
target_compile_options(linuxcnc_rs274_wasm_safe_probe PRIVATE -include wctype.h)
|
||||
target_include_directories(linuxcnc_rs274_wasm_safe_probe
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm_shims
|
||||
${CNC_SIM_LINUXCNC_ROOT_ABS}/src
|
||||
${CNC_SIM_LINUXCNC_ROOT_ABS}/src/emc
|
||||
${CNC_SIM_LINUXCNC_ROOT_ABS}/src/emc/nml_intf
|
||||
${CNC_SIM_LINUXCNC_ROOT_ABS}/src/emc/rs274ngc
|
||||
${CNC_SIM_LINUXCNC_ROOT_ABS}/src/emc/motion
|
||||
${CNC_SIM_LINUXCNC_ROOT_ABS}/include
|
||||
)
|
||||
target_link_libraries(linuxcnc_rs274_wasm_safe_probe PRIVATE fmt)
|
||||
|
||||
if(linuxcnc_wasm_blocked_sources)
|
||||
add_custom_target(linuxcnc_rs274_wasm_blocked_sources
|
||||
SOURCES ${linuxcnc_wasm_blocked_sources}
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_library(cnc_sim_objects OBJECT
|
||||
${cnc_sim_core_sources}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user