18 KiB
18 KiB
LinuxCNC Source Policy
The simulator must not grow independently designed functional behavior. Functional behavior must come from LinuxCNC source code.
Hard rules:
- Port-first: prefer direct LinuxCNC source porting, trimming, wrapping, or platform adaptation over project-authored replacements.
- Do not write project-owned functional CNC behavior.
- Functional CNC behavior must be ported, trimmed, wrapped, or routed from LinuxCNC source code.
- Any G/M-code interpretation, motion behavior, kinematics, coordinate handling, cutter compensation, canned cycle, parameter expression, modal state, tool data, remap behavior, or RTCP behavior must first be traced to LinuxCNC source before implementation.
- Browser-side wasm filesystem behavior must use OPFS-backed storage. Do not add browser filesystem paths that bypass OPFS.
Allowed project code:
- LinuxCNC source porting, trimming, wrappers, and platform adaptation.
- Thin adapters between LinuxCNC source code and the simulator C API.
- Platform shims needed to compile LinuxCNC code for native tests or wasm.
- Event serialization, test fixtures, build scripts, and documentation.
- Temporary smoke scaffolding only when it is explicitly marked as temporary.
Not allowed as final behavior:
- Hand-written G-code interpretation semantics.
- Hand-derived kinematics, RTCP, coordinate transform, cutter compensation, canned cycle, modal, parameter, or expression behavior.
- Behavior copied from documentation, controller intuition, or examples without checking the LinuxCNC implementation.
Required workflow for every functional change:
- Identify the LinuxCNC source file and function that defines the behavior.
- Add or update a test that demonstrates the LinuxCNC behavior.
- Port, wrap, or route to that LinuxCNC implementation.
- Record the source file/function in code comments or nearby documentation when the mapping is not obvious.
- Keep the change inside one active workstream context unless a dependency is unavoidable and explicitly named in the final report.
- Run
./test-native.shand./test-linuxcnc-source-link.sh. - For source-manifest, build, or build-policy changes, also run the aggregate
and guardrail checks:
./test-all-native.sh,./test-linuxcnc-source-syntax.sh, and./test-linuxcnc-wasm-cmake-safe-probe.sh. When./test-native.shand./test-linuxcnc-source-link.shhave already been run in the same pass, useCNC_SIM_ALL_NATIVE_GUARDRAILS_ONLY=1 ./test-all-native.shfor the aggregate guardrail pass instead of recompiling the same native/source-link targets again. - Keep
./test-linuxcnc-wasm-cmake-safe-probe.shfocused on the actual CMake probe by default. RunCNC_SIM_WASM_CMAKE_SAFE_PROBE_SELF_CHECKS=1 ./test-linuxcnc-wasm-cmake-safe-probe.shonly when changing its meta-guardrails or the surrounding build-wasm policy.
Efficiency rules:
- Each pass should advance one reasonable, reviewable context. Do not use a nearby failing smoke assertion, broad fixture, or convenient touched file as permission to expand the pass into another workstream.
- Do not add a smoke-only behavior path when the LinuxCNC-backed route already exists; add coverage to the source-backed route instead.
- Smoke tests are verification guardrails. They must not be expanded with new functional CNC behavior unless that behavior is directly routed to, copied from, or checked against the relevant LinuxCNC source in the same narrow context.
- Do not mix generator/table work, manifests, OPFS/browser work, and build policy cleanup in the same pass unless the files directly depend on each other.
- Prefer tightening an existing probe or manifest over adding another broad end-to-end smoke case.
- Do not run the full native aggregate after already running its expensive native/source-link children in the same pass; use the explicit guardrails-only aggregate mode for build-policy cleanup.
- Keep meta-guardrails out of hot build paths. The wasm-safe CMake probe may
run extended self-checks with
CNC_SIM_WASM_CMAKE_SAFE_PROBE_SELF_CHECKS=1, and the source syntax probe may run extended self-checks withCNC_SIM_SOURCE_SYNTAX_SELF_CHECKS=1. The wasm blocker probe may run analyzer failure-path self-checks withCNC_SIM_WASM_BLOCKERS_SELF_CHECKS=1. The default actual CMake, syntax, and blocker probe paths remain fast. - Keep
test-linuxcnc-wasm-source-syntax.shon the same persistent incremental build pattern as the native syntax probe. It must usebuild/wasm-source-syntax-testby default, dependency files, a signature,make --output-sync=target, andCNC_SIM_BUILD_JOBS:-8. - Reuse source preflight results in persistent build directories through
check-linuxcnc-inputs-cached.sh; its signature must include the LinuxCNC root, manifest content, source file size and nanosecond mtime stats, the check mode, and the checker script hash. Cache updates must be serialized with a lock inside the cache directory and must write next signatures through unique temporary files. Root-only source, flag, and link helper scripts must also use this cached preflight, defaulting tobuild/linuxcnc-helper-preflight-cachewhen a caller has not suppliedCNC_SIM_PREFLIGHT_CACHE_DIR.build-wasm.shmust pass its preflight cache into nested build probes such astest-linuxcnc-wasm-blockers.shandtest-linuxcnc-wasm-cmake-safe-probe.shinstead of forcing a second cache walk in the same pass. - Cache wasm blocker analyzer output in
test-linuxcnc-wasm-blockers.sh. Its signature must include the analyzer script, manifest content, LinuxCNC source size and nanosecond mtime stats, shim lister script, and shim source hashes. The cache must be locked and may be overridden withCNC_SIM_WASM_BLOCKERS_CACHE_DIR. - Reuse switchkins/remap table check results in the same persistent cache with
check-linuxcnc-switchkins-remap-table-cached.sh; its signature must include the checker and generator scripts, the kinematics manifest, referenced LinuxCNC source size and nanosecond mtime stats, and tracked generated table/case outputs. - Reuse wasm probe objects across the wasm source object probe,
rs274ngc_preblocker/link probes, and the runtime link probe throughbuild-linuxcnc-wasm-probe-objects.sh. Its mode-specific object caches must be keyed by compiler, LinuxCNC root, manifest, flags, and source list, and must include make dependency files so repeated build-wasm passes and the pairedrs274ngc_preprobes do not recompile unchanged LinuxCNC core files, shims, or kinematics adapters. - Reuse standalone wasm probe objects and binaries for the tooldata link,
tooldata_common link,
interp_baselink, python_plugin link, andrs274ngc_preobject probes throughbuild-linuxcnc-wasm-standalone-probe.sh. Its mode-specific caches must keep compiler, LinuxCNC root, flags, source list, dependency files, and a lock so repeated build-wasm passes do not rebuild unchanged probe inputs. - Reuse wasm final link probes for
rs274ngc_preand runtime link checks throughbuild-linuxcnc-wasm-link-probe.sh. It must consumebuild-linuxcnc-wasm-probe-objects.sh, cache probe main objects and linked executables with dependency files and a lock, and keep runtime symbol checks intest-linuxcnc-wasm-runtime-link.sh. - Cache the runtime link probe symbol table in
test-linuxcnc-wasm-runtime-link.shusing the probe binary size and mtime plus an explicitSYMBOL_RULE_VERSION, so repeated build-wasm passes do not rerunnm -Con an unchanged probe. - Cache the
rs274ngc_prepre-link undefined-symbol scan intest-linuxcnc-wasm-rs274ngc-pre-link-blockers.sh. Its signature must include the LinuxCNC root, manifest, object list, object size and mtime stats, and an explicitFILTER_RULE_VERSION, with a lock andCNC_SIM_WASM_RS274NGC_PRE_LINK_BLOCKERS_CACHE_DIRoverride. - Keep
test-linuxcnc-wasm-python-c-api-symbols.shpersistent for repeated build-wasm passes. It must usebuild/wasm-python-c-api-symbols, dependency files, a build signature, cached source token and object symbol signatures,make --output-sync=target, andCNC_SIM_BUILD_JOBS:-8while still deriving required Python C API symbols from LinuxCNC RS274 Python/remap sources. - Keep
test-linuxcnc-wasm-interp-find-link.shpersistent for repeated build-wasm passes. It must usebuild/wasm-interp-find-link, dependency files, a signature,make --output-sync=target, andCNC_SIM_BUILD_JOBS:-8while still linking LinuxCNCinterp_find.ccwith the wasm-safe tooldata and RTAPI shims. - Keep tooldata symbol probes persistent for repeated build-wasm passes.
test-linuxcnc-wasm-tooldata-mmap-symbols.shmust usebuild/wasm-tooldata-mmap-symbols, andtest-linuxcnc-wasm-tooldata-runtime-symbols.shmust usebuild/wasm-tooldata-runtime-symbols; both must use dependency files, build signatures, cachednm --defined-onlysymbol export signatures,make --output-sync=target, andCNC_SIM_BUILD_JOBS:-8while comparing wasm shim exports against LinuxCNC tooldata sources. - Default native, source-link, build-wasm, and wasm-safe CMake probe
parallelism to
CNC_SIM_BUILD_JOBS:-8; raise it only by explicit positive-integer environment override. - Persistent object/stamp signatures must not include
CNC_SIM_BUILD_JOBS. Parallelism affects scheduling only; changing it must not invalidate otherwise unchanged LinuxCNC source, shim, syntax, or CMake probe build outputs. - Persistent native, source-object, source-link, source-syntax, RS274 native,
bridge native, API native, shared bridge-object, wasm source-syntax,
wasm probe-object, wasm link-probe, wasm standalone-probe, wasm Python C API,
wasm interp_find, and wasm tooldata symbol signatures must include an explicit
BUILD_RULE_VERSIONinstead of hashing the whole probe script. Bump that version when generated compile or link rule semantics change; ordinary guardrail and smoke assertion edits must not invalidate unchanged LinuxCNC source, shim, or project objects. - The LinuxCNC canon bridge native smoke probe must use persistent
build/bridge-native-testobjects, dependency files, a build-rule signature,make --output-sync=target, andCNC_SIM_BUILD_JOBS:-8; it must not compile all bridge sources in a throwaway temporary directory on every aggregate pass. Its 41 LinuxCNC bridge/project objects must be built through the sharedbuild-linuxcnc-native-bridge-objects.shcache so the RS274 API native smoke probe can link the same objects instead of recompiling them. - The LinuxCNC RS274 API native smoke probe must use persistent
build/api-native-testobjects, dependency files, a build-rule signature,make --output-sync=target, andCNC_SIM_BUILD_JOBS:-8; it must keep resetting its RS274 parameter file from LinuxCNCtests/halui/jogging/sim.varbefore running the smoke executable. It must reuse the shared bridge object cache and compile only its extra API/backend sources locally. Its LinuxCNC RS274 backend compile define must be applied only to source files that use that define, currentlycore/src/gcode_backend.cpp, so unrelated bridge and kinematics adapter objects are not rebuilt by backend-specific rule changes. - When
ccacheis available andCXXis unset, native, source-link, source-syntax, and wasm build paths should enable compiler caching automatically rather than requiring a manual wrapper, including the wasm-safe CMake probe. - Persistent native, source-link, source-syntax, and wasm-safe CMake probe build directories, plus the wasm source-syntax, Python C API, and interp_find probe build directories, tooldata symbol probe build directories, and wasm standalone/link probe cache directories may be overridden for local workflows, but must not point at the filesystem root.
- Build policy knobs are intentionally narrow:
CNC_SIM_BUILD_JOBS,CNC_SIM_NATIVE_BUILD_DIR,CNC_SIM_SOURCE_LINK_BUILD_DIR,CNC_SIM_SOURCE_SYNTAX_BUILD_DIR,CNC_SIM_SOURCE_OBJECTS_BUILD_DIR,CNC_SIM_BRIDGE_NATIVE_BUILD_DIR,CNC_SIM_API_NATIVE_BUILD_DIR,CNC_SIM_NATIVE_BRIDGE_OBJECT_CACHE_DIR, andCNC_SIM_RS274_NATIVE_BUILD_DIR, andCNC_SIM_WASM_CMAKE_SAFE_PROBE_BUILD_DIR. The wasm source-syntax probe also acceptsCNC_SIM_WASM_SOURCE_SYNTAX_BUILD_DIRbecause it owns a persistent incremental cache. The wasm Python C API probe acceptsCNC_SIM_WASM_PYTHON_C_API_BUILD_DIRfor the same reason, and the wasm interp_find probe acceptsCNC_SIM_WASM_INTERP_FIND_BUILD_DIR. Tooldata symbol probes acceptCNC_SIM_WASM_TOOLDATA_MMAP_SYMBOLS_BUILD_DIRandCNC_SIM_WASM_TOOLDATA_RUNTIME_SYMBOLS_BUILD_DIR. Standalone wasm probes acceptCNC_SIM_WASM_STANDALONE_PROBE_CACHE_DIR. Final wasm link probes acceptCNC_SIM_WASM_LINK_PROBE_CACHE_DIR. Build directory overrides must stay non-empty, whitespace-free, and outside the filesystem root. build-wasm.shkeeps fixed artifact paths: CMake writesbuild/wasm, then the script copies and byte-comparescnc_sim.jsandcnc_sim.wasmunderweb/publicbefore running Node and browser smoke checks.
Build and source-link guardrails:
CNC_SIM_BUILD_JOBSmust be a positive integer and defaults to8.test-native.shuses persistentbuild/native-testobjects, dependency files, andnative-build.signature.test-linuxcnc-source-link.shuses persistentbuild/source-link-testobjects, dependency files, andsource-link-build.signature.test-linuxcnc-source-syntax.shuses persistentbuild/source-syntax-teststamps, dependency files, andsource-syntax.signature.test-linuxcnc-source-objects.shuses persistentbuild/source-objects-testobjects, dependency files, andsource-objects.signature.test-linuxcnc-rs274-native.shuses persistentbuild/rs274-native-testobjects, dependency files, andrs274-native.signature.test-linuxcnc-wasm-cmake-safe-probe.shuses persistentbuild/wasm-cmake-safe-probeandwasm-cmake-safe-probe.signature; signature changes must reconfigure in place, its signature must include an explicitCONFIGURE_RULE_VERSION, and its two probe executables must be built with one combinedcmake --buildinvocation.test-linuxcnc-wasm-source-syntax.shuses persistentbuild/wasm-source-syntax-teststamps, dependency files, andwasm-source-syntax.signature.test-linuxcnc-wasm-python-c-api-symbols.shuses persistentbuild/wasm-python-c-api-symbolsobjects, dependency files, andpython-c-api.signature.test-linuxcnc-wasm-interp-find-link.shuses persistentbuild/wasm-interp-find-linkobjects, dependency files, andinterp-find.signature.test-linuxcnc-wasm-tooldata-mmap-symbols.shuses persistentbuild/wasm-tooldata-mmap-symbolsobjects, dependency files, andtooldata-mmap-symbols.signature.test-linuxcnc-wasm-tooldata-runtime-symbols.shuses persistentbuild/wasm-tooldata-runtime-symbolsobjects, dependency files, andtooldata-runtime-symbols.signature.- Native, source-link, source-syntax, wasm-safe CMake probe, and build-wasm paths must reject empty, whitespace-containing, or filesystem-root build directory overrides before doing destructive cleanup.
- Native, source-link, source-syntax, and build-wasm entry points must serialize shared non-concurrency-safe paths with lock files before writing fixed outputs.
CNC_SIM_ALL_NATIVE_GUARDRAILS_ONLY=1 ./test-all-native.shmust run the aggregate guardrail and failure-path assertions without invoking the expensive child native/source-link compile and smoke scripts.- Native, source-object, source-link, RS274 native, and syntax probes must build
from generated makefiles with
-MMD -MPdependency tracking andmake --output-sync=target. build-wasm.shmust run blocker, syntax, object, CMake, tooldata,interp_*, Python,rs274ngc_pre, and runtime link probes before copying browser artifacts.- Independent tooldata,
interp_*, Python, andrs274ngc_preobject probes inbuild-wasm.shmay run in parallel, but their logs must be replayed in a deterministic order and the script must wait for all of them beforers274ngc_prelink checks. build-wasm.shmust checkcmake,emcmake,emcc, andnodebefore the Emscripten configure step.build-wasm.shmust reuse a persistentbuild/wasmconfigure signature keyed by manifest,core/CMakeLists.txt, an explicitCONFIGURE_RULE_VERSION, LinuxCNC root, and compiler launcher. The signature must not includeCNC_SIM_BUILD_JOBS, and signature changes must reconfigure the existing build tree in place instead of deleting compiled objects.build-wasm.shmust buildcnc_sim_wasm_runtime_probebeforecnc_sim_wasm, using one combinedcmake --buildinvocation for both targets.build-wasm.shmust copybuild/wasm/cnc_sim.jsandbuild/wasm/cnc_sim.wasmexactly once each.build-wasm.shmust compare copied artifacts withcmp -sbefore running Node or browser smoke tests.build-wasm.shmust run the Node smoke before the browser smoke.- The default wasm manifest partition must remain explicitly checked for 25 wasm-safe core sources and 9 blocked sources.
- Manifest source listers must reject malformed lines, absolute source paths, unknown groups, unknown filters, and duplicate source entries.
- Native link flags must include the built LinuxCNC
libpath and rpath. - Common CXX flag helpers must surface helper failures instead of hiding them
behind process substitution or
read. - Temporary probe reports must be cleaned on failure and preserved only after a successful report path explicitly opts in.
- Documentation-only build policy edits should still update the guardrail checks that enforce the relevant script and artifact ordering.
Current temporary exceptions:
- The smoke parser exists only to exercise the public API and UI around remaining fallback paths; native, source-linked, and wasm smoke coverage now route LinuxCNC RS274 behavior through the LinuxCNC-backed interpreter.
- RTCP pivot behavior is limited to LinuxCNC source-backed switchkins paths; unsupported switchkins types must not fall back to hand-derived geometry.
Both exceptions should shrink over time. New functional behavior should not be added to them unless it is directly copied from, or routed to, LinuxCNC source code.