Playdate development in Rust is broken.
How to avoid a Rust bug and set up Playdate development as of Sep. '22
Panic's handheld game console, the Playdate, can run games written in Rust. The usual way to write these is using the tools crank
and crankstart
, written by Rob Tsuk.
Unfortunately, there is an open bug in the Rust langauge itself which breaks compiling the standard library for Cortex M microprocessors. Currently this causes crank
to bail out of compiling for real Playdates (using the --device
) flag.
To skirt around this issue, we need to compile our own version of rustc with a fix applied, and use that to compile our game.
First, clone a fixed version of Rust from GitHub user 'japaric', because their PR to the main repo has not been approved yet:
git clone https://github.com/japaric/rust
cd rust
git checkout gh98378
Now, we need to configure Rust's build system.
cp config.example.toml config.toml
$EDITOR config.toml
Change the prefix
setting to something memorable, I chose /Users/adam/myrust
, and change extended
to true
, uncommenting the tools
line below - then save and exit your editor.
If you're on a default macOS installation, you won't have any binaries in $PATH
named python
, so I edited the shebang on line one of ./x.py
(Rust's build script) to say python3
instead.
Now, we can build and install Rust and its surrounding tools.
./x.py build && ./x.py install *
Congrats, you just built your own rustc.
Next, we need to build our own crank
.
git clone https://github.com/pd-rs/crank
cd crank
We need to patch crank to pay attention to our custom Rust version. Open src/main.rs
and change this section around line 625 to resemble the following:
let mut command = Command::new("/Users/adam/myrust/bin/cargo");
command.args(args);
info!("build command: {:?}", command);
Where the path in Command::new
points to the cargo
binary you built earlier.
Now, install crank using your custom cargo: /Users/adam/myrust/bin/cargo install --path . --force
Next we need to make sure that when crank calls build-std
to rebuild the Rust standard library, it builds our patched standard library. Since in our custom environment we don't have Rustup, we need to emulate having the rust-src
component installed by symlinking our cloned Rust repo into our myrust
directory:
cd ~/myrust/lib/rustlib
mkdir src && cd src
ln -s ~/cloned/rust ./rust
Where ~/cloned/rust
points to the Rust git repo we cloned from GitHub earlier.
Now, cd to the directory where the source for your Playdate game resides, and run the following:
export RUSTC=/Users/adam/myrust/bin/rustc
crank build --release --device
If all has gone well, you should get a working build of your game on to your Playdate without bailing during compilation. If so, you have successfully worked around the bug in rustc!
Back