I know you are itching to start making games, but we need to do a small amount of setup first.
All Bevy app and engine code is written in Rust. This means that before we begin, we need to set up our Rust development environment.
Install Rust by following the Rust Getting Started Guide.
Once this is done, you should have the rustc
compiler and the cargo
build system installed in your path.
You can use any code editor you want, but we highly recommend one that has a Rust Analyzer plugin. Rust Analyzer is still in development, but it already provides top-tier autocomplete and code intelligence. Visual Studio Code has an officially supported Rust Analyzer Extension.
The goal of this book is to learn Bevy, so it won't serve as a full Rust education. If you would like to learn more about the Rust language, check out the following resources:
Now we are ready to set up a Bevy project! Bevy is just a normal Rust dependency. You can either add it to an existing Rust project or create a new one. For completeness we will assume you are starting from scratch.
First, navigate to a folder where you want to create your new project. Then, run the following command to create a new folder containing our rust executable project:
cargo new my_bevy_game
cd my_bevy_game
Now run cargo run
to build and run your project. You should see Hello, world!
printed to your terminal. Open the my_bevy_game
folder in your code editor of choice and take some time to look through the files.
main.rs
is the entry point of your program:
fn main() {
println!("Hello, world!");
}
Cargo.toml
is your "project file". It contains metadata about your project such as its name, dependencies, and build configuration.
[package]
name = "my_bevy_game"
version = "0.1.0"
authors = ["You <you@veryrealemail.com>"]
edition = "2018"
[dependencies]
Bevy can be built just fine using default configuration on stable Rust. However for maximally fast iterative compiles, we recommend the following configuration:
bevy
as a dependency you can run your app with dynamic linking like this:
cargo run --features bevy/dynamic
sudo apt-get install lld
sudo pacman -S lld
cargo install -f cargo-binutils
rustup component add llvm-tools-preview
brew install michaeleisel/zld/zld
# Install the nightly toolchain
rustup toolchain install nightly
# Configure your current project to use nightly (run this command within the project)
rustup override set nightly
# OR configure cargo to use nightly for all projects -- switch back with `rustup default stable`
rustup default nightly
cargo +nightly ...
if you don't want to change the default to nightly.To enable fast compiles, install the nightly rust compiler and LLD. Then copy this file to YOUR_WORKSPACE/.cargo/config.toml
. For the project in this guide, that would be my_bevy_game/.cargo/config.toml
.
Bevy is available as a library on crates.io, the official Rust package repository. Find the latest version number () and add it to your Cargo.toml file:
[package]
name = "my_bevy_game"
version = "0.1.0"
authors = ["You <you@veryrealemail.com>"]
edition = "2018"
[dependencies]
bevy = "0.4" # make sure this is the latest version
Run cargo run
again. The Bevy dependencies should start building. This will take some time as you are essentially building an engine from scratch. You will only need to do a full rebuild once. Every build after this one will be fast!
If something went wrong, check out our troubleshooting section or ask for help on our Discord.
Now that we have our Bevy project set up, we're ready to start making our first Bevy app!