Rust on Dreamcast: Difference between revisions

From dreamcast.wiki
Jump to navigation Jump to search
No edit summary
Line 4: Line 4:
* gccrs: a Rust frontend for GCC
* gccrs: a Rust frontend for GCC


==rustc_codegen_gcc==
=rustc_codegen_gcc=
GCC includes a component called '''libgccjit''' which provides an API for an embeddable just-in-time code generator using GCC, useful for creating programs like interpreters. However, this component can also be used to generate code ahead of time as well. '''rustc_codegen_gcc''' is a project which interfaces the official Rust compiler with the libgccjit API to generate machine code from Rust using the GCC backend. With this, we can compile Rust programs for Dreamcast using familiar compiler tools such as <code>rustc</code> and <code>cargo</code>! The familiar borrow checker still works, and one can write <code>#![no_std]</code> crates with full <code>libcore</code> support. An experimental crate binding with [[KallistiOS]] provides <code>liballoc</code> functionality such as a heap and familiar collections like Vec, String, etc. as well.
GCC includes a component called '''libgccjit''' which provides an API for an embeddable just-in-time code generator using GCC, useful for creating programs like interpreters. However, this component can also be used to generate code ahead of time as well. '''rustc_codegen_gcc''' is a project which interfaces the official Rust compiler with the libgccjit API to generate machine code from Rust using the GCC backend. With this, we can compile Rust programs for Dreamcast using familiar compiler tools such as <code>rustc</code> and <code>cargo</code>! The familiar borrow checker still works, and one can write <code>#![no_std]</code> crates with full <code>libcore</code> support. An experimental crate binding with [[KallistiOS]] provides <code>liballoc</code> functionality such as a heap and familiar collections like Vec, String, etc. as well.


===Building a cross-compiling libgccjit.so for rustc_codegen_gcc===
==Building a cross-compiling libgccjit.so for rustc_codegen_gcc==
===Building rustc_codegen_gcc===
==Building rustc_codegen_gcc==
===Creating a new project using Cargo===
==Creating a new project using Cargo==
===Compiling individual modules into object files with rustc===
==Compiling individual modules into object files with rustc==


==gccrs==
=gccrs=
gccrs implements a Rust compiler frontend for GCC. This essentially means implementing a new Rust compiler from the ground up using the GCC toolchain infrastructure. This project is in early stages and is targeting the Rust 1.49 revision from December 2020. As of this writing (February 2024), it is not yet able to compile Rust's <code>libcore</code>, so many basic language features are unimplemented or not functional. Additionally, Rust standard tooling like <code>cargo</code> is not available, nor is borrow checking implemented. It is possible to use this compiler by compiling either GCC 14.0.1-dev or GCCRS git repo.
gccrs implements a Rust compiler frontend for GCC. This essentially means implementing a new Rust compiler from the ground up using the GCC toolchain infrastructure. This project is in early stages and is targeting the Rust 1.49 revision from December 2020. As of this writing (February 2024), it is not yet able to compile Rust's <code>libcore</code>, so many basic language features are unimplemented or not functional. Additionally, Rust standard tooling like <code>cargo</code> is not available, nor is borrow checking implemented. It is possible to use this compiler by compiling either GCC 14.0.1-dev or GCCRS git repo.
==Building a GCCRS-enabled toolchain==
==Setting up Makefiles to compile Rust modules==

Revision as of 19:43, 31 January 2024

Preliminary support exists for developing for the Dreamcast using the Rust programming language. This is a bit of a challenge, however, as the official Rust compiler is based on the LLVM toolchain infrastructure, which does not support the Dreamcast's CPU SuperH architecture. Dreamcast programming is instead done with GCC, the GNU Compiler Collection. There exists two solutions to this problem:

  • rustc_codegen_gcc: A libgccjit codegen backend for rustc (preferred method)
  • gccrs: a Rust frontend for GCC

rustc_codegen_gcc

GCC includes a component called libgccjit which provides an API for an embeddable just-in-time code generator using GCC, useful for creating programs like interpreters. However, this component can also be used to generate code ahead of time as well. rustc_codegen_gcc is a project which interfaces the official Rust compiler with the libgccjit API to generate machine code from Rust using the GCC backend. With this, we can compile Rust programs for Dreamcast using familiar compiler tools such as rustc and cargo! The familiar borrow checker still works, and one can write #![no_std] crates with full libcore support. An experimental crate binding with KallistiOS provides liballoc functionality such as a heap and familiar collections like Vec, String, etc. as well.

Building a cross-compiling libgccjit.so for rustc_codegen_gcc

Building rustc_codegen_gcc

Creating a new project using Cargo

Compiling individual modules into object files with rustc

gccrs

gccrs implements a Rust compiler frontend for GCC. This essentially means implementing a new Rust compiler from the ground up using the GCC toolchain infrastructure. This project is in early stages and is targeting the Rust 1.49 revision from December 2020. As of this writing (February 2024), it is not yet able to compile Rust's libcore, so many basic language features are unimplemented or not functional. Additionally, Rust standard tooling like cargo is not available, nor is borrow checking implemented. It is possible to use this compiler by compiling either GCC 14.0.1-dev or GCCRS git repo.

Building a GCCRS-enabled toolchain

Setting up Makefiles to compile Rust modules