To get started with Tetra, you'll need a couple of things installed:
- Rust 1.31 or higher
- The SDL 2.0 development libraries
- The ALSA development libraries (only required on Linux)
Most of this is one-time setup, so let's get it out of the way!
Installing Rust is pretty simple - just go to the website and download the Rustup toolchain manager.
Note that if you're developing on Windows with the default toolchain, you'll also need to install the Microsoft Visual C++ Build Tools, as Rust uses the MSVC linker when building.
Installing SDL 2.0
Tetra uses SDL for windowing and input, so you will need to have both the runtime and development libraries installed.
The instructions below are adapted from the README of the sdl2 crate - further information can be found there.
If you're using the default MSVC Rust toolchain:
- Go to the SDL website and download the Visual C++ version of the development libraries.
- Copy the
.libfiles from the
SDL2-2.0.x/lib/x64folder of the zip to the
%USERPROFILE/.rustup/toolchains/stable-x86_64-pc-windows-msvc/lib/rustlib/x86_64-pc-windows-msvc/libfolder on your machine. If you are building on a beta/nightly toolchain, adjust the location accordingly.
If you're using the GNU-based Rust toolchain:
- Go to the SDL website and download the MinGW version of the development libraries.
- Copy the
.libfiles from the
SDL2-2.0.x/x86_64-w64-mingw32/libfolder of the zip to the
%USERPROFILE/.rustup/toolchains/stable-x86_64-pc-windows-gnu/lib/rustlib/x86_64-pc-windows-gnu/libfolder on your machine. If you are building on a beta/nightly toolchain, adjust the location accordingly.
The easiest way to install SDL is via Homebrew:
brew install sdl2
You will also need to add the following to your
~/.bash_profile, if it is not already present.
The SDL development libraries are distributed through most Linux package managers - here are a few examples:
# Ubuntu/Debian sudo apt install libsdl2-dev # Fedora/CentOS sudo yum install SDL2-devel # Arch Linux sudo pacman -S sdl2
Installing ALSA (Linux only)
On Linux, ALSA is used as the audio backend, so you will also need the ALSA development libraries installed. Similar to SDL, you can find these libraries on most Linux package managers:
# Ubuntu/Debian sudo apt install libasound2-dev # Fedora/CentOS sudo yum install alsa-lib-devel # Arch Linux sudo pacman -S alsa-lib
Creating a New Project
Now that you've got the dependencies set up, we can start making a game!
First, create a new Cargo project:
cargo new --bin my-first-tetra-game
Then, add Tetra as a dependency in
[dependencies] tetra = "0.2"
If you're on Windows, you'll need to place the SDL2 .dll in the root of your project (and alongside your .exe when distributing your game). You can download this from the 'runtime binaries' section of the SDL website.
Once those steps are complete, you're ready to start writing your first game with Tetra!