Files
cnc_wams/完善wasm/working/19-04动态加载与预编译Manifest复核.md
2026-07-10 21:26:42 -04:00

136 lines
7.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 19-04 动态加载与预编译 Manifest 复核
## 定位
本文件落实 `ACC-031/INT-018`:复核 `04基于Web的LinuxCNC兼容数控仿真平台.txt` 中动态加载与预编译相关条目,覆盖:
- `4.7` and2 组件
- `4.8` or2 组件
- `4.9` not 组件
- `4.10` mux2 组件
- `4.11` scale 组件
- `4.16` loadrt 加载组件
- `6.5` 自定义运动学
- `6.6` 并联运动学
严格口径:浏览器/WASM 环境不能把 LinuxCNC 原生 `loadrt` 的运行时模块加载能力直接标为通过。已经编译进 WASM 的模块可以按 manifest、源码归属和运行 gate 单独验收;未进入 manifest 和 gate 的组件只能保持条件通过或待补专项证据。
## LinuxCNC 源码复核
### HAL 基础组件
04 文档把 `and2``or2``not``mux2``scale` 写为 `and2.c` 等 C 文件。以本仓库锁定的 LinuxCNC 源码为准,真实源码归属是 `src/hal/components/*.comp`
| 04 项 | 组件 | 本地 LinuxCNC 源码 | 核心逻辑 |
| --- | --- | --- | --- |
| 4.7 | and2 | `linuxcnc/src/hal/components/and2.comp` | `out = in0 && in1` |
| 4.8 | or2 | `linuxcnc/src/hal/components/or2.comp` | `out = in0 || in1` |
| 4.9 | not | `linuxcnc/src/hal/components/not.comp` | `out = ! in` |
| 4.10 | mux2 | `linuxcnc/src/hal/components/mux2.comp` | `sel ? in1 : in0` |
| 4.11 | scale | `linuxcnc/src/hal/components/scale.comp` | `out = in * gain + offset` |
这些 `.comp` 文件在 LinuxCNC 原生构建中会生成可加载 HAL 组件。Web/WASM 若要宣称支持,必须证明组件已经进入预编译组件清单、导出函数、引脚/参数模型和逻辑 truth-table gate仅有 HAL pin/signal/net 运行时不能替代组件函数执行。
### loadrt
LinuxCNC 原生 `loadrt` 属于 RTAPI/HAL 模块加载路径,依赖原生进程、共享内存、实时线程和可加载模块生命周期。当前 `wasm-port/runtime/core/linuxcnc_wrap/linuxcnc_hal_runtime.cpp` 中:
- `loadusr` 被记录为 `blocked:loadusr` 并返回阻塞码。
- `loadrt` 只记录 `loadrt:<name>` 事件并返回成功。
- 该路径不执行运行时动态链接,也不实例化任意 `.comp` 组件逻辑。
因此 `4.16 loadrt` 只能按“预编译 allowlist + manifest + gate”晋级不能按原生 LinuxCNC 动态加载能力无条件通过。
### 运动学预编译
运动学与 HAL 组件不同:`wasm-port/tools/source-manifest.txt` 已登记多组 LinuxCNC kinematics 源码,包括:
```text
src/emc/kinematics/switchkins.c
src/emc/kinematics/trtfuncs.c
src/emc/kinematics/xyzac-trt-kins.c
src/emc/kinematics/xyzbc-trt-kins.c
src/emc/kinematics/pumakins.c
src/emc/kinematics/genhexkins.c
src/emc/kinematics/genserkins.c
src/emc/kinematics/genserfuncs.c
src/emc/kinematics/pentakins.c
```
`wasm-port/tests/wasm/node/verify_kinematics_wasm.mjs` 进一步固定了预编译模块集合:
```text
trivkins
5axiskins
xyzac-trt
xyzbc-trt
corexy
rotate
rose
max
lineardelta
rotarydelta
scorbot
tripod
scara
puma
genser
genhex
pentakins
```
该 gate 检查每个模块的 WASM 文件、`lckins_forward``lckins_inverse``lckins_run_probe`、kinematics type、switchable 元数据和 roundtrip 行为。对 `6.5/6.6` 而言,这可以支撑“已列入 manifest 的预编译运动学模块条件通过”;但不等价于用户在运行时加载任意自定义 kinematics `.so`
## 当前 Web/WASM 证据
| 范围 | 现有证据 | 可声明内容 | 不可声明内容 |
| --- | --- | --- | --- |
| HAL pin/signal/param/net/thread | `wasm-port/tests/wasm/node/verify_hal_runtime.sh``verify_hal_runtime.mjs``source-reuse-map.md` HAL runtime row | Web/WASM 具备 virtual HAL registry、信号连接、参数写入和线程调度基础 | 不代表 and2/or2/not/mux2/scale 组件函数已执行 |
| `loadrt` 命令 | `linuxcnc_hal_runtime.cpp``loadrt:<name>` 事件记录 | 可记录 HAL 文件中的 `loadrt` 语句,用于配置解析边界 | 不代表运行时动态加载 LinuxCNC realtime module |
| `loadusr` 命令 | `blocked:loadusr` evidence | 外部用户态进程默认阻塞 | 不代表支持原生外部进程 |
| 预编译 kinematics | `source-manifest.txt``verify_kinematics_wasm.sh` | 已进入清单的 kinematics 模块有 WASM 行为 gate | 不代表任意自定义/并联运动学运行时加载 |
| HAL 基础组件 | LinuxCNC `.comp` 源码已定位 | 可作为后续 manifest 源码来源 | 当前缺 HAL component precompile manifest 和 truth-table gate |
## HAL 组件预编译 Manifest 要求
后续要把 `4.7-4.11` 从条件通过升级为完成,至少需要新增一份可机读 manifest例如 `hal_component_precompile_manifest.json` 或等价 TSV并由 Node/Browser gate 校验。建议字段:
| 字段 | 要求 |
| --- | --- |
| `component` | `and2``or2``not``mux2``scale` 等 LinuxCNC 组件名 |
| `linuxcncSource` | 指向本地 LinuxCNC `.comp` 源码相对路径 |
| `generatedSource` | 如有 `.comp` 生成 C/C++,登记生成产物路径和生成命令 |
| `pins` | 每个 pin 的名称、方向、HAL 类型和默认值 |
| `params` | 每个参数的名称、HAL 类型和默认值 |
| `functionNames` | LinuxCNC component function 名称和 addf 对应关系 |
| `loadrtName` | HAL 文件中允许的 `loadrt` 名称 |
| `wasmSymbol` | 预编译后暴露给 runtime 的 WASM/C ABI 符号 |
| `formula` | 逻辑公式或真值表摘要 |
| `tests` | truth-table、net propagation、thread scheduler、negative cases 的测试文件 |
最低专项 gate
```bash
cd wasm-port && ./tests/wasm/node/verify_hal_runtime.sh
cd wasm-port && node tests/wasm/node/verify_hal_component_precompile_manifest.mjs
```
若目标 Web 应用要把这些组件显示为 UI 发布能力,还需要追加 browser/evidence gate证明 HAL 文件中的 `loadrt and2 count=N``addf``net` 和 UI 监视输出都来自同一 runtime snapshot。
## 逐项结论
| 04 项 | 当前结论 | 后续晋级条件 |
| --- | --- | --- |
| 4.7 and2 | LinuxCNC 源码已定位为 `.comp`;当前 Web/WASM 未见组件预编译 manifest 和 truth-table gate | 补 manifest、WASM symbol、pin/net/thread truth-table gate |
| 4.8 or2 | 同上 | 同上 |
| 4.9 not | 同上 | 同上 |
| 4.10 mux2 | 同上 | 同上,需覆盖 `sel=false/true` 两路 |
| 4.11 scale | 同上 | 同上,需覆盖 `gain``offset`、float 误差容差 |
| 4.16 loadrt | 当前仅为事件记录,不是动态链接;运行时动态加载保持 Blocked | 只能按预编译 allowlist/manifest 晋级,禁止宣称任意模块 runtime load |
| 6.5 自定义运动学 | 已列入 `verify_kinematics_wasm.mjs` 的预编译 kinematics 可条件通过;任意用户自定义 kinematics 运行时加载仍 Blocked | 对每个新增 kinematics 补 source-manifest、WASM artifact、probe、roundtrip gate |
| 6.6 并联运动学 | `puma``genser``genhex``pentakins` 等已有预编译 probe具体并联机床 profile/UI 发布仍需单独证据 | 对具体机床补 INI、HAL、G-code、Native/WASM/Web 对比和 profile boundary gate |
## 当前结论
`ACC-031/INT-018` 已完成源码边界复核。`6.5/6.6` 的“已预编译模块”部分可由 `source-manifest.txt``verify_kinematics_wasm.sh` 支撑条件通过;`4.7-4.11` 只能登记为 LinuxCNC `.comp` 源码已定位、待补 HAL component precompile manifest`4.16 loadrt` 运行时动态加载在浏览器/WASM 中保持 Blocked只能按预编译 allowlist 逐项晋级。