Getting Started with Rust on Playdate
The Panic Playdate is a tiny, just-for-fun indie game console. Rust is a drop-in replacement for C that is fast and memory safe. This post will discuss getting started with the Panic Playdate using Rust. It is a follow-up to my post on getting started with Playdate.
crank and crankstart will be used because they are working, existing solutions for using Rust to develop applications for the Playdate. The post will cover installation, running examples, as well as building and running a couple of existing crankstart projects: Klondike solitaire, and Nine Lives.
Familiarity with Rust and the command line are assumed. It is also assumed that the Playdate SDK has already been installed from the Playdate Developer Page and that Rust has been installed with rustup.
Software Versions
Instructions
Installation
First, install crank according to the README.
Next, clone the crankstart repository to run the examples.
Running Examples
The hello_world and life examples can simply be run.
Assets from the C_API need to be copied in before running the sprite_game example.
Klondike Solitaire
The author of crank and crankstart wrote a Klondike solitaire game in Rust. Use the following commands to build and run it.
Nine Lives
A third party, bravely, wrote the Nine Lives game in Rust. It can be built and run as follows.
Running on Hardware
cargo-xbuild is required to build for hardware.
xbuild requires source to be installed, so it needs to be installed with rustup.
The build subcommand takes a –device flag that can be used to target hardware exclusively. Alternatively, the package subcommand can be used to build binaries for both the device and the simulator. To upload a PDX file to hardware, first, run it in the simulator. Then either “Upload Game to Device” from the “Device” menu or Playdate icon on the lower lefthand corner of the simulator (with the crank controls collapsed). Once the game is on the device, pdutil can be used to launch it.
The run subcommand should work like the build subcommand, but it is not working on the author’s machice in the latest version of the SDK. The latest version of the SDK also seems to have trouble booting PDX files with spaces in the filename using the simulator and pdutil, but the game can be launched on the device after it has been uploaded.
More Information
Note that the Playdate C API documentation (and to a lesser extent, the Lua documentation) are useful when developing applications in Rust. This post is based on the Rust development thread from the Playdate Developer Forum.
References:
- crank, cargo wrapper for building and running Playdate software
- crankstart, Klondike Solitaire
- crankstart, Rust crate for Playdate application development
- crankstart, Nine Lives
- Playdate C API Documentation
- Playdate Developer Forum
- Playdate Developer Forum, Rust Development Thread
- Playdate Developer Page
- Playdate Homepage
- Playdate Lua Documentation
- Playdate, Getting Started with
- Playdate SDK, Latest
- Rust Homepage
- Rust, rustup
- Rust, cargo-xbuild