Installing Rust
Create new project:
- In your terminal run these commands:
- After running above commmands, your project folder will have a tree structure like this:
│ Cargo.lock
│ Cargo.toml
├───src
| main.rs
└───target
main.rs
is your Root Crate which is the entry point of the program:
Cargo.toml
is the “project file” which includes:
- Metadata
- Dependencies
- Build configs
Add Bevy to the project:
- Method 1:
cargo add bevy
.
- Method 2: Add the following line
bevy = "*"
to your toml file:
*
means it will get the latest version of bevy crate. If you want to pick a specific version go to this website and check the version Bevy.
Compiling optimization:
- In case you want to debug the game, the complication is super slow for doing that. To optimize it, add these following lines in your toml file:
Optional:
Feature:
- Enable bevy’s dynamic linking Feature:
- Run
cargo run --features bevy/dynamic_linking
each time.
- If you don’t want to do it each run then add the following feature to your toml file:
Compiler:
- Nightly Rust Compiler: Not stable but this gives lightly performance than the stable rust.
- Create “rust-toolchain.toml” file
- Then put following code:
Linker:
- Choose one of following linkers:
- Use LLD linker:
- Use mold linker: x5 faster than LLD linker but not stable and not Windows support
- Ubuntu:
sudo apt-get install mold clang
Enable fast compiles:
- Install both LLD linker and nightly rust compiler.
- Put
.cargo/config.toml
next to src
folder.
- Copy following code in the url to
config.toml
file: link
Rebuild:
- Build your project again to see the significant change.
- The first time may be slow but after that it will be fast.