From fc56b11d8f3ac4d2253875f043afb15f026bb59a Mon Sep 17 00:00:00 2001 From: cnc Date: Sat, 6 Jun 2026 12:40:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E6=BA=90=E9=93=BE=E6=8E=A5Python?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E6=8E=A2=E9=92=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 结论:依据 LinuxCNC canonmodule.cc、interpmodule.cc 与 py*.cc,新增 Python binding link probe,证明 7 个 non-gcodemodule blocked binding 对象可与 inert Python/runtime shims 链接;同时负向锁定 gcodemodule.cc 与浏览器 runtime canon bridge 的 Canon 回调重定义冲突,Python/remap 执行仍禁用,未扩展 smoke。 检查:./test-linuxcnc-wasm-python-binding-link.sh;./test-linuxcnc-wasm-python-c-api-symbols.sh;./test-linuxcnc-wasm-runtime-link.sh;git diff --check;./test-native.sh;./test-linuxcnc-source-link.sh。 --- build-wasm.sh | 1 + test-linuxcnc-wasm-python-binding-link.sh | 94 +++++++++++++++++++++++ test-native.sh | 2 + 3 files changed, 97 insertions(+) create mode 100755 test-linuxcnc-wasm-python-binding-link.sh diff --git a/build-wasm.sh b/build-wasm.sh index e92c405..cb92e6c 100755 --- a/build-wasm.sh +++ b/build-wasm.sh @@ -144,6 +144,7 @@ run_parallel_wasm_probe "LinuxCNC wasm interp_base link probe" ./test-linuxcnc-w run_parallel_wasm_probe "LinuxCNC wasm interp_find link probe" ./test-linuxcnc-wasm-interp-find-link.sh run_parallel_wasm_probe "LinuxCNC wasm python_plugin link probe" ./test-linuxcnc-wasm-python-plugin-link.sh run_parallel_wasm_probe "LinuxCNC wasm Python C API symbol probe" ./test-linuxcnc-wasm-python-c-api-symbols.sh +run_parallel_wasm_probe "LinuxCNC wasm Python binding link probe" ./test-linuxcnc-wasm-python-binding-link.sh run_parallel_wasm_probe "LinuxCNC wasm rs274ngc_pre object probe" ./test-linuxcnc-wasm-rs274ngc-pre-object.sh wait_parallel_wasm_probes diff --git a/test-linuxcnc-wasm-python-binding-link.sh b/test-linuxcnc-wasm-python-binding-link.sh new file mode 100755 index 0000000..8d461f9 --- /dev/null +++ b/test-linuxcnc-wasm-python-binding-link.sh @@ -0,0 +1,94 @@ +#!/usr/bin/env bash +set -euo pipefail + +cd "$(dirname "$0")" + +# LinuxCNC source basis: src/emc/rs274ngc/canonmodule.cc, interpmodule.cc, +# and py*.cc are blocked Python/Boost.Python binding sources. This probe links +# the non-gcodemodule binding objects against inert Python/runtime shims, while +# keeping src/emc/rs274ngc/gcodemodule.cc isolated because it defines Canon +# callbacks that collide with the browser runtime bridge. +manifest=${1:-linuxcnc-rs274-wasm-source-files.txt} + +preflight_cache_dir=${CNC_SIM_PREFLIGHT_CACHE_DIR:-build/wasm-probe-preflight-cache} +python_build_dir=${CNC_SIM_WASM_PYTHON_C_API_BUILD_DIR:-build/wasm-python-c-api-symbols} +if [[ -z "$python_build_dir" ]]; then + echo "CNC_SIM_WASM_PYTHON_C_API_BUILD_DIR must not be empty" >&2 + exit 1 +fi +if [[ "$python_build_dir" =~ [[:space:]] ]]; then + echo "CNC_SIM_WASM_PYTHON_C_API_BUILD_DIR must not contain whitespace: $python_build_dir" >&2 + exit 1 +fi +mkdir -p "$python_build_dir" +python_build_dir=$(cd "$python_build_dir" && pwd) +if [[ "$python_build_dir" == "/" ]]; then + echo "CNC_SIM_WASM_PYTHON_C_API_BUILD_DIR must not be the filesystem root" >&2 + exit 1 +fi +exec 9>"$python_build_dir/python-binding-link.lock" +flock 9 + +CNC_SIM_PREFLIGHT_CACHE_DIR="$preflight_cache_dir" \ + CNC_SIM_WASM_PYTHON_C_API_BUILD_DIR="$python_build_dir" \ + ./test-linuxcnc-wasm-python-c-api-symbols.sh +runtime_probe=$(CNC_SIM_PREFLIGHT_CACHE_DIR="$preflight_cache_dir" ./build-linuxcnc-wasm-link-probe.sh --mode runtime "$manifest") +runtime_dir=$(dirname "$runtime_probe") +runtime_signature="$runtime_dir/link.signature" +if [[ ! -f "$runtime_signature" ]]; then + echo "missing runtime link probe signature: $runtime_signature" >&2 + exit 1 +fi + +mapfile -t runtime_objects < <(awk 'flag{print} /^OBJECTS:$/{flag=1; next}' "$runtime_signature" | sed '/^$/d') +if [[ "${#runtime_objects[@]}" -eq 0 ]]; then + echo "runtime link probe signature did not list objects" >&2 + exit 1 +fi + +non_gcode_binding_objects=( + "$python_build_dir/canonmodule.o" + "$python_build_dir/interpmodule.o" + "$python_build_dir/pyarrays.o" + "$python_build_dir/pyblock.o" + "$python_build_dir/pyemctypes.o" + "$python_build_dir/pyinterp1.o" + "$python_build_dir/pyparamclass.o" +) +for object in "${non_gcode_binding_objects[@]}" "$python_build_dir/gcodemodule.o"; do + if [[ ! -f "$object" ]]; then + echo "missing Python binding object: $object" >&2 + exit 1 + fi +done + +main_source="$python_build_dir/python_binding_link_probe_main.cc" +main_object="$python_build_dir/python_binding_link_probe_main.o" +target="$python_build_dir/python_binding_link_probe" +cat > "$main_source" <<'EOF' +int main() { return 0; } +EOF +trap 'rm -f "$main_source" "$main_object"' EXIT + +cxx=${CXX:-g++} +if [[ -z ${CXX:-} ]] && command -v ccache >/dev/null 2>&1; then + cxx="ccache $cxx" +fi +$cxx -std=c++17 -c "$main_source" -o "$main_object" +$cxx "${runtime_objects[@]}" "${non_gcode_binding_objects[@]}" "$main_object" \ + -Wl,--no-gc-sections -lfmt -o "$target" + +negative_log="$python_build_dir/python_binding_gcodemodule_collision.err" +if $cxx "${runtime_objects[@]}" "${non_gcode_binding_objects[@]}" "$python_build_dir/gcodemodule.o" "$main_object" \ + -Wl,--no-gc-sections -lfmt -o "$python_build_dir/python_binding_link_probe_with_gcodemodule" \ + 2>"$negative_log"; then + echo "gcodemodule binding unexpectedly linked with runtime bridge Canon callbacks" >&2 + exit 1 +fi +grep -F "multiple definition of" "$negative_log" >/dev/null +grep -F "gcodemodule.o" "$negative_log" >/dev/null +grep -F "linuxcnc_canon_bridge.cpp" "$negative_log" >/dev/null + +"$target" + +echo "linuxcnc wasm Python binding link probe passed" diff --git a/test-native.sh b/test-native.sh index 99de904..8b6c9ef 100755 --- a/test-native.sh +++ b/test-native.sh @@ -77,6 +77,8 @@ grep -F 'LINUXCNC_ROOT="$linuxcnc_root" ./check-linuxcnc-inputs-cached.sh "$mani grep -F 'LinuxCNC source basis: Puma560 DH parameter output is generated from' generate-linuxcnc-puma560-dh-parameters.sh >/dev/null grep -F 'LinuxCNC source basis: all-native guardrails lock source-backed manifests' test-all-native.sh >/dev/null grep -F 'LinuxCNC source basis: this probe derives required Python C API exports from' test-linuxcnc-wasm-python-c-api-symbols.sh >/dev/null +grep -F 'LinuxCNC source basis: src/emc/rs274ngc/canonmodule.cc, interpmodule.cc,' test-linuxcnc-wasm-python-binding-link.sh >/dev/null +grep -F 'LinuxCNC wasm Python binding link probe' build-wasm.sh >/dev/null grep -F 'LinuxCNC source basis: this probe compares wasm-safe tooldata runtime stubs' test-linuxcnc-wasm-tooldata-runtime-symbols.sh >/dev/null grep -F 'LinuxCNC source basis: the standalone probe links src/emc/rs274ngc/interp_base.cc' test-linuxcnc-wasm-interp-base-link.sh >/dev/null grep -F 'LinuxCNC source basis: src/emc/pythonplugin/python_plugin.cc and' test-linuxcnc-wasm-python-plugin-link.sh >/dev/null