HN
Today

Bun is being ported from Zig to Rust

Bun, the JavaScript runtime, is undertaking a massive, AI-assisted port of its codebase from Zig to Rust. This ambitious move has ignited fiery debate on HN, dissecting the merits of both systems languages and the contentious practice of 'vibe coding' at such scale. The community is also grappling with the implications for Bun's future, particularly after its acquisition by AI powerhouse Anthropic, and its strained relationship with the Zig project.

492
Score
348
Comments
#1
Highest Rank
11h
on Front Page
First Seen
May 5, 1:00 AM
Last Seen
May 5, 11:00 AM
Rank Over Time
11123435533

The Lowdown

A GitHub commit reveals a detailed "Phase-A porting guide" for Bun's ambitious project to translate its codebase from Zig to Rust. This document outlines a rigorous, file-by-file methodology aimed at producing a faithful, though initially non-compiling, Rust draft.

  • The guide stresses meticulous adherence to Zig's original logic, even for unsafe operations, requiring mirrored // SAFETY: annotations.
  • It lays down strict ground rules, including specific file naming conventions, crate structuring, and a blanket ban on standard Rust async/IO libraries like tokio or std::fs, as Bun intends to retain control over its event loop and syscalls.
  • Extensive mapping tables are provided for translating Zig types, idioms (e.g., Option<T> for ?T, Result<T, Error> for anyerror!T), and library constructs into their Rust equivalents.
  • A significant emphasis is placed on handling strings as raw byte slices (&[u8]) rather than UTF-8 validated &str, reflecting Bun's WTF-8 and arbitrary byte handling.
  • Specific guidance is given for memory management, distinguishing between arena-allocated data in AST/parser crates (bumpalo::Bump) and global mimalloc usage elsewhere.
  • Detailed instructions cover Rust equivalents for Zig's pointer types, ownership models (Box, Rc, Arc, intrusive types), and custom collection implementations for performance.
  • The document outlines precise requirements for interacting with JSC (JavaScriptCore) types, including JSValue ownership rules and host function signatures.
  • Finally, it lists elements not to be translated (e.g., redundant Zig @import lines) and mandates a PORT STATUS trailer comment for each ported file, indicating translation confidence and remaining tasks.

This guide serves as a testament to the complexity and systematic effort required for such a large-scale language migration, especially one involving deep systems-level concerns and the controversial integration of AI-assisted code generation.

The Gossip

Vibe Coding's Virtues & Vices

The use of AI (specifically Claude) to generate a substantial portion of the Rust codebase sparked a heated debate on HN. Many commenters questioned whether this constitutes 'vibe coding'—a term for LLM-generated code potentially lacking human review and understanding. Skeptics voiced concerns about the non-deterministic nature of LLMs, the potential for 'trash Rust code,' and the loss of historical knowledge and maintainability. Others were cautiously optimistic, suggesting that for a task like language porting, with a well-defined source and a comprehensive test suite, AI could be a powerful tool, especially given Anthropic's deep LLM expertise. Some pointed out the sheer volume of changes (hundreds of thousands of lines) made human review of every line improbable, if not impossible.

Zig's Instability & Bun's Backstory

A major theme was the motivation behind Bun's decision to port away from Zig. Many commenters speculated this was a direct response to Zig's "anti-AI" policy, which led to the rejection of Bun's previous contributions to the Zig compiler. Others cited Zig's pre-1.0 instability, frequent breaking changes, and the burden of maintaining a customized Zig fork as compelling technical reasons for the switch. The recent acquisition of Bun by AI powerhouse Anthropic was also highlighted as a likely factor, with some suggesting Anthropic's Rust-centric internal culture and its LLM capabilities played a role. Conversely, some defended Zig, pointing to detailed explanations from Zig maintainers that Bun's rejected changes had technical flaws, irrespective of AI involvement, and that Zig has achieved its own performance improvements.

Rust's Rigor & Runtime Relevance

Discussions also focused on Rust's suitability as Bun's new foundation. Proponents highlighted Rust's memory safety, robust type system, and mature ecosystem as benefits, arguing that its strictness could even help in catching LLM-generated errors. The porting guide's explicit ban on common Rust async/IO libraries like `tokio` and `std::fs` caught attention, indicating Bun's commitment to maintaining its custom event loop and low-level control. This was seen by some as a technically sound decision for a runtime, while others questioned the trade-offs regarding Rust's typically longer compile times, especially when dealing with such a large codebase. Some suggested that Rust's inherent complexity (e.g., borrow checker, metaprogramming) would still make a direct, line-by-line translation challenging, even for an LLM.

Community Crossroads & Cautionary Tales

The news sparked significant debate about the future of the Bun project and its relationship with its user and contributor base. Bun's lead developer clarified that the port is currently an experiment, not a committed rewrite, attempting to temper the community's strong reactions. However, many users expressed concerns about the project's direction, especially given existing unaddressed bugs and the perception of a shift towards 'vibe coding' over traditional human-led development. Some long-time Bun users declared they would move back to Node.js, citing a loss of trust. Others saw it as a fascinating case study in AI-assisted development, regardless of its ultimate success, while questioning the ethics and long-term implications for open-source project management and community contributions.