Files
wasm-simulator/test-linuxcnc-wasm-rs274ngc-pre-link-blockers.sh
cnc 40a63c76f7 高效率推进 LinuxCNC 源码对齐流程
说明:集中 LinuxCNC 源码清单与 wasm/native probe 的路径解析,补强 manifest、shim、source-link 检查,并保持 LinuxCNC 源码后端对齐验证流程可复用。

验证:./test-native.sh;./test-linuxcnc-source-link.sh;./test-all-native.sh;wasm source/probe 相关脚本。
2026-05-27 11:14:06 +08:00

143 lines
5.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
linuxcnc_root=${LINUXCNC_ROOT:-../linuxcnc}
cxx=${CXX:-g++}
build_dir=$(mktemp -d "${TMPDIR:-/tmp}/cnc_sim_linuxcnc_wasm_rs274ngc_pre_link_blockers.XXXXXX")
report_file=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_linuxcnc_wasm_rs274ngc_pre_undefined.XXXXXX.txt")
manifest=${1:-linuxcnc-rs274-wasm-source-files.txt}
if [[ ! -f "$manifest" ]]; then
echo "missing manifest: $manifest" >&2
exit 1
fi
if [[ ! -d "$linuxcnc_root" ]]; then
echo "missing LinuxCNC root: $linuxcnc_root" >&2
exit 1
fi
trap 'rm -rf "$build_dir"' EXIT
common_flags=(
-std=c++20
-DULAPI
-ffunction-sections
-fdata-sections
-include wctype.h
-I "$(pwd)/core/include"
-I "$(pwd)/core/wasm_shims"
-I "$linuxcnc_root/src"
-I "$linuxcnc_root/src/emc"
-I "$linuxcnc_root/src/emc/nml_intf"
-I "$linuxcnc_root/src/emc/rs274ngc"
-I "$linuxcnc_root/src/emc/motion"
-I "$linuxcnc_root/include"
)
shim_list="$build_dir/wasm_safe_shims.txt"
./list-linuxcnc-wasm-safe-shims.sh > "$shim_list"
mapfile -t shim_sources < "$shim_list"
project_source_list="$build_dir/wasm_safe_project_sources.txt"
./list-linuxcnc-wasm-safe-project-sources.sh > "$project_source_list"
mapfile -t project_sources < "$project_source_list"
linuxcnc_sources=()
source_list="$build_dir/wasm_core_sources.txt"
LINUXCNC_ROOT="$linuxcnc_root" ./list-linuxcnc-wasm-manifest-sources.sh "$manifest" core full > "$source_list"
mapfile -t linuxcnc_sources < "$source_list"
shim_index=0
for source in "${shim_sources[@]}"; do
obj="$build_dir/shim_${shim_index}.o"
"$cxx" "${common_flags[@]}" -c "$source" -o "$obj"
shim_index=$((shim_index + 1))
done
project_index=0
for source in "${project_sources[@]}"; do
obj="$build_dir/project_${project_index}.o"
"$cxx" "${common_flags[@]}" -c "$source" -o "$obj"
project_index=$((project_index + 1))
done
linuxcnc_index=0
for source in "${linuxcnc_sources[@]}"; do
obj="$build_dir/linuxcnc_${linuxcnc_index}.o"
"$cxx" "${common_flags[@]}" -c "$source" -o "$obj"
linuxcnc_index=$((linuxcnc_index + 1))
done
undefined_file="$build_dir/undefined.raw"
defined_file="$build_dir/defined.raw"
nm -u "$build_dir"/*.o \
| awk '{print $2}' \
| sed '/^$/d' \
| LC_ALL=C sort -u \
> "$undefined_file"
nm --defined-only "$build_dir"/*.o \
| awk '{print $3}' \
| sed '/^$/d' \
| LC_ALL=C sort -u \
> "$defined_file"
{
comm -23 "$undefined_file" "$defined_file" \
| grep -Ev '^(_GLOBAL_OFFSET_TABLE_|_Unwind_Resume)$' \
| grep -Ev '^(__assert_fail|__cxa_|__divdc3|__dso_handle|__errno_location|__gxx_personality_v0|__isoc23_|__muldc3|__stack_chk_fail)' \
| grep -Ev '^(abort|access|acos|asin|atan2|atof|atoi|basename|cabs|calloc|ceil|close|closedir|copysign|cos|cosl|exit|exp|fclose|fdatasync|fdopen|feof|fflush|fgetc|fgets|fileno|floor|fmod|fopen|fprintf|fputs|free|freelocale|fseek|fstat|ftell|fwrite|getcwd|getenv|getpid|gettimeofday|hypot|islower|isprint|isspace|isupper|isxdigit|link|localtime|log|lstat|malloc|memchr|memcmp|memcpy|memmove|memset|mkstemp|nearbyint|newlocale|open|opendir|perror|pow|printf|pthread_mutex_lock|pthread_mutex_unlock|putc|puts|read|readdir|realpath|realloc|remove|rename|setlocale|sin|sinl|snprintf|sprintf|sqrt|sscanf|stat|stderr|stdout|strcasecmp|strcat|strchr|strcmp|strcpy|strdup|strerror|strlen|strncasecmp|strncat|strncmp|strncpy|strrchr|strspn|strstr|strtod|strtok_r|strtol|strtoul|tan|tanl|tolower|toupper|towlower|unlink|uselocale|vfprintf|vsnprintf|wordexp|wordfree)$' \
| grep -Ev '^(_ZN3fmt|_ZSt|_ZNSt|_ZNKSt|_ZNKRSt|_ZNS|_ZTI|_ZTS|_ZTV|_Zdl|_Znwm|_Znam|_Zda|_ZdaPv|_ZdaPvm|_ZdlPvm|_ZTv|_ZTh)'
} > "$report_file" || true
if grep -F "_ZN6Interp13read_commentEPcPiP12block_structPd" "$report_file" >/dev/null; then
echo "unexpected unresolved read_comment after interp_read.cc" >&2
exit 1
fi
if grep -F "_ZN6Interp15find_tool_indexEP5setupiPi" "$report_file" >/dev/null; then
echo "unexpected unresolved find_tool_index after interp_find.cc" >&2
exit 1
fi
if grep -F "_ZN6Interp16find_named_paramEPKcPiPd" "$report_file" >/dev/null; then
echo "unexpected unresolved find_named_param after interp_namedparams.cc" >&2
exit 1
fi
if grep -Fx "emcStatus" "$report_file" >/dev/null; then
echo "unexpected unresolved emcStatus after shim" >&2
exit 1
fi
if grep -Fx "gettext" "$report_file" >/dev/null; then
echo "unexpected unresolved gettext after shim" >&2
exit 1
fi
if grep -Fx "_task" "$report_file" >/dev/null; then
echo "unexpected unresolved _task after runtime shim" >&2
exit 1
fi
if grep -Fx "builtin_modules" "$report_file" >/dev/null; then
echo "unexpected unresolved builtin_modules after runtime shim" >&2
exit 1
fi
for hal_symbol in \
hal_get_param_value_by_name \
hal_get_pin_value_by_name \
hal_get_signal_value_by_name \
hal_init \
hal_ready; do
if grep -Fx "$hal_symbol" "$report_file" >/dev/null; then
echo "unexpected unresolved $hal_symbol after runtime shim" >&2
exit 1
fi
done
if [[ -s "$report_file" ]]; then
echo "unexpected unresolved project symbols after rs274ngc_pre shim coverage:" >&2
sed -n '1,120p' "$report_file" >&2
exit 1
fi
echo "linuxcnc wasm rs274ngc_pre link blocker scan passed"
echo "wrote $report_file"