What is the Experience of Rewriting Nearly 60,000 Lines of C++ Code in Rust?

From WeChat Official Account:OSC Open Source Community

Link: https://www.oschina.net/news/327176/fishshell-rustport

Fish is a command-line shell for Linux and macOS, known for its ease of use, powerful features, intelligence, and user-friendliness.Many features that other shells require configuration for are provided by default in fish, without any setup needed.

What is the Experience of Rewriting Nearly 60,000 Lines of C++ Code in Rust?

At the beginning of 2023, the author of fish announced that the Fish Shell project would be rewritten in Rust.

What is the Experience of Rewriting Nearly 60,000 Lines of C++ Code in Rust?The reasons for the rewrite include:

  • No one really likes C++ or CMake, and there is no clear way to get rid of the old toolchain. The “developer pain” increases every year.
  • C++ is becoming a “legacy language”, making it harder to find contributors in the future, while Rust has an active and growing community.
  • Rust is the language needed for implementing concurrent function execution.
  • Writing in Rust will help fish continue to be seen as modern and valuable.

Now, nearly two years later, fish 4.0 has recently released its first beta, and the developers claim that this version contains 0% C++ and almost 100% pure Rust code.

They stated that the migration of the fish shell codebase from C++ to Rust has been initially successful, and the data shows that this is a massive undertaking:

  • 1,155 file changes, 110,247 additions (+), 88,941 deletions (-), excluding transcriptions
  • Over 200 contributors submitted 2,604 contributions
  • 498 issues
  • Nearly 2 years of development cycle
  • Rewriting 57,000 lines of C++ code into 75,000 lines of Rust (plus 400 lines of C)
  • Thoroughly cleaned up C++ code

The Fish Shell team also stated that the benefits of migrating to Rust have become apparent over time. For example, the previous (n) curses issues are now gone because they no longer use curses. Instead, they switched to using Rust crate packages, which meet their needs well, allowing access to terminfo and extending its sequences.This eliminates some awkward global states and means that those building from source no longer need to ensure that curses is “correctly” installed on their systems — just download a crate package and build it.The development team also mentioned some regrets, such as the goal of removing CMake during this C++ code rewrite was not achieved.This is because while cargo excels in building, it is quite rudimentary in installation.Cargo aims to put everything into a few neat binaries, but this does not apply to their project.

Fish has about 1,200 .fish scripts (961 completions, 217 related functions), as well as about 130 pages of documentation (in HTML and man page formats), along with web-config tools and man page generators (both written in Python).

Overall:

“The porting process has not been smooth, and not everything has gone according to plan. But overall, the progress has been quite smooth.

We now have a codebase that we really like, with added features that were difficult to achieve in the C++ era, and more features are in development.

We also created a separate version 3.7, which includes some cool things. We are happy to be doing this.

Related Sources

https://fishshell.com/blog/rustport

https://github.com/fish-shell/fish-shell/pull/9512

—END—

Leave a Comment