rust-anything 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -4,12 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
<h1 align="center">rust-anything</h1>
|
|
6
6
|
|
|
7
|
+
<p align="center">by <a href="https://github.com/erkamyaman">erKam Yaman</a></p>
|
|
8
|
+
|
|
7
9
|
<p align="center"><em>Rewrite your whole app in Rust. Keep it working the whole way.</em></p>
|
|
8
10
|
|
|
9
11
|
<p align="center"><em>CLIs, servers and libraries, piece by piece, checked against the original at every step.</em></p>
|
|
10
12
|
|
|
13
|
+
<p align="center">Node.js and TypeScript · Python · C · Go · Ruby · Java · PHP and C# in preview</p>
|
|
14
|
+
|
|
11
15
|
<p align="center">
|
|
12
16
|
<a href="https://crates.io/crates/rust-anything"><img src="https://img.shields.io/crates/v/rust-anything?color=E2862A&label=crates.io" alt="crates.io version"></a>
|
|
17
|
+
<a href="https://www.npmjs.com/package/rust-anything"><img src="https://img.shields.io/npm/v/rust-anything?color=E2862A&label=npm" alt="npm version"></a>
|
|
13
18
|
<img src="https://img.shields.io/badge/languages-6-E2862A" alt="6 languages">
|
|
14
19
|
<a href="#works-with"><img src="https://img.shields.io/badge/works%20with-4%20agents-E2862A" alt="Works with 4 agents"></a>
|
|
15
20
|
<a href="https://github.com/erkamyaman/rust-anything/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/erkamyaman/rust-anything/ci.yml?branch=main&label=tests" alt="Tests"></a>
|
|
@@ -19,8 +24,12 @@
|
|
|
19
24
|
|
|
20
25
|
<p align="center">up to 20x faster · 38,251 recorded cases replayed · 0 mismatches · one command</p>
|
|
21
26
|
|
|
27
|
+
<p align="center">
|
|
28
|
+
<img src="docs/assets/race.gif" alt="Typing user.profile into x18n's search over 50,000 keys: TypeScript spends 143 ms, the rust-anything batch 6.9 ms, with the same results at every keystroke." width="820">
|
|
29
|
+
</p>
|
|
30
|
+
|
|
22
31
|
**Rewrite your whole app in Rust, one piece at a time.** rust-anything records what your
|
|
23
|
-
TypeScript/JavaScript, Python, C, Go, Ruby or Java app does today, then checks every piece of the
|
|
32
|
+
Node.js (TypeScript/JavaScript), Python, C, Go, Ruby or Java app does today, then checks every piece of the
|
|
24
33
|
Rust rewrite against that recording before it moves on, until the app is pure Rust. CLIs, HTTP
|
|
25
34
|
servers and libraries; your coding agent (or you) writes the Rust. It can only catch what the
|
|
26
35
|
recording covers: see [What it can't catch](#what-it-cant-catch). Only need the slow part fast?
|
|
@@ -35,10 +44,6 @@ Port just that, one hot path at a time:
|
|
|
35
44
|
| `Slugify` over 50,000 strings (Go) | 49 ms | **4x faster** |
|
|
36
45
|
| `slugify` over 50,000 strings (Java) | 43 ms | **3x faster** |
|
|
37
46
|
|
|
38
|
-
<p align="center">
|
|
39
|
-
<img src="docs/assets/race.gif" alt="Typing user.profile into x18n's search over 50,000 keys: TypeScript spends 143 ms, the rust-anything batch 6.9 ms, with the same results at every keystroke." width="820">
|
|
40
|
-
</p>
|
|
41
|
-
|
|
42
47
|
Measured on 4 cores; every number has a benchmark in [`demo/`](./demo) that first checks the
|
|
43
48
|
results are identical. Calling Rust once per small function is usually *slower* than a JIT;
|
|
44
49
|
rust-anything finds the loop worth moving, and moves it.
|
|
@@ -100,7 +105,6 @@ Or run the steps yourself:
|
|
|
100
105
|
<img src="docs/assets/terminal.gif" alt="rust-anything profile finds fuzzyScore in a loop, bridge --batch generates the Rust crate, gate passes with 2000/2000 recorded cases, and the benchmark shows 20.7x faster than TS." width="820">
|
|
101
106
|
</p>
|
|
102
107
|
|
|
103
|
-
|
|
104
108
|
```sh
|
|
105
109
|
rust-anything profile . -- node bench.mjs # what is hot, and who calls it
|
|
106
110
|
rust-anything bridge . src/fuzzy.ts --batch fuzzyScore:text
|
|
@@ -127,14 +131,28 @@ done.
|
|
|
127
131
|
| Go | 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 |
|
|
128
132
|
| Ruby | file or folder of module functions | a magnus extension under the original modules | a generated Ruby driver |
|
|
129
133
|
| Java | package of `public static` methods | typed JNI and a generated binary wire, in wrapper classes with the original methods | a generated reflection driver |
|
|
134
|
+
| PHP (preview) | folder of functions and `public static` methods | coming next: PHP FFI over a C ABI | whole apps today: `app record`, `app replay` and the front door, for CLIs and servers (`php -S`) |
|
|
135
|
+
| C# (preview) | folder of `public static` methods | coming next: P/Invoke over a C ABI | whole apps today: `app record`, `app replay` and the front door, for CLIs and ASP.NET servers (`dotnet <app>.dll`) |
|
|
130
136
|
|
|
131
137
|
Every language except C also gets batch classes (`--batch`): the items cross once and stay in
|
|
132
138
|
Rust, and each call runs over all of them on all cores.
|
|
133
139
|
|
|
134
|
-
The language is detected from the repository (`go.mod`, `pom.xml`, `
|
|
135
|
-
`package.json`, else the most common source files);
|
|
136
|
-
source: TS types, Python hints, C
|
|
137
|
-
used as numbers are inferred
|
|
140
|
+
The language is detected from the repository (`go.mod`, `pom.xml`, a `.csproj` or `.sln`,
|
|
141
|
+
`pyproject.toml`, `Gemfile`, `composer.json`, `package.json`, else the most common source files);
|
|
142
|
+
`--lang` overrides it. Types come from the source: TS types, Python hints, C, Go, Java and C#
|
|
143
|
+
signatures, Ruby YARD tags, PHP types and phpdoc; untyped parameters used as numbers are inferred
|
|
144
|
+
as numbers.
|
|
145
|
+
|
|
146
|
+
PHP is in preview: `analyze` plans a PHP app (Composer packages and PSR-4 autoloading, risks
|
|
147
|
+
such as loose comparison and integer overflow into floats, Composer packages mapped to crates),
|
|
148
|
+
and a PHP CLI or server can be recorded, replayed and put behind a Rust front door. Porting its
|
|
149
|
+
units into Rust through PHP's FFI is the next step ([issue #2](https://github.com/erkamyaman/rust-anything/issues/2)).
|
|
150
|
+
|
|
151
|
+
C# is in preview the same way: `analyze` reads `.csproj` projects and their NuGet packages
|
|
152
|
+
(mapped to crates), resolves `using` directives to folders, and flags what C# does differently
|
|
153
|
+
(`decimal`, `dynamic`, LINQ's deferred queries, `Task`, `lock`, reflection). A C# CLI or ASP.NET
|
|
154
|
+
server can be recorded, replayed and put behind a Rust front door; porting units through P/Invoke
|
|
155
|
+
comes next.
|
|
138
156
|
|
|
139
157
|
## How it works
|
|
140
158
|
|
|
@@ -491,7 +509,6 @@ cargo fmt
|
|
|
491
509
|
|
|
492
510
|
Design choices and their reasons: [DECISIONS.md](./DECISIONS.md).
|
|
493
511
|
|
|
494
|
-
|
|
495
512
|
## Update or remove
|
|
496
513
|
|
|
497
514
|
```sh
|
|
@@ -531,6 +548,9 @@ usually lives outside the recording, so know where the edges are:
|
|
|
531
548
|
- **Anything not in the output.** Timing, memory, concurrency under load, and side effects other
|
|
532
549
|
than stdout, stderr, exit codes, written files and HTTP responses (network calls, databases,
|
|
533
550
|
signals) are not compared.
|
|
551
|
+
- **Other platforms.** A recording proves behavior on the machine that ran it. C whose results
|
|
552
|
+
depend on type sizes, endianness or the compiler can behave differently on the target; `analyze`
|
|
553
|
+
keeps hardware-facing C in C for that reason.
|
|
534
554
|
|
|
535
555
|
## FAQ
|
|
536
556
|
|
|
@@ -552,6 +572,39 @@ multiply-add and the math library differ between compilers. Record with `--float
|
|
|
552
572
|
(`record` or `app record`), and floats match within that share of the larger value (absolute below
|
|
553
573
|
1). Integers, text and structure still have to match exactly.
|
|
554
574
|
|
|
575
|
+
**Can it port an app I only have as an APK, a JAR or an .exe?** No. It ports source code: it
|
|
576
|
+
parses the functions, records what each one does, and checks the Rust against the running
|
|
577
|
+
original. A compiled app has none of that to work with, and `analyze` says so. Writing a new Rust
|
|
578
|
+
app from a binary's visible behavior is a different project.
|
|
579
|
+
|
|
580
|
+
**Should I port battle-tested C?** Often not, and `analyze` tells you where. C that touches
|
|
581
|
+
hardware registers, relies on its compiler's type sizes or memory layout, or uses inline assembly
|
|
582
|
+
(`volatile`, bitfields, packed structs, `__asm__`, integers cast to addresses) is marked "keep in
|
|
583
|
+
C": a recording on your machine proves nothing about the target, and stable driver or firmware
|
|
584
|
+
code gains little from a rewrite. The portable logic around it (parsing, protocols, data handling)
|
|
585
|
+
is what moves well.
|
|
586
|
+
|
|
587
|
+
**Can it port my Electron app?** The logic, yes; the windows stay web pages. `analyze
|
|
588
|
+
--whole-app` spots Electron and plans the main process piece by piece while the renderer stays as
|
|
589
|
+
it is. Moving the UI to Tauri (the same web UI on a Rust backend) is a separate step once the logic
|
|
590
|
+
is Rust.
|
|
591
|
+
|
|
592
|
+
**What about C#, Kotlin or Swift?** C# is in preview (see [Languages](#languages)); Kotlin and
|
|
593
|
+
Swift are not supported yet. Each language needs a parser, a recorder, a bridge and a replay
|
|
594
|
+
driver, all tested end to end. Open an issue (or upvote one) for the language you need.
|
|
595
|
+
|
|
596
|
+
**Won't the Rust be much bigger than the original?** It shouldn't be. `gate` compares the port's
|
|
597
|
+
lines with the original's and fails above 3x (plus 50 lines for imports and signatures): that usually means hand-writing what a crate already
|
|
598
|
+
does, or handling cases one by one. `analyze` lists the crates to use.
|
|
599
|
+
|
|
600
|
+
**Doesn't porting piece by piece lock the Rust into the old app's design?** Only while both run
|
|
601
|
+
side by side. The recordings check behavior at the app's edges (a CLI's output, a server's
|
|
602
|
+
responses, a module's exported functions), not its internals. Mirror the old structure while
|
|
603
|
+
units still cross the bridge; once `app lift` has removed the original, restructure the Rust
|
|
604
|
+
freely, and `app replay` still proves the behavior. Nothing calls back into the original either:
|
|
605
|
+
the front door runs it as a separate process (or forwards HTTP to it), bridged units are called
|
|
606
|
+
by the original and never the other way round, and callbacks stay in the source language.
|
|
607
|
+
|
|
555
608
|
**Does my code leave my machine?** No: rust-anything runs locally and sends none of your code
|
|
556
609
|
anywhere. Cargo downloads crates as usual, and your agent's model provider sees what your agent
|
|
557
610
|
sends it, under its own policy.
|
|
@@ -561,12 +614,41 @@ sends it, under its own policy.
|
|
|
561
614
|
|
|
562
615
|
**Something broke.** Open an issue with the command, its output and your platform.
|
|
563
616
|
|
|
617
|
+
## Sponsors
|
|
618
|
+
|
|
619
|
+
rust-anything is free and open source. If it helps your work, please consider sponsoring it. Your support keeps development going.
|
|
620
|
+
|
|
621
|
+
<p>
|
|
622
|
+
<a href="https://github.com/sponsors/erkamyaman"><img src="https://img.shields.io/badge/Sponsor-%E2%9D%A4-db61a2?logo=githubsponsors&logoColor=white" alt="Sponsor rust-anything on GitHub" /></a>
|
|
623
|
+
</p>
|
|
624
|
+
|
|
625
|
+
### Company sponsors
|
|
626
|
+
|
|
627
|
+
<!-- prettier-ignore-start -->
|
|
628
|
+
<a href="https://coderabbit.ai"><img src="https://github.com/coderabbitai.png?size=120" width="120" height="120" alt="CodeRabbit" /></a>
|
|
629
|
+
<!-- prettier-ignore-end -->
|
|
630
|
+
|
|
631
|
+
### Individual sponsors
|
|
632
|
+
|
|
633
|
+
<!-- sponsors -->
|
|
634
|
+
<!-- prettier-ignore-start -->
|
|
635
|
+
<table>
|
|
636
|
+
<tbody>
|
|
637
|
+
<tr>
|
|
638
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/aliyilmazco"><img src="https://github.com/aliyilmazco.png?size=100" width="80px;" alt="Ali Yilmaz"/><br /><sub><b>Ali Yilmaz</b></sub></a></td>
|
|
639
|
+
</tr>
|
|
640
|
+
</tbody>
|
|
641
|
+
</table>
|
|
642
|
+
<!-- prettier-ignore-end -->
|
|
643
|
+
<!-- /sponsors -->
|
|
644
|
+
|
|
564
645
|
## Contributing
|
|
565
646
|
|
|
566
|
-
Issues and pull requests are welcome.
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
647
|
+
Issues and pull requests are welcome; [CONTRIBUTING.md](./CONTRIBUTING.md) covers the setup, where
|
|
648
|
+
tests go, and how to add a language. Design choices and their reasons are in
|
|
649
|
+
[DECISIONS.md](./DECISIONS.md). Case studies of real ports are especially welcome. Please report
|
|
650
|
+
security problems privately ([SECURITY.md](./SECURITY.md)), and see the
|
|
651
|
+
[code of conduct](./CODE_OF_CONDUCT.md).
|
|
570
652
|
|
|
571
653
|
## License
|
|
572
654
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rust-anything",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Rewrite your app in Rust, one piece at a time, checked against the original's recorded behavior at every step. TypeScript, Python, C, Go, Ruby, Java.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rust",
|