|
| 1 | +--- |
| 2 | +title: "The Road to Rust" |
| 3 | +author: Naev DevTeam |
| 4 | +tags: [ 'development' ] |
| 5 | +blurb: Naev has started to be ported to Rust, a more inherently safe language. |
| 6 | +--- |
| 7 | + |
| 8 | +A long project in the making, the Naev DevTeam is now proud to announce that |
| 9 | +Naev is now partially written in [Rust programming |
| 10 | +language](https://www.rust-lang.org/). While still only about 5% of the C code |
| 11 | +has been rewritten, it includes many of the critical components such as the |
| 12 | +most of the rendering pipeline and initialization bits. The porting is being |
| 13 | +done in tandem with general development, so C and Rust will co-exist for a |
| 14 | +while until the port is completed and C can be dropped as necessary. Scripting |
| 15 | +will still be in Lua, which will be much easier to develop using |
| 16 | +[mlua](https://docs.rs/mlua/latest/mlua/index.html) from Rust. |
| 17 | + |
| 18 | +## What does this mean? |
| 19 | + |
| 20 | +Short-term, it means it is likely there will be more bugs and quirks, however, |
| 21 | +in the longer picture, this means that Naev will be able to make use of the |
| 22 | +inherent memory and threading safety of Rust to be much more bug-free. Rust |
| 23 | +also makes it possible to simplify significant parts of the code and thread |
| 24 | +them more easily, meaning that it is likely that performance will also go up |
| 25 | +over time. |
| 26 | + |
| 27 | +The porting is also a good way to revise the existing codebase. With the first |
| 28 | +commit being 18 years ago, as you can expect, some parts have not aged too |
| 29 | +well. Rewriting the code in Rust will not only help modernize it, but also |
| 30 | +streamline it so that many more improvements can be easily made. Some |
| 31 | +particular example of something that will become easily possible is |
| 32 | +implementing mechanisms to modify the number of outfit slots on a ship via |
| 33 | +outfits. |
| 34 | + |
| 35 | +## What has been done? |
| 36 | + |
| 37 | +While the port is far from over, very important aspects have already been moved |
| 38 | +to Rust side including initialization, rendering, and Lua scripting. Some |
| 39 | +low-hanging fruits have also been grabbed as a proof of concept including |
| 40 | +things like the 2D vector Lua library, damage types, and slot types. The entire |
| 41 | +build system has also been rehauled to have C and Rust work somewhat happily |
| 42 | +together. Besides having to file a lot of bug reports upstream to |
| 43 | +[meson](https://mesonbuild.com/) and other projects, we now figured it out with |
| 44 | +lots of not so beautiful tricks to compile both a C and Rust library |
| 45 | +separately, and then link them together in Rust. It's a bit hacky, but it seems |
| 46 | +to work well for the time being. |
| 47 | + |
| 48 | +## What can you do to help? |
| 49 | + |
| 50 | +There is a lot of work left to still be done. Good thing is that anyone can |
| 51 | +help! If you want to help with porting, you can look at the [issue on rust |
| 52 | +porting](https://github.com/naev/naev/issues/2890) that tries to centralize |
| 53 | +work being done on Rust. If you don't want to do Rust, you can also help as |
| 54 | +always by testing the nightly and reporting any issues that you may find. |
| 55 | + |
| 56 | +As always, help is also needed with artwork, sound effects, and music, |
| 57 | +including [graphics for |
| 58 | +outfits](https://github.com/naev/naev/wiki/Needed-Artwork%3A-Outfits) and [new |
| 59 | +portraits](https://github.com/naev/naev/wiki/Needed-Artwork%3A-Characters). |
0 commit comments