Skip to main content

Crate rust_anything

Crate rust_anything 

Source
Expand description

rust-anything: plan, bridge, verify and ship incremental migrations to Rust.

The steps (analyze, bridge, harness, shadow, gate) are language-neutral in shape; each source language is a plugin module. TypeScript/JavaScript (ts) is the first.

Modules§

analyze
Builds the migration plan: units, their dependency graph, port order and readiness.
android
Android NDK builds: the JNI cdylib for each ABI, installed into jniLibs/.
android_device
On-device recording and diffing over adb.
app
App-level record and replay for CLIs, in any language: the program is a black box.
bridge
Step 2: scaffold a Rust crate for one unit, with JS bindings and a manifest the later steps read.
cache
One cargo target folder for every port and bridge, so dependencies compile once.
card
report: a unit’s result as Markdown and an SVG card, for a pull request or a README.
codegen
Code generation for a bridge crate: port stubs from TS signatures, and the binding layer (lib.rs, index.cjs) from the port’s Rust signatures.
codegen_batch
Batch classes: a function run over many items that stay on the Rust side.
codegen_batch_native
Batch classes for Ruby (magnus), Go (cgo) and Java (JNI): the same run and rank as the TS and Python batches in codegen_batch, over items kept in Rust and run on all cores.
codegen_c
C ABI bridge: drop-in extern "C" replacements with the original names and signatures.
codegen_csharp
The C# side of the JSON bridge: a wrapper with the original classes and signatures under <namespace>.Rust, each method calling the Rust library through P/Invoke, and the driver that records the original and diffs the wrapper.
codegen_ffi
The JSON bridge for Go, Ruby and Java: the port is plain Rust over serde types, and one dispatcher takes a function name and its arguments as JSON and answers {"ok": value}, {"error": message} or {"panic": message}.
codegen_go
Go: the cgo wrapper package (the original API over the Rust library), and the driver that calls a package’s functions by name for record, diff and bench.
codegen_java
Java: the JNI wrapper (the original classes’ static methods over the Rust library), a small JSON codec with no dependencies, and the reflection driver for record, diff and bench.
codegen_kotlin
Kotlin’s generated artifacts are Java artifacts.
codegen_php
codegen_powershell
The PowerShell side of the JSON dispatcher: a wrapper script with the original functions, each calling rust_anything_call through P/Invoke methods that Reflection.Emit declares when the wrapper loads (no C# compiler, no Add-Type), and the driver record, diff and bench run in pwsh.
codegen_py
PyO3 bindings and the Python wrapper package for a bridge crate.
codegen_ruby
Ruby: the Fiddle wrapper (the original module functions over the Rust library), and the driver that calls them by name for record, diff and bench.
codegen_tswire
The binary wire for TypeScript/JavaScript: generated JS encoders write arguments into a buffer registered once with the Rust module, the Rust side reads them in place, and the result comes back the same way. No JSON text, no per-property napi calls.
crates
The libraries each source language imports and the Rust crates that replace them, from the data table crates.toml: adding a mapping is a few lines there, not code.
doctor
doctor: check the toolchains, the agent setup and the MCP server on this machine, and say the command that fixes each problem.
effects
enable
enable and disable: switch a ported unit in and out of the app with one command.
error_paths
Error paths: where the original fails (throw, raise, an error result), whether a recorded case reaches each of them, and whether the port panics where the original failed politely.
from_tests
record --from-tests -- <test command>: runs the original’s own test suite and keeps every call it makes to the unit’s exported functions as recorded inputs, so the cases cover what the project’s authors thought worth testing, not only generated values.
front_door
The front door: rust/app, a Rust binary that owns a CLI’s entry point from day one and runs the original for every command not ported yet, and wire, which hands commands to a unit’s port.rs behind a kill switch.
front_door_http
The HTTP front door: an axum server that proxies every route no unit answers to the original server, which it starts on a port of its own.
fuzz
Live differential testing: fresh inputs from a new seed, run through the original and the port, mismatches reported and optionally kept in the recording.
gate
Step 5: the definition of done for one port.
go
go: the hot-path loop in one command. Profile the workload, bridge the top portable function (the outermost one, batched where profile says so), record it, hand the port to an agent, then build, diff and gate it, and switch it on with enable only when all pass. Run it again after porting by hand: every finished step is kept.
harness
Steps 3 and 5’s runtime half: record what the original code does, build the Rust module, and replay the recorded cases against it.
harness_c
The C side of record, build, diff and bench: the original is compiled into a shared library, and Python’s ctypes calls it and the Rust library with the same signatures.
harness_csharp
The C# side of record, build, diff and bench. A generated console project compiles the unit’s project sources with a driver that calls the static methods by reflection: the originals to record, and the P/Invoke wrapper over the Rust library to diff.
harness_go
The Go side of record, build, diff and bench. A generated driver calls the package’s functions by name: built against the original package to record, and against the cgo wrapper over the Rust library to diff. Both builds are separate modules under .rust-anything/ with replace directives, so nothing is written into the original repository.
harness_java
The Java side of record, build, diff and bench. A generated driver calls the unit’s static methods by reflection: compiled with the original sources to record, and with the JNI wrapper classes over the Rust library to diff.
harness_kotlin
The Kotlin side of record, build, diff and bench.
harness_php
harness_powershell
harness_py
The Python side of record, build, diff and bench: same cases, same markers, run by a Python driver instead of Node.
harness_ruby
The Ruby side of record, build, diff and bench. A generated driver calls the module functions by name: with the original files loaded to record, and with the Fiddle wrapper over the Rust library loaded to diff.
http
HTTP servers as a black box: start the original (or any build) on a port, send the recorded requests in order, and store or compare what it answers.
lang
Source languages. TypeScript/JavaScript lives in crate::ts; the others are plugins that produce the same workspace, facts and exports, with types mapped into the TS-like type dialect the planner, generators and port stubs use (string, number, int, T[], …).
library
Libraries (no main, no server): the front door is the library’s public API as a Rust crate, rust/app, re-exporting each unit’s port.rs once it is wired. Until the lift, the original package keeps its callers and reaches Rust through each unit’s bindings and shadow drop-in, which honors the unit’s kill switch.
lift
app lift: once the front door answers every recorded case in Rust, remove the fallback, the kill switches and the units’ bindings, and prove the pure binary on the recorded cases.
mcp
MCP server over stdio: every step as a tool, for any agent.
mcp_prompts
MCP prompts: the skill’s playbooks as ready-to-send messages, for agents that load prompts rather than skills.
package
Step 6: turn a gated port into packages end users install, the way maturin and @napi-rs/cli lay them out. Writes files only: it never builds for other platforms (the generated GitHub Actions workflow does) and never publishes.
pin
Pinned clock and random numbers (record --pin-clock), so units that read them can be recorded and diffed.
port_map
process
Every outside program runs with stdin closed, in its own process group, under a time limit.
profile
profile: run a real workload under the language’s own profiler and say what to port.
recording
What a recording was made from, and the differences from it a port is allowed to keep.
report
Renders a Report as a Markdown migration plan for people.
risks
The catalog of TypeScript/JavaScript behaviors that do not carry over to Rust as-is.
setup
setup: register rust-anything with the coding agents on this machine, in one command.
shadow
Step 4: a drop-in module that runs the TS original and the Rust port side by side.
tolerance
Float tolerance: numeric code (physics, statistics, graphics) rarely gives bit-identical floats once ported, because the order of operations, fused multiply-add and the math library differ. With a tolerance, two results still match when every number differs by at most tolerance times the larger magnitude (absolute below 1). Integers, strings and structure must still match exactly, and the same value written differently (3 and 3.0) is a formatting difference, not rounding, so it never passes.
ts
The TypeScript/JavaScript language plugin: discovery, parsing and the npm crate table.
walk
Directory walks that read .gitignore the way git does: from the repository root down to the scanned folder and below it, never from folders above the repository (a * in a home-folder .gitignore would otherwise hide every file).
whole_app
analyze --whole-app: what a whole-app port needs on top of the unit plan. The app’s entry points and shape, every external dependency (imported or declared) with its Rust crate, the port order as pieces (units that import each other move together), and the decisions to put to the user in the grilling round.
wire
The binary wire for Go and Java: values cross as compact bytes whose encoders and decoders are generated per type on both sides, without JSON text or reflection.