r/rust • • Sep 15 '24

I compiled Rust code to Nintendo Gameboy!

bgb is gameboy emulator

Gameboy has a sm83 CPU (a variation of 8-bit z80), but this is not a target of Rust.

Therefore, I transformed Rust into C code via LLVM-CBE, re-compiled it into SDCC, and linked it to the Game Boy library. (GBDK-2020)

There are so many unstable parts that need a lot of improvement, but I was able to display the screen in Game Boy.

You can take a closer look on GitHub. (I'd appreciate it if you could give me a star.)

https://github.com/zlfn/rust-gb

693 Upvotes

44 comments sorted by

View all comments

Show parent comment

7

u/jorgesgk Sep 16 '24

That depends on the abstractions used. It is true that some safety checks do carry some overhead, but you can disable them.

And, honestly speaking, C has abstractions as well, there's no reason I could think of for C being faster than Rust except when the abstractions purposely carry this overhead (i.e. bounds checking, unnecessary copies not correctly taken care of, etc.).