Rewrite your app in Rust, piece by piece, checked against the original at every step. Works with TypeScript, JavaScript, Python, Go, Ruby, Java, C, PHP, C#, Kotlin, PowerShell and Swift.
Languages
| Language | Unit | Bridge | Recorded and replayed by |
|---|---|---|---|
| folder or file | napi-rs or wasm-bindgen with a generated binary wire; classes and async included | Node, running the .ts sources |
|
| folder or file | napi-rs or wasm-bindgen with a generated binary wire; classes and async included | Node, running the .js sources |
|
| package or module | PyO3 (abi3), direct conversion, typed exceptions | Python, importing the original | |
.c file |
extern "C" functions with the original names and a header |
the original compiled to a shared library, called through ctypes, one fork per case | |
| package | typed cgo calls and a generated binary wire, in a package with the original API | a generated Go driver, built as its own module | |
| file or folder of module functions | a magnus extension under the original modules | a generated Ruby driver | |
package of public static methods |
typed JNI and a generated binary wire, in wrapper classes with the original methods | a generated reflection driver | |
Gradle module of top-level functions and @JvmStatic methods |
the Java bridge: typed JNI in Java wrapper classes calling the compiled Kotlin statics | a generated reflection driver, with the Kotlin sources compiled by kotlinc |
|
file or folder of top-level functions and final classes whose public members are all static methods |
a JSON dispatcher over ext-ffi, in a file that redeclares the functions and static methods with the original parameters |
a generated PHP driver; whole apps with app record, app replay and the front door, for CLIs and servers (php -S) |
|
.psm1 module or .ps1 script of functions with param() blocks (exported per Export-ModuleMember) |
a JSON dispatcher over P/Invoke, declared at load time with Reflection.Emit, in a .ps1 that redeclares each function with its original param() block |
a generated pwsh driver (PowerShell 7.4+) |
|
file or folder of public static methods |
a JSON dispatcher over P/Invoke, in <namespace>.Rust classes with the original methods |
a generated reflection driver, compiled with the project's sources by dotnet build; whole apps with app record, app replay and the front door, for CLIs and ASP.NET servers (dotnet <app>.dll) |
|
| Swift | file of top-level functions in a SwiftPM target or folder | a JSON dispatcher over the C ABI, in swift/<Crate>.swift, which redeclares each function with its labels, defaults and throws and imports a generated C module map |
a generated main.swift driver, compiled by swiftc with the target's sources; a case that traps is recorded as a trap |
Every language except C, PHP, C#, PowerShell and Swift also gets batch classes (--batch): the items cross once and stay in
Rust, and each call runs over all of them on all cores.
The language is detected from the repository (go.mod, pom.xml, build.gradle/build.gradle.kts,
a .csproj, .sln or .slnx, or Directory.Build.props, pyproject.toml, setup.py or setup.cfg, Gemfile,
composer.json, package.json, Package.swift,
else the most common source files); a Gradle module with .kt sources and no .java sources is Kotlin, mixed
modules stay Java. --lang overrides it. Types come from the source: TS types, Python hints, C, Go,
Java, Kotlin and C# signatures, Ruby YARD tags, PHP types and phpdoc; untyped parameters used as
numbers are inferred as numbers. Types lists what each one becomes in the port,
and which keep a function in its language.
A Java unit is compiled with the rest of its source tree. When those sources import classes from
outside it (the module's libraries, or another module), set CLASSPATH to the jars and class
folders the project builds against before record, diff and bench; javac and the driver both
use it. With Gradle, print it from the module's compile classpath
(configurations.compileClasspath.asPath, or <variant>CompileClasspath on Android); with Maven,
mvn dependency:build-classpath. Without it, javac fails on the missing types and the error says
to set it.
For Android, rust-anything build <crate> --profile android builds the same JNI library with the
NDK for arm64-v8a, armeabi-v7a and x86_64 (or the --abi values you pass) and installs it
into <crate>/jniLibs/<abi>/; --api sets the API level (minimum 26, which the generated Java
runtime needs). It finds the NDK from ANDROID_NDK_HOME/ANDROID_NDK_ROOT or the SDK, needs the
Rust targets (rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android), links 64-bit libraries with 16 KB page alignment, and checks that every
JNI entry point is exported. Gradle looks in src/main/jniLibs by default, so pass
--jni-libs app/src/main/jniLibs or add <crate>/jniLibs to sourceSets.main.jniLibs.srcDirs.
rust-anything record <crate> --profile android runs the original Kotlin unit under ART on a
connected device (adb), dexes the generated driver with d8 from the SDK's build-tools, and pulls
the results back as the same cases.jsonl; diff <crate> --profile android replays them against
the .so built for the device's ABI. Both need adb, a device, kotlinc, an SDK with build-tools
and a platform, and --device <serial> when more than one device is connected. The profile covers
logic units: Activity/Compose/XML UI, lifecycle and SDK-only classes stay in Kotlin, and each call
crosses JNI, so prefer the generated batch wrappers for hot loops. On a host, record and diff
keep using the desktop JVM.
For PHP, analyze plans a PHP app (Composer packages and PSR-4 autoloading, risks
such as loose comparison and integer overflow into floats, Composer packages mapped to crates),
and a PHP CLI or server can be recorded, replayed and put behind a Rust front door. A unit's
top-level functions with scalar, string, list and assoc-array parameters, and the public static
methods of a final class whose public members are all static methods, are bridged through PHP's
FFI extension (php with ext-ffi, on by default for the CLI): once diff passes, require the
generated php/<crate>.php (the name is the crate with - written as _, so foo-rs is
php/foo_rs.php) where the app required the original, and leave both files where they are: the
wrapper loads its native library relative to its own folder, so moving it breaks the load. The wrapper
declares each bridged function or static method unconditionally, with no function_exists guard,
so it replaces the original file rather than joining it. Whatever else that file holds cannot come
along: a class the bridge keeps in PHP (an instance method, a non-final class or an unsupported
default, say), functions the bridge keeps in PHP (a callable or Closure parameter, say), and
top-level statements such as define('FEATURE_ENABLED', true) are not in the wrapper, and
requiring both files redeclares the bridged functions. Keep those in a file that stays required:
the crate's README, the wrapper's header and the shadow refusal name the kept functions and the
files to move them out of.
Each
call crosses as JSON, about 1 µs, so bench shows small functions slower than PHP; there is no shadow for PHP yet
(issue #200).
C# works the same way: analyze reads .csproj projects and their NuGet packages
(mapped to crates), resolves using directives to folders, and flags what C# does differently
(decimal, dynamic, LINQ's deferred queries, Task, lock, reflection). A C# CLI or ASP.NET
server can be recorded, replayed and put behind a Rust front door. A unit's public static methods
with scalar, string, array, list, dictionary and record or plain-class parameters are bridged
through P/Invoke (dotnet on PATH to record and diff): once diff passes, compile the generated
cs/ wrapper (one file named after the crate: foo-rs gives cs/FooRs.cs) into the project and keep
the built native library next to the app, then call
the generated classes in the <namespace>.Rust namespace (Acme.Text.Slug.Slugify becomes
Acme.Text.Rust.Slug.Slugify), or alias them with using. Each call crosses as JSON, about 1-3 µs,
so bench shows small methods slower than .NET; there is no shadow for C# yet
(issue #200).
For PowerShell, analyze reads .psm1 modules, .ps1 scripts and .psd1 manifests
(RequiredModules), follows Import-Module, using module and dot-sourced files, and flags what
PowerShell does differently: implicit output and array unrolling, case-insensitive -eq, -match
and hashtable keys, $null, and implicit conversions (5 / 2 is 2.5, [int]2.5 is 2). A unit's
functions with [string], integer, [double], [bool]/[switch], array, [hashtable] or untyped
parameters are bridged through P/Invoke from a generated ps/<crate>.ps1; filters, begin/process
blocks, pipeline input, [scriptblock], [ref] and other .NET types stay in PowerShell with the
reason. Once diff passes, rust-anything enable <crate> dot-sources the wrapper at the end of the
original file. Each call crosses as JSON encoded by PowerShell code: about 0.1 ms for a few
scalars on an Apple M4, more for arrays and hashtables, so only functions that do more work than
that per call get faster (bench measures it for yours). Most slow PowerShell in tools is the
start-up of a new pwsh or powershell.exe per command (0.24 to 0.45 s for
pwsh -NoProfile -c 1 on the same M4), which no port fixes: keep one shell open and send it the
commands (see the FAQ).
For Swift, analyze reads SwiftPM packages (Package.swift and its .package(url:)
dependencies, mapped to crates), resolves import to the package's targets, sets aside files that
import SwiftUI, UIKit or AppKit as UI, and flags what Swift does differently: traps on Int
overflow, ! and out-of-range indices, strings counted and compared by grapheme cluster, and the
text form of a Double. A file's top-level functions with String, integer, Double/Float,
Bool, optional, array and [String: T] parameters and results, and throws, are bridged through
a C module map (swiftc on PATH to record and diff; Xcode or a Swift 5.9+ toolchain). Once diff
passes, compile the generated swift/<Crate>.swift (foo-rs gives swift/FooRs.swift) into the
target in place of the original file, with -I swift for the module map in
swift/<Crate>Native/ and -L swift for the built library. A function kept in Swift (a variadic
one, say) is not in the wrapper: the crate's README and the wrapper's header name it, and it has to
move out of the original file into one that stays in the target first. The crate builds with
overflow-checks = true, so a port's + panics where Swift traps, and the wrapper turns a Rust
panic into fatalError: diff compares a trap with a trap. A port's Err("Type: message") is
thrown as <Crate>Error with that type name and message, and diff compares both with the
original's error. Methods, extensions, closures, inout, generics, async, Set and the
project's own types stay in Swift; there is no shadow, --batch or profile for Swift
yet (issue #200).