Turborepo migrates from Go to Rust
The build system is starting to incrementally adopt Rust in their project
Vercel has been continuously updating and innovating their product lineups. From introducing a scheduler last month to introducing Next 13.2 - the latest stable version of Next.js, they are on a roll. And now they have announced the latest interesting update on one of their products.
Turborepo, the build system from Vercel is migrating from Go to Rust incrementally. Although Go is still a integral part of the tool, it is slowly migrating away from it. One of the most important aspects of Turborepo is the support for monorepos.
Turborepo improves development speeds by offering multiple features like incremental builds, parallel execution and remote caching.
Turborepo is inspired from esbuild, the awesome build tool for javascript written in Go. Naturally Vercel chose Go as their language for Turborepo.
Language migration is a demanding task. There's a lot to consider and the decision shouldn't be taken lightly. But instead of simply comparing the pros, cons and other aspects of a language (those doesn’t matter in a large scale most of the time), it is important to consider certain design choices and the scenarios the language is envisioned to be used for.
Go's strength is network computing in data centers and it excels at this task, powering these workloads at the world's largest scales. The goroutine-per-request model, Context API, and the standard library inclusion of server infrastructure is testament to this community focus. Go is also particularly simple in its syntax. Although, sometimes the syntax can be quite limiting and weird, it works most of the time.
The Turborepo team points out the same as their reason for the switch: “Additionally, Go favors simplicity over expressiveness. A side effect of that decision means more errors are caught at runtime where other languages might catch them at compilation. With a service running in a data center, you can roll back, fix, and roll forward at your convenience. But, when building software that users install, the cost of each mistake is higher. For us, it's worth using tools that prioritize up-front correctness. We fully recognize the mismatch of Go's priorities and what we are prioritizing as a problem that we created for ourselves to solve.”
That’s quite an interesting case to know. But does rust emphasize on compile time errors. You bet!
Unlike Go, which is focussed on networks, servers and large scale systems, Rust focusses on correctness over abstraction which provides a lot more control in aspects like process management, file systems, os, etc.
Since being a software that is shipped to client devices, it makes sense.
“Rust's type system and safety features allow us to put guardrails in place in our codebase where we need them. The language's expressiveness allows our developers to encode constraints that catch errors at compile time rather than in GitHub issues.”
One more reason is the ability to interop with C/C++. A majority of low level libraries are still developed and maintained in C and C++. But newer developers want a safe language and also some ability to interface with those languages. Rust provides exactly that.
Rust has an unsafe alter ego is that the underlying computer hardware is inherently unsafe. If Rust didn’t let you do unsafe operations, you couldn’t do certain tasks.Rust has a FFI interface. It provides a keyword “extern” to allow rust code to invoke C code. Here is an example from the rust book:
extern "C" {
fn abs(input: i32) -> i32;
}
fn main() {
unsafe {
println!("Absolute value of -3 according to C: {}", abs(-3));
}
}
Rust makes us happy
Another important aspect the team provides is since Rust allows them to be flexible and does not get in their way, it makes the team happy. It is not unique to Turborepo team. In fact, Rust is the most desired language for the past 4 years in Stack Overflow surveys.
Rust finds its way into a majority of web and other software tooling these days partly because of the correctness and dev satisfaction.
Let’s see how this turns out for the Turborepo team.
Here is the announcement blog: https://vercel.com/blog/turborepo-migration-go-rust