Web Game/Engine written in Rust
Application is available online at https://hatsu.tech (probably only on chrome at the moment though, requires webgpu support)
Currently build for web using:
https://www.rust-lang.org/tools/install
rustup update
For local development, we want to use bacon with clippy instead of building every time. Clippy does not easily allow
building of wasm though...
Notes for host deployment: Make sure firewall allows access on 80/443 for http/https sudo ufw allow 80 sudo ufw allow 443
sudo ufw allow http sudo ufw allow https
Useful rust tools to improve project:
cargo build --timings
produces a report showing crate compile timescargo update
to update latest compatible semantic versioncargo fmt
to format the projectcargo tree
to see dependency graph.cargo tree --duplicate
can be used to find dependencies with multiple versions.cargo features prune
to show only the features used by our project. Other features can be disabledcargo audit
to scan CVEscargo +nightly udeps --all-targets
to find unused/duplicate dependenciescargo clippy
for linting tips, small code improvementscargo outdated
orcargo outdated --depth 1
to find new versions of dependencies. Alternatively, cargo-machete can be used.cargo update --verbose
can also be used to find older dependenciescargo bloat --release -n 100
optionally with--crates
to figure out functions and dependencies that contribute most to binary size Other things to consider:- Switching to other linker may be faster (mold is optimized for linux, lld is an option)
cargo +nightly rustc --bin kloenk_bin -- -Z time-passes
to figure out time taken for linker
- Switching to Cranelift for local development, less optimized but produces working executable binaries
- Switching to nightly compiler:
rustup target add wasm32-unknown-unknown --toolchain nightly
- or
rustup toolchain install nightly --allow-downgrade
?
cargo +nightly build -Z build-std=std,panic_abort --target wasm32-unknown-unknown --release --target-dir target --frozen --bin kloenk_bin
- Look at Bevy's optimizations:
Setting up the server:
- To enter the server:
ssh root@$ip_adress
- Initialize using
initialize_server.sh
Now we can deploy
- Checking docker containers:
docker ps -a
- Logs:
docker logs $container_name
- Enter container:
docker exec -it $container_name /bin/sh
Local development(linux+standalone client): cargo watch -x 'run' cargo +nightly run -Z build-std=std,panic_abort --target-dir target --bin kloenk_bin --target x86_64-unknown-linux-gnu
Local development(windows+standalone client): cargo run --target x86_64-pc-windows-msvc (cargo watch -x 'run --target x86_64-pc-windows-msvc') (cargo +nightly watch --delay 60 -x 'run --target x86_64-pc-windows-msvc')
Local development(windows+web):
Once:
Run nginx
cp -Force .\resources\web\nginx.conf C:\Users\Jelmer\Downloads\nginx-1.27.2\nginx-1.27.2\conf
cp -Force .\resources\web\common_headers.conf C:\Users\Jelmer\Downloads\nginx-1.27.2\nginx-1.27.2\conf
cp -r -Force .\resources\ C:\Users\Jelmer\Downloads\nginx-1.27.2\nginx-1.27.2\html
cp .\index.html C:\Users\Jelmer\Downloads\nginx-1.27.2\nginx-1.27.2\html
Every change:
cargo build --target wasm32-unknown-unknown --target-dir target --frozen --bin kloenk_bin
wasm-bindgen target/wasm32-unknown-unknown/debug/kloenk_bin.wasm --target web --out-dir bg_output --out-name kloenk
mv -Force .\bg_output\kloenk_bg.wasm .\bg_output\kloenk.wasm
cp ./bg_output/kloenk.wasm C:\Users\Jelmer\Downloads\nginx-1.27.2\nginx-1.27.2\html
cp ./bg_output/kloenk.js C:\Users\Jelmer\Downloads\nginx-1.27.2\nginx-1.27.2\html\
Local development(linux+web): sudo systemctl start nginx cp ./web/nginx/nginx.conf /etc/nginx/nginx.conf cp ./web/nginx/common_headers.conf /etc/nginx/common_headers.conf sudo cp -r ./resources /usr/share/nginx/html sudo cp ./index.html /usr/share/nginx/html
Every change:
cargo build --target wasm32-unknown-unknown --target-dir target --bin kloenk_bin
wasm-bindgen target/wasm32-unknown-unknown/debug/kloenk_bin.wasm --target web --out-dir bg_output --out-name kloenk
mv ./bg_output/kloenk_bg.wasm ./bg_output/kloenk.wasm
sudo cp bg_output/kloenk.wasm /usr/share/nginx/html
sudo cp bg_output/kloenk.js /usr/share/nginx/html
Build for product owner (on windows):
cargo build --target x86_64-pc-windows-msvc --release
Compress-Archive -Path .\target\x86_64-pc-windows-msvc\release\assets\,.\target\x86_64-pc-windows-msvc\release\kloenk.exe -DestinationPath .\kloenk.zip