Skip to content

Commit af971bf

Browse files
authored
Devtools overhaul (#60)
Gives some much needed love to devtools: - Adds git hooks - Improves justfile tooling - Adds additional CI checks
1 parent be7b189 commit af971bf

13 files changed

Lines changed: 201 additions & 28 deletions

File tree

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22
watch_file \
3+
justfile \
34
rust-toolchain.toml \
45
*.nix
56
use flake

.githooks/pre-push

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env sh
2+
set -eu
3+
4+
required_rust_version="1.92.0"
5+
6+
if ! command -v rustc >/dev/null 2>&1; then
7+
echo "🚫 pre-push: rustc is not installed or not on PATH"
8+
exit 1
9+
fi
10+
11+
current_rust_version=$(rustc --version | awk '{print $2}')
12+
13+
version_ge() {
14+
awk -v v1="$1" -v v2="$2" '
15+
BEGIN {
16+
n1 = split(v1, a, ".")
17+
n2 = split(v2, b, ".")
18+
max = (n1 > n2 ? n1 : n2)
19+
20+
for (i = 1; i <= max; i++) {
21+
x = (i <= n1 ? a[i] : 0) + 0
22+
y = (i <= n2 ? b[i] : 0) + 0
23+
24+
if (x > y) exit 0
25+
if (x < y) exit 1
26+
}
27+
28+
exit 0
29+
}
30+
'
31+
}
32+
33+
if ! version_ge "$current_rust_version" "$required_rust_version"; then
34+
echo "🚫 pre-push: rustc $current_rust_version found, but $required_rust_version or newer is required"
35+
exit 1
36+
fi
37+
38+
echo "🔎 pre-push: running checks that mirror GitHub CI"
39+
echo "• cargo test"
40+
cargo test
41+
42+
echo "• cargo clippy -- -D warnings"
43+
cargo clippy -- -D warnings
44+
45+
echo "• cargo fmt --all -- --check"
46+
cargo fmt --all -- --check
47+
48+
echo "✅ pre-push: all checks passed"

.github/workflows/ci.yaml

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ jobs:
2828
~/.cargo/git/db/
2929
target/
3030
key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.toml') }}
31-
- name: Install stable toolchain
32-
uses: dtolnay/rust-toolchain@stable
31+
- name: Install Rust
32+
uses: dtolnay/rust-toolchain@1.92.0
3333
- name: Install Dependencies
3434
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev
3535
- name: Run cargo test
@@ -53,15 +53,40 @@ jobs:
5353
~/.cargo/git/db/
5454
target/
5555
key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.toml') }}
56-
- name: Install stable toolchain
57-
uses: dtolnay/rust-toolchain@stable
56+
- name: Install Rust
57+
uses: dtolnay/rust-toolchain@1.92.0
5858
with:
5959
components: clippy
6060
- name: Install Dependencies
6161
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev
6262
- name: Run clippy
6363
run: cargo clippy -- -D warnings
6464

65+
# Run cargo doc with rustdoc warnings denied
66+
docs:
67+
name: Docs
68+
runs-on: ubuntu-latest
69+
timeout-minutes: 30
70+
steps:
71+
- name: Checkout sources
72+
uses: actions/checkout@v4
73+
- name: Cache
74+
uses: actions/cache@v4
75+
with:
76+
path: |
77+
~/.cargo/bin/
78+
~/.cargo/registry/index/
79+
~/.cargo/registry/cache/
80+
~/.cargo/git/db/
81+
target/
82+
key: ${{ runner.os }}-cargo-doc-${{ hashFiles('**/Cargo.toml') }}
83+
- name: Install Rust
84+
uses: dtolnay/rust-toolchain@1.92.0
85+
- name: Install Dependencies
86+
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev
87+
- name: Run cargo doc
88+
run: RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --workspace --all-features --exclude guest_wit_example --exclude host_wit_example --exclude simple
89+
6590
# Run cargo fmt --all -- --check
6691
format:
6792
name: Format
@@ -70,8 +95,8 @@ jobs:
7095
steps:
7196
- name: Checkout sources
7297
uses: actions/checkout@v4
73-
- name: Install stable toolchain
74-
uses: dtolnay/rust-toolchain@stable
98+
- name: Install Rust
99+
uses: dtolnay/rust-toolchain@1.92.0
75100
with:
76101
components: rustfmt
77102
- name: Run cargo fmt

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
[![Downloads](https://img.shields.io/crates/d/wasvy.svg)](https://crates.io/crates/wasvy)
1111
[![Docs](https://docs.rs/wasvy/badge.svg)](https://docs.rs/wasvy)
1212
[![Rust Version](https://img.shields.io/badge/rust-1.92.0+-blue.svg)](https://www.rust-lang.org)
13-
[![CI](https://github.com/wasvy-org/wasvy/workflows/CI/badge.svg)](https://github.com/wasvy-org/wasvy/actions)
13+
[![CI](https://github.com/wasvy-org/wasvy/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/wasvy-org/wasvy/actions)
1414
[![Discord](https://img.shields.io/discord/691052431525675048.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.com/channels/691052431525675048/1492230910383357992/1492230910383357992)
1515

1616
> 🪺 **Just hatched**: This project in in the process of stabilization. Some features are still missing and breaking API changes are likely to happen as we approach a 1.0 release. Use at your own risk!
1717
18-
> 🎯 **Community Feedback**: Your ideas, suggestions, and contributions are highly valued! Come and talk with us in the [Bevy Discord](https://discord.com/channels/691052431525675048/1034543904478998539). Report bugs and discuss new features on [Github](https://github.com/wasvy-org/wasvy/issues). Together, we can shape this into something great!
18+
> 🎯 **Community Feedback**: Your ideas, suggestions, and contributions are highly valued! Come and talk with us in the [Bevy Discord](https://discord.com/channels/691052431525675048/1492230910383357992/1492230910383357992). Report bugs and discuss new features on [Github](https://github.com/wasvy-org/wasvy/issues). Together, we can shape this into something great!
1919
20-
> 💡 **TIP**: Check out the [`justfile`](justfile) for useful commands and as a reference for common operations in the project.
20+
> 💡 **TIP**: Check out the [`justfile`](./justfile) for useful commands and as a reference for common operations in the project.
2121
2222
## Overview
2323

@@ -232,6 +232,30 @@ Check out the examples directory for more detailed usage:
232232

233233
Contributions come in many forms, and we welcome all kinds of help! Here's how you can contribute:
234234

235+
### Setup your development environment
236+
237+
Using the project's [Nix flake](https://nixos.org/download/) is the simplest way to get a working development environment.
238+
239+
1. Install [Nix](https://nixos.org/download/).
240+
2. Install [direnv](https://direnv.net/) and hook it into your shell by following the [official setup instructions](https://direnv.net/docs/hook.html).
241+
3. From the repository root, allow direnv to load the flake-based development shell:
242+
243+
```sh
244+
direnv allow
245+
```
246+
247+
Once allowed, direnv will automatically enter the development shell for this repository and provision the required tooling.
248+
249+
### Other environments
250+
251+
If you are not using Nix, install the required tooling manually:
252+
253+
- Install [Rust 1.92.0+](https://www.rust-lang.org/tools/install)
254+
- Install [`just`](https://github.com/casey/just)
255+
- Run `just enable-git-hooks`
256+
257+
For additional project commands, see the [`justfile`](./justfile).
258+
235259
### Code Contributions
236260

237261
1. Fork the repository

crates/wasvy_cli/src/runtime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717

1818
/// The config for a [Runtime]
1919
///
20-
/// Create a new runtime by calling [Runtime::build]
20+
/// Create a new runtime by calling [Runtime::new]
2121
pub struct Config {
2222
/// A namespace, usually the name of the game/software being modded
2323
pub namespace: String,

flake.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
wkg
4545
nixd
4646
nil
47+
ripgrep
4748

4849
poetry
4950
python3
@@ -80,6 +81,8 @@
8081
shellHook = ''
8182
${wkgConfigHook}
8283
84+
just enable-git-hooks
85+
8386
# Impure python setup for now
8487
unset PYTHONPATH
8588
uv sync --directory examples/python_example

justfile

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,107 @@
1+
# TIP: run the command `just -l` to get an overview
2+
3+
# Build an example rust crate to Wasm and copy it into host assets.
4+
[group("examples")]
5+
[arg("example", pattern="^(simple|guest_wit_example)$")]
16
build-example example:
27
cargo build --release --target wasm32-wasip2 -p {{example}}
38
mkdir -p ./examples/host_example/assets/mods
49
cp ./target/wasm32-wasip2/release/{{example}}.wasm ./examples/host_example/assets/mods
510

11+
# Run the host example app.
12+
[group("examples")]
613
run-host-example:
714
cargo run -p host_example --features bevy/file_watcher
815

9-
# Requires `poetry` to run
16+
# Run the host wit example app.
17+
[group("examples")]
18+
run-host-wit-example:
19+
cargo run -p host_example --features bevy/file_watcher
20+
21+
# Build the Python example mod.
22+
[group("examples")]
23+
[working-directory("examples/python_example/src")]
1024
build-example-python:
11-
cd examples/python_example/src && poetry run componentize-py --wit-path ../wit/ --world example componentize app -o ../../host_example/assets/mods/python.wasm
25+
poetry run componentize-py --wit-path ../wit/ --world example componentize app -o ../../host_example/assets/mods/python.wasm
1226

13-
# Create the bindings for the python example
27+
# Generate Python bindings for example mod.
28+
[group("examples")]
29+
[working-directory("examples/python_example")]
1430
example-bindings-python:
15-
cd examples/python_example && rm -rf ./src/componentize_py_async_support && rm -rf ./src/wit_world && rm -rf ./src/componentize_py_runtime.pyi && rm -rf ./src/componentize_py_types.py && rm -rf ./src/poll_loop.py && poetry run componentize-py --wit-path wit/ --world example bindings src
31+
rm -rf ./src/componentize_py_async_support
32+
rm -rf ./src/wit_world
33+
rm -f ./src/componentize_py_runtime.pyi
34+
rm -f ./src/componentize_py_types.py
35+
rm -f ./src/poll_loop.py
36+
poetry run componentize-py --wit-path wit/ --world example bindings src
1637

38+
# Build the Go example mod.
39+
[group("examples")]
40+
[working-directory("examples/go_example/src")]
41+
[env("GOARCH", "wasm")]
42+
[env("GOOS", "wasip1")]
1743
build-example-go:
18-
cd examples/go_example/src && GOARCH="wasm" GOOS="wasip1" go build -o core.wasm -buildmode=c-shared -ldflags=-checklinkname=0 && wasm-tools component embed -w example ../wit/ core.wasm -o core-with-wit.wasm && wasm-tools component new --adapt ../wasi_snapshot_preview1.reactor.wasm core-with-wit.wasm -o go.wasm
44+
go build -o core.wasm -buildmode=c-shared -ldflags=-checklinkname=0
45+
wasm-tools component embed -w example ../wit/ core.wasm -o core-with-wit.wasm
46+
wasm-tools component new --adapt ../wasi_snapshot_preview1.reactor.wasm core-with-wit.wasm -o go.wasm
1947

48+
# Generate Go bindings for example mod.
49+
[group("examples")]
50+
[working-directory("examples/go_example/src")]
2051
example-bindings-go:
21-
cd examples/go_example/src && wit-bindgen go -w example ../wit/
52+
wit-bindgen go -w example ../wit/
2253

23-
# For the fetching to take effect you must delete the deps folder manually
54+
# Fetch WIT dependencies for one example (deprecated, use cli instead).
55+
[group("examples")]
2456
example-fetch-deps example:
2557
cd examples/{{example}} && wkg wit fetch
2658

27-
build-host:
28-
cargo build -p wasvy
59+
# Enable repository git hooks.
60+
[group("setup")]
61+
enable-git-hooks:
62+
git config core.hooksPath .githooks
63+
chmod +x .githooks/pre-push
2964

65+
# Build the ECS WIT package.
66+
[group("chores")]
3067
build-wasvy-ecs:
3168
wkg wit build --wit-dir ./wit/ecs/
3269

70+
# Publish the ECS package to wa.dev.
71+
[group("chores")]
3372
publish-wasvy-ecs file_path version:
3473
wkg publish --package wasvy:ecs@{{version}} {{file_path}} --registry wa.dev
74+
75+
# Replace the existing (1.92.0) rust toolchain version with a new one.
76+
[group("chores")]
77+
[arg("new", pattern="^\\d+\\.\\d+\\.\\d+$")]
78+
bump-toolchain new:
79+
rg -l 'rust' . | xargs sed -i "/rust/s/1.92.0/{{new}}/g"
80+
81+
# Replace the existing (0.18.0) bevy version with a new one.
82+
[group("chores")]
83+
[arg("new", pattern="^\\d+\\.\\d+\\.\\d+$")]
84+
bump-bevy new:
85+
rg -l -g '!Cargo.lock' 'bevy' . | xargs sed -i "/bevy/s/0.18.0/{{new}}/g"
86+
cargo check
87+
88+
# Replace the existing (0.0.8) wasvy version with a new one.
89+
[group("chores")]
90+
[arg("new", pattern="^\\d+\\.\\d+\\.\\d+$")]
91+
bump-version new:
92+
rg -l -g '!Cargo.lock' 'version' . | xargs sed -i "/version/s/0.0.8/{{new}}/g"
93+
cargo check
94+
95+
# Publishes all crates
96+
[group("chores")]
97+
[confirm]
98+
publish:
99+
# CI
100+
cargo test
101+
cargo clippy -- -D warnings
102+
cargo fmt --all -- --check
103+
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --workspace --all-features --exclude guest_wit_example --exclude host_wit_example --exclude simple
104+
105+
# Publish
106+
cargo publish -p wasvy_macros
107+
cargo publish -p wasvy

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[toolchain]
2-
channel = "1.92.0" # Track same version as Bevy
2+
channel = "1.92.0" # Track same rust version as Bevy
33
components = [
44
"cargo",
55
"llvm-tools",

src/authoring.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! **no methods**. This is important for components that are queried or
66
//! serialized but never invoked.
77
//! - [`WasvyMethods`] registers exported methods (typically via
8-
//! [`#[wasvy::methods]`](crate::methods)).
8+
//! [`#[wasvy::methods]`](macro@crate::methods)).
99
//! - [`WasvyAutoRegistrationPlugin`] apply all submitted
1010
//! registrations to a Bevy `App`.
1111
//!

src/component.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub type TypePath = String;
2323

2424
/// Registry for storing the components that are registered from WASM assets.
2525
///
26-
/// Note that this is unique per world, not per app like the [AppTypeRegistry](bevy_ecs::reflect::AppTypeRegistry)
26+
/// Note that this is unique per world, not per app like the [AppTypeRegistry]
2727
#[derive(Default, Clone, Debug, Resource, Deref, DerefMut)]
2828
pub struct WasmComponentRegistry(HashMap<TypePath, ComponentId>);
2929

0 commit comments

Comments
 (0)