接入 task HAL Web 仿真运行时

This commit is contained in:
2026-06-22 06:11:55 +08:00
parent 3771b9eafe
commit bd11a5f8d6
42 changed files with 5574 additions and 50 deletions

View File

@@ -0,0 +1,58 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
WRAP_DIR="$ROOT_DIR/runtime/core/linuxcnc_wrap"
SHIM_DIR="$ROOT_DIR/runtime/core/shims"
INCLUDE_DIR="$ROOT_DIR/runtime/core/include"
OUT_DIR="$ROOT_DIR/build/wasm/task-hal"
OBJ_DIR="$OUT_DIR/obj"
source "$ROOT_DIR/tools/wasm_incremental_build_lib.sh"
mkdir -p "$OUT_DIR" "$OBJ_DIR"
TARGET="linuxcnc_task_hal_wasm"
: > "$OUT_DIR/$TARGET.stdout.log"
: > "$OUT_DIR/$TARGET.stderr.log"
COMMON_FLAGS=(
-O2
-D_GNU_SOURCE
-I"$WRAP_DIR"
-I"$SHIM_DIR"
-I"$INCLUDE_DIR"
)
SOURCES=(
"$WRAP_DIR/linuxcnc_hal_runtime.cpp"
"$WRAP_DIR/linuxcnc_motion_runtime.c"
"$WRAP_DIR/linuxcnc_task_hal_wasm.cpp"
)
OBJECTS=()
for source in "${SOURCES[@]}"; do
obj="$(source_object_path "$source" "$ROOT_DIR" "$OBJ_DIR")"
OBJECTS+=("$obj")
if [[ "$source" == *.c ]]; then
compile_wasm_object "$TARGET" "$source" "$obj" "$OUT_DIR" -std=c11 "${COMMON_FLAGS[@]}"
else
compile_wasm_object "$TARGET" "$source" "$obj" "$OUT_DIR" -std=c++20 "${COMMON_FLAGS[@]}"
fi
done
link_wasm_module \
"$TARGET" \
"$OUT_DIR/linuxcnc_task_hal.js" \
"$OUT_DIR" \
-O2 \
"${OBJECTS[@]}" \
-s MODULARIZE=1 \
-s EXPORT_ES6=1 \
-s ENVIRONMENT=web,node \
-s ALLOW_MEMORY_GROWTH=1 \
-s NO_EXIT_RUNTIME=1 \
-s EXPORTED_FUNCTIONS='["_malloc","_free","_hal_init","_hal_ready","_hal_exit","_hal_malloc","_hal_pin_bit_new","_hal_pin_float_new","_hal_pin_s32_new","_hal_pin_u32_new","_hal_pin_s64_new","_hal_pin_u64_new","_hal_pin_bit_newf","_hal_pin_float_newf","_hal_pin_s32_newf","_hal_pin_u32_newf","_hal_pin_s64_newf","_hal_pin_u64_newf","_hal_param_bit_new","_hal_param_float_new","_hal_param_s32_new","_hal_param_u32_new","_hal_param_s64_new","_hal_param_u64_new","_hal_param_bit_newf","_hal_param_float_newf","_hal_param_s32_newf","_hal_param_u32_newf","_hal_param_s64_newf","_hal_param_u64_newf","_hal_get_pin_value_by_name","_hal_get_signal_value_by_name","_hal_get_param_value_by_name","_hal_link","_hal_unlink","_hal_set_p","_hal_get_p","_hal_create_thread","_hal_add_funct_to_thread","_hal_del_funct_from_thread","_hal_start_threads","_hal_stop_threads","_lchal_init_runtime","_lchal_load_hal_file","_lchal_set_pin_float","_lchal_set_pin_s32","_lchal_set_pin_bit","_lchal_get_pin_json","_lchal_get_snapshot_json","_lchal_step_threads","_lchal_reset_runtime","_lcmot_init_from_ini","_lcmot_write_command_json","_lcmot_step_servo","_lcmot_read_status_json","_lcmot_read_hal_snapshot_json","_lcmot_reset","_lctask_init_session","_lctask_stage_file","_lctask_open_program","_lctask_send_command_json","_lctask_run_cycles","_lctask_read_status_json","_lctask_read_events_json","_lctask_reset_session"]' \
-s EXPORTED_RUNTIME_METHODS='["UTF8ToString","stringToUTF8","lengthBytesUTF8","getValue","setValue"]'
echo "linuxcnc_task_hal_wasm_build=ok"

View File

@@ -0,0 +1,28 @@
# LinuxCNC task / motion / HAL source references for future task-HAL runtime.
#
# This manifest is intentionally separate from source-manifest.txt. The main
# source manifest is tied to current native source-probe coverage; these files
# are Phase 0 references for the future task/HAL runtime boundary and must not
# be treated as promoted runtime coverage until the task/HAL WASM/native/browser
# gates exist.
src/emc/task/task.hh
src/emc/task/taskclass.hh
src/emc/task/taskclass.cc
src/emc/task/emctask.cc
src/emc/task/emctaskmain.cc
src/emc/task/taskintf.cc
src/emc/task/emccanon.cc
src/emc/nml_intf/emc.hh
src/libnml/posemath/posemath.h
src/libnml/posemath/posemath.cc
src/emc/motion/usrmotintf.h
src/emc/motion/motion.h
src/emc/motion/motion.c
src/emc/motion/command.c
src/emc/motion/control.c
src/emc/motion/mot_priv.h
src/hal/hal_lib.c
src/hal/hal_priv.h
src/hal/components/threads.c
src/hal/utils/halcmd_commands.cc

View File

@@ -0,0 +1,150 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
LINUXCNC_ROOT="${LINUXCNC_ROOT:-$ROOT_DIR/../linuxcnc}"
VENDOR_ROOT="$ROOT_DIR/vendor/linuxcnc"
MANIFEST="$ROOT_DIR/tools/task-hal-source-manifest.txt"
BUILD_DIR="$ROOT_DIR/build/task-hal"
REPORT="$BUILD_DIR/task-hal-source-manifest.tsv"
mkdir -p "$BUILD_DIR"
print_kv() {
printf '%s=%s\n' "$1" "$2"
}
if [[ ! -f "$MANIFEST" ]]; then
print_kv task_hal_source_manifest_status missing_manifest
print_kv task_hal_source_manifest_path "$MANIFEST"
exit 1
fi
tmp="$(mktemp "$BUILD_DIR/task-hal-source-manifest.XXXXXX.tsv")"
trap 'rm -f "$tmp"' EXIT
printf '%s\t%s\t%s\t%s\t%s\n' \
source_rel \
reference_exists \
vendor_exists \
vendor_hash_matches \
boundary > "$tmp"
source_count=0
task_source_count=0
hal_source_count=0
motion_source_count=0
nml_source_count=0
libnml_source_count=0
reference_ready=1
vendor_ready=1
vendor_match_ready=1
missing_reference=()
missing_vendor=()
mismatched_vendor=()
while IFS= read -r source_rel; do
[[ -z "$source_rel" || "$source_rel" =~ ^[[:space:]]*# ]] && continue
source_count=$((source_count + 1))
case "$source_rel" in
src/emc/task/*)
task_source_count=$((task_source_count + 1))
;;
src/hal/*)
hal_source_count=$((hal_source_count + 1))
;;
src/emc/motion/*)
motion_source_count=$((motion_source_count + 1))
;;
src/emc/nml_intf/*)
nml_source_count=$((nml_source_count + 1))
;;
src/libnml/*)
libnml_source_count=$((libnml_source_count + 1))
;;
esac
reference_file="$LINUXCNC_ROOT/$source_rel"
vendor_file="$VENDOR_ROOT/$source_rel"
reference_exists=0
vendor_exists=0
vendor_hash_matches=0
if [[ -f "$reference_file" ]]; then
reference_exists=1
else
reference_ready=0
missing_reference+=("$source_rel")
fi
if [[ -f "$vendor_file" ]]; then
vendor_exists=1
else
vendor_ready=0
missing_vendor+=("$source_rel")
fi
if [[ "$reference_exists" == "1" && "$vendor_exists" == "1" ]]; then
if cmp -s "$reference_file" "$vendor_file"; then
vendor_hash_matches=1
else
vendor_match_ready=0
mismatched_vendor+=("$source_rel")
fi
elif [[ "$vendor_exists" != "1" ]]; then
vendor_hash_matches=0
fi
printf '%s\t%s\t%s\t%s\t%s\n' \
"$source_rel" \
"$reference_exists" \
"$vendor_exists" \
"$vendor_hash_matches" \
"phase0_reference_only_not_runtime_promoted" >> "$tmp"
done < "$MANIFEST"
mv -f "$tmp" "$REPORT"
trap - EXIT
join_csv() {
local IFS=,
printf '%s' "$*"
}
print_kv task_hal_source_manifest_status ok
print_kv task_hal_source_manifest_ready "$(( source_count > 0 && reference_ready == 1 ? 1 : 0 ))"
print_kv task_hal_source_manifest_path "$MANIFEST"
print_kv task_hal_source_manifest_report "$REPORT"
print_kv task_hal_source_count "$source_count"
print_kv task_source_count "$task_source_count"
print_kv hal_source_count "$hal_source_count"
print_kv motion_source_count "$motion_source_count"
print_kv nml_source_count "$nml_source_count"
print_kv libnml_source_count "$libnml_source_count"
print_kv task_hal_reference_source_ready "$reference_ready"
print_kv task_hal_vendor_source_ready "$vendor_ready"
print_kv task_hal_vendor_hash_match_ready "$vendor_match_ready"
print_kv task_hal_missing_reference_source_count "${#missing_reference[@]}"
print_kv task_hal_missing_reference_sources_ready "$(( ${#missing_reference[@]} == 0 ? 1 : 0 ))"
if [[ "${#missing_reference[@]}" -gt 0 ]]; then
print_kv task_hal_missing_reference_source_list "$(join_csv "${missing_reference[@]}")"
else
print_kv task_hal_missing_reference_source_list "-"
fi
if [[ "${#missing_vendor[@]}" -gt 0 ]]; then
print_kv task_hal_missing_vendor_source_list "$(join_csv "${missing_vendor[@]}")"
else
print_kv task_hal_missing_vendor_source_list "-"
fi
if [[ "${#mismatched_vendor[@]}" -gt 0 ]]; then
print_kv task_hal_mismatched_vendor_source_list "$(join_csv "${mismatched_vendor[@]}")"
else
print_kv task_hal_mismatched_vendor_source_list "-"
fi
print_kv task_hal_runtime_promoted 0
print_kv nativeTaskReady false
print_kv nativeHalSyncReady false
if [[ "$source_count" -eq 0 || "$reference_ready" != "1" ]]; then
exit 1
fi