Initial Commit
This commit is contained in:
22
.cargo/config.toml
Normal file
22
.cargo/config.toml
Normal file
@@ -0,0 +1,22 @@
|
||||
[target.x86_64-unknown-linux-gnu]
|
||||
linker = "clang"
|
||||
rustflags = [
|
||||
"-C", "link-arg=-fuse-ld=lld",
|
||||
"-C", "link-arg=-lxkbcommon",
|
||||
]
|
||||
|
||||
[target.x86_64-pc-windows-msvc]
|
||||
linker = "rust-lld.exe"
|
||||
|
||||
[target.x86_64-apple-darwin]
|
||||
rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/opt/llvm/bin/ld64.lld"]
|
||||
|
||||
# [unstable]
|
||||
# codegen-backend = true
|
||||
# [profile.dev]
|
||||
# codegen-backend = "cranelift"
|
||||
# [profile.dev.package."*"]
|
||||
# codegen-backend = "llvm"
|
||||
|
||||
[build]
|
||||
rustflags = ["-Z", "share-generics=y"]
|
45
.gitignore
vendored
Normal file
45
.gitignore
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
# Rust
|
||||
/target
|
||||
app-bevy/target
|
||||
lib-utils/target
|
||||
**/*.rs.bk
|
||||
Cargo.lock
|
||||
|
||||
# Nix
|
||||
result
|
||||
.direnv
|
||||
|
||||
# Editor-Specific
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Bevy
|
||||
/assets
|
||||
app-bevy/assets
|
||||
lib-utils/assets
|
||||
|
||||
# Misc
|
||||
.idea
|
||||
tmp/
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
|
||||
# Build artifacts
|
||||
*.o
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
*.wasm
|
||||
*.pyc
|
||||
node_modules/
|
||||
|
||||
# Backup Files
|
||||
*~
|
||||
|
0
.projectile
Normal file
0
.projectile
Normal file
33
Cargo.toml
Normal file
33
Cargo.toml
Normal file
@@ -0,0 +1,33 @@
|
||||
[workspace]
|
||||
members = [
|
||||
"app-bevy",
|
||||
"lib-utils",
|
||||
]
|
||||
resolver = "2" # wgpu/bevy need this
|
||||
|
||||
[workspace.package]
|
||||
version = "0.14.0"
|
||||
edition = "2021"
|
||||
|
||||
[workspace.dependencies]
|
||||
bevy = { version = "0.14.0", features = ["dynamic_linking", "wayland"] }
|
||||
log = { version = "*", features = ["max_level_debug", "release_max_level_warn"] }
|
||||
|
||||
[profile.dev]
|
||||
opt-level = 1
|
||||
|
||||
[profile.dev.package."*"]
|
||||
opt-level = 3
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
lto = "thin"
|
||||
|
||||
[profile.wasm-release]
|
||||
inherits = "release"
|
||||
opt-level = "s"
|
||||
lto = "thin"
|
||||
strip = "debuginfo"
|
||||
|
||||
[workspace.metadata.rust-analyzer]
|
||||
rustc_private = true
|
16
app-bevy/.gitignore
vendored
Normal file
16
app-bevy/.gitignore
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
# Rust
|
||||
/target
|
||||
**/*.rs.bk
|
||||
Cargo.lock
|
||||
|
||||
# Nix
|
||||
result
|
||||
.direnv
|
||||
|
||||
# Editor-specific for people using these
|
||||
.vscode
|
||||
.idea
|
||||
|
||||
# OS-specific for people using these
|
||||
.DS_Store
|
||||
Thumbs.db
|
19
app-bevy/Cargo.toml
Normal file
19
app-bevy/Cargo.toml
Normal file
@@ -0,0 +1,19 @@
|
||||
[package]
|
||||
name = "pong"
|
||||
version = { workspace = true }
|
||||
edition = { workspace = true }
|
||||
|
||||
[dependencies]
|
||||
bevy = { workspace = true }
|
||||
log = { workspace = true }
|
||||
lib-utils = { path = "../lib-utils" }
|
||||
|
||||
[features]
|
||||
default = ["bevy/dynamic_linking", "bevy/wayland"]
|
||||
nightly = ["bevy/dynamic_linking", "bevy/wayland"] # Remove dynamic_linking when shipping!
|
||||
|
||||
[package.metadata.rust-analyzer]
|
||||
rustc_private = true
|
||||
|
||||
[unstable]
|
||||
codegen-backend = true
|
89
app-bevy/src/main.rs
Normal file
89
app-bevy/src/main.rs
Normal file
@@ -0,0 +1,89 @@
|
||||
#![allow(dead_code)]
|
||||
use bevy::prelude::*;
|
||||
|
||||
use lib_utils::UtilsPlugin;
|
||||
|
||||
/* COMPONENTS:
|
||||
* Rust structs that implement the 'Component' trait */
|
||||
|
||||
#[derive(Component)]
|
||||
struct Position {
|
||||
x: f32,
|
||||
y: f32,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
struct Person;
|
||||
|
||||
#[derive(Component)]
|
||||
struct Name(String);
|
||||
|
||||
/* SYSTEMS:
|
||||
* Normal rust functions */
|
||||
|
||||
// EXAMPLE SYSTEMS
|
||||
fn print_position_system(query: Query<&Position>) {
|
||||
for position in &query {
|
||||
println!("position: {} {}", position.x, position.y);
|
||||
}
|
||||
}
|
||||
fn hello_world() {
|
||||
println!("hello world!");
|
||||
}
|
||||
|
||||
// STARTUP SYSTEMS
|
||||
fn add_people(mut commands: Commands) {
|
||||
commands.spawn((Person, Name("Elaina Proctor".to_string())));
|
||||
commands.spawn((Person, Name("Renzo Hume".to_string())));
|
||||
commands.spawn((Person, Name("Zayna Nieves".to_string())));
|
||||
}
|
||||
|
||||
// OTHER SYSTEMS
|
||||
fn greet_people(time: Res<Time>, mut timer: ResMut<GreetTimer>, query: Query<&Name, With<Person>>) {
|
||||
if timer.0.tick(time.delta()).just_finished() {
|
||||
for name in &query {
|
||||
println!("hello {}!", name.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn update_people(mut query: Query<&mut Name, With<Person>>) {
|
||||
for mut name in &mut query {
|
||||
if name.0 == "Elaina Proctor" {
|
||||
name.0 = "Elaina Hume".to_string();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* RESOURCES:
|
||||
* */
|
||||
#[derive(Resource)]
|
||||
struct GreetTimer(Timer);
|
||||
|
||||
/* ENTITIES:
|
||||
* a simple type containing a unique integer */
|
||||
struct Entity(u64);
|
||||
|
||||
/* PLUGINS
|
||||
* */
|
||||
pub struct HelloPlugin;
|
||||
impl Plugin for HelloPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(GreetTimer(Timer::from_seconds(2.0, TimerMode::Repeating)))
|
||||
.add_systems(Startup, add_people)
|
||||
.add_systems(Update, (update_people, greet_people).chain());
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins((DefaultPlugins, HelloPlugin))
|
||||
.add_plugins(UtilsPlugin)
|
||||
// .add_systems(Startup, (
|
||||
// )
|
||||
// )
|
||||
// .add_systems(Update, (
|
||||
// )
|
||||
// )
|
||||
.run();
|
||||
}
|
96
flake.lock
generated
Normal file
96
flake.lock
generated
Normal file
@@ -0,0 +1,96 @@
|
||||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1710146030,
|
||||
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1725103162,
|
||||
"narHash": "sha256-Ym04C5+qovuQDYL/rKWSR+WESseQBbNAe5DsXNx5trY=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "12228ff1752d7b7624a54e9c1af4b222b3c1073b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1718428119,
|
||||
"narHash": "sha256-WdWDpNaq6u1IPtxtYHHWpl5BmabtpmLnMAx0RdJ/vo8=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "e6cea36f83499eb4e9cd184c8a8e823296b50ad5",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"rust-overlay": "rust-overlay"
|
||||
}
|
||||
},
|
||||
"rust-overlay": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1725243956,
|
||||
"narHash": "sha256-0A5ZP8uDCyBdYUzayZfy6JFdTefP79oZVAjyqA/yuSI=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "a10c8092d5f82622be79ed4dd12289f72011f850",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
69
flake.nix
Normal file
69
flake.nix
Normal file
@@ -0,0 +1,69 @@
|
||||
{
|
||||
description = "Minimal Rust development environment for Bevy project";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
rust-overlay.url = "github:oxalica/rust-overlay";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs =
|
||||
{
|
||||
nixpkgs,
|
||||
rust-overlay,
|
||||
flake-utils,
|
||||
...
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (
|
||||
system:
|
||||
let
|
||||
overlays = [ (import rust-overlay) ];
|
||||
pkgs = import nixpkgs { inherit system overlays; };
|
||||
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
|
||||
extensions = [
|
||||
"rust-src"
|
||||
"rust-analyzer"
|
||||
"clippy"
|
||||
];
|
||||
};
|
||||
in
|
||||
{
|
||||
devShells.default = pkgs.mkShell {
|
||||
nativeBuildInputs = with pkgs; [ pkg-config ];
|
||||
buildInputs = with pkgs; [
|
||||
rustToolchain
|
||||
clang
|
||||
llvmPackages_latest.bintools
|
||||
udev
|
||||
alsa-lib
|
||||
vulkan-loader
|
||||
xorg.libX11
|
||||
xorg.libXcursor
|
||||
xorg.libXi
|
||||
xorg.libXrandr
|
||||
libxkbcommon
|
||||
wayland
|
||||
glibc.dev
|
||||
glib.dev
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin
|
||||
export LD_LIBRARY_PATH=${
|
||||
pkgs.lib.makeLibraryPath [
|
||||
pkgs.vulkan-loader
|
||||
pkgs.libxkbcommon
|
||||
pkgs.wayland
|
||||
pkgs.alsa-lib
|
||||
pkgs.udev
|
||||
]
|
||||
}:$LD_LIBRARY_PATH
|
||||
export LIBCLANG_PATH="${pkgs.llvmPackages_latest.libclang.lib}/lib"
|
||||
export BINDGEN_EXTRA_CLANG_ARGS="-I${pkgs.glibc.dev}/include -I${pkgs.llvmPackages_latest.libclang.lib}/lib/clang/${pkgs.llvmPackages_latest.libclang.version}/include -I${pkgs.glib.dev}/include/glib-2.0 -I${pkgs.glib.out}/lib/glib-2.0/include/"
|
||||
export RUSTFLAGS="-C link-arg=-fuse-ld=lld"
|
||||
echo "Bevy development environment loaded!"
|
||||
'';
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
8
lib-utils/Cargo.toml
Normal file
8
lib-utils/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "pong-utils"
|
||||
version = { workspace = true }
|
||||
edition = { workspace = true }
|
||||
|
||||
[dependencies]
|
||||
bevy = { workspace = true }
|
||||
log = { workspace = true }
|
13
lib-utils/src/lib.rs
Normal file
13
lib-utils/src/lib.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
pub fn print_hello_world() {
|
||||
println!("Hello from utils crate!");
|
||||
}
|
||||
|
||||
pub struct UtilsPlugin;
|
||||
|
||||
impl Plugin for UtilsPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, print_hello_world);
|
||||
}
|
||||
}
|
3
rust-toolchain.toml
Normal file
3
rust-toolchain.toml
Normal file
@@ -0,0 +1,3 @@
|
||||
[toolchain]
|
||||
channel = "nightly"
|
||||
components = ["rustfmt", "clippy"]
|
Reference in New Issue
Block a user