Skip to content

cargo-generate template for a very simple bevy project. No optional features, fast compiles active, only bevy.

License

Notifications You must be signed in to change notification settings

laundmo/simple_bevy_template

Repository files navigation

Basic Bevy template

Basic Bevy project template to get started quickly.

Use this template with:

cargo generate laundmo/simple_bevy_template --allow-commands

Fast-compile config, optional during setup:

  • Mold (when on linux)
  • Nightly Rust (generics sharing)
    • Cranelift
    • Parallel frontend

Other useful files included:

  • Bacon config for running on save
  • KDE Window Rule for always on top without focus stealing
    • Import .kwinrule in the KDE "Window Rules" settings
    • Move window and detect properties, then click on checkmark for position and size to adjust to your screen layout

Re-compile time for small changes (string content):

time options OS/Kernel CPU RAM Disk
0.53s All 6.14.3-arch1-1 Ryzen 5800X 2x16GB CL16 DDR4 3200MT/s Samsung 980 PRO NVMe

Global cargo config / expert mode

Or: What is meant by "Skip generating cargo/toolchain config? (expert only)"?

I added that question for primarily myself, since i configure cargo with most of these options globally.

The downside of doing that is that it will cause cargo to complain about unstable options when trying to compile a project with the stable toolchain. This can be worked around by wrapping cargo in a shell function which runs with an extra config based on some conditions.

This is in my .zshrc - it defaults to nightly with fastcompiles config unless the local a rust-toolchain.toml (relative to call) specifies stable. You might want to adjust this, its supposed to serve as an example more than a finished solution.

function cargo() {
    if [[ -f "rust-toolchain.toml" ]]; then
        local channel=$(awk '/^channel =/ {print $3}' rust-toolchain.toml)
        
        # Don't pass extra config for stable
        if [[ $channel == *"stable"* ]]; then
            echo Running cargo with stable config
            command cargo "$@"
            return
        fi
    fi
    
    # Default behavior
    echo Running cargo with fastcompiles config
    command cargo --config ~/.cargo/config-fastcompiles.toml "$@"
    return
}
compdef _cargo cargo

This is my ~/.cargo/config-fastcompiles.toml - it matches pretty closely what is generated by this template, with the exception of setting opt-level in it instead of in Cargo.toml and configuring a global target dir so projects can share cache.

[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = [
  "-Clink-arg=-fuse-ld=/usr/bin/mold",

  # Nightly
  "-Zshare-generics=y",
  "-Zthreads=0",
]

[unstable]
codegen-backend = true

[profile.dev]
codegen-backend = "cranelift"
opt-level = 3

[profile.dev.package."*"]
codegen-backend = "llvm"
opt-level = 3

[build]
target-dir = "/home/a/rust-projects/GLOBAL_TARGET_DIR/"

About

cargo-generate template for a very simple bevy project. No optional features, fast compiles active, only bevy.

Topics

Resources

License

Stars

Watchers

Forks