Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
zlfn committed Sep 13, 2024
2 parents 03fa7ed + 8d65131 commit 87e2938
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Rust-GB
Compile Rust code to GBZ80 (Work in Progress)
My primary language is not English. It is always welcome to point out the awkward parts of this README.
Compile Rust code to GBZ80 (Work in Progress)
My first language is not English. It is always welcome to point out the awkward parts of this README.

![image](https://github.com/user-attachments/assets/ad6be282-170f-4a05-9d38-55217396e232)

## How is this possible?
1. The Rust compiler can generate LLVM-IR for the ATMega328 processor. (which powers Arduino)
Expand All @@ -18,7 +20,7 @@ Thanks to GBDK, Z80 Assembly generated from Rust can call GBDK's low-level libra

My task is to wrap these functions in high-level Rust abstractions.

## Why Rust not C or ASM?
## Why use Rust instead of C or ASM?
1. Rust provides higher-level grammer than C like traits or generics.
2. Rust's memory stability helps you avoid to write incorrect code (even on a small device).
3. Putting everything aside, it's fun!
Expand All @@ -44,7 +46,20 @@ But if you want to do it, Here is the description below.
2. Build llvm-cbe in `./ext` directory.
follow [llvm-cbe](https://github.com/JuliaHubOSS/llvm-cbe)'s instruction to build it.
the path is `./ext/llvm-project/llvm/build/bin/llvm-cbe`
3. Command `cargo build-rom` will build your GB ROM to `./out/main.gb`
3. Execute `cargo build --release` in `./ext/rust-deps`
4. Now, `cargo build-rom` will build your GB ROM to `./out/main.gb`

```bash
# build GB ROM from Rust code
cargo build-rom

# build GB ROM from LLVM-IR
cargo llvm-rom
# ... from C code
cargo c-rom
# ... from ASM code
cargo asm-romm
```

## Build chain Description
### Rust bundling
Expand All @@ -57,7 +72,7 @@ Currently, nigtly Rust's LLVM version is 19. and LLVM-CBE's LLVM version is 17.

Keep compatibility through the replacement of new function or polyfill.
### LLVM-IR -> C
LLVM-CBE compile LLVM-IR to C code.
LLVM-CBE compile LLVM-IR to C code.
Unfortunetly, LLVM-CBE do not support some calling convention generated by Rust.
So, Some features from rust (like `alloc::Vec`) can not be used.

Expand All @@ -77,7 +92,6 @@ I used GBDK's build chain for this. GBDK's `lcc` link ASM with GBDK libraries an
* Call the GBDK library in Rust
* Use `core` or `alloc` libraries of Rust
### Can't do
* Some Rust functions use fast calling convention which not supported in `LLVM-CBE`. (`alloc::Vec` or `assert_eq!` etc.)
I'm finding a solution for it.
* Some Rust functions use fast calling convention which not supported in `LLVM-CBE`. (`alloc::Vec` or `assert_eq!` etc.<br>I'm finding a solution for it.
* External crates are likely not supported.

0 comments on commit 87e2938

Please sign in to comment.