TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How to rewrite it in Rust

238 pointsby FBTover 5 years ago

6 comments

sorenbsover 5 years ago
We did a similar thing with a Scala -&gt; Rust rewrite for the <a href="http:&#x2F;&#x2F;prisma.io" rel="nofollow">http:&#x2F;&#x2F;prisma.io</a> query engine.<p>By rewriting small components and integrating them into the existing project using Javas native interface, our small team of 5 developers were able to pull off this massive rewrite in just under a year. The resulting code base is rearchitected in a few very important ways, but mostly follows the same structure.<p>And because we kept and evolved our old Scala based test suite, we have a very high confidence in the rewrite.<p>When Async&#x2F;.await finally landed, we could switch over very quickly, and it has been a joy to focus on benchmarks and performance over the last month. Spoiler: Rust is faster than Scala :-D
评论 #21682988 未加载
评论 #21682232 未加载
评论 #21691340 未加载
评论 #21683421 未加载
评论 #21684518 未加载
pornelover 5 years ago
This ability to incrementally add Rust to a C codebase is very useful for adopting Rust in established projects.<p>You don&#x27;t actually have to rewrite everything on day one. You can stop writing new C code right now, and then gradually replace old code only when you need to fix it or refactor it.
评论 #21682103 未加载
评论 #21682332 未加载
saagarjhaover 5 years ago
&gt; However, Rust has a killer feature when it comes to this sort of thing. It can call into C code with no overhead (i.e. the runtime doesn’t need to inject automatic marshalling like C#’s P&#x2F;Invoke) and it can expose functions which can be consumed by C just like any other C function.<p>As we see below, you may still need to write some code to convert from C types to something that is more ergonomic to use in Rust. But the marshaling ABI-wise is minimal.<p>&gt; Turns out the original tinyvm will crash for some reason when you have multiple layers of includes<p>It&#x27;s actually crashing because there are no lines of code in the file, so certain data structures never get initialized.
评论 #21688034 未加载
ridiculous_fishover 5 years ago
&gt; This is where build scripts come in. Our strategy will be for the Rust crate to use a build.rs build script and the cc crate to invoke the equivalent commands to our make invocation<p>Yikes - port the entire build system to cargo before you write a line of Rust. Now draw the reset of the owl!<p>Surely&#x27;s there&#x27;s an incremental path for the build as well? Perhaps if you&#x27;re using CMake?
评论 #21684414 未加载
评论 #21684571 未加载
staticassertionover 5 years ago
Great guide, this looked surprisingly straightforward.
评论 #21682028 未加载
bfrogover 5 years ago
This seems exactly what remacs is doing with emacs.