From f4946081490e5d43990e563f0d56ada5eb8c24b2 Mon Sep 17 00:00:00 2001 From: Tony Stark Date: Tue, 15 Jul 2025 19:24:59 -0500 Subject: [PATCH 01/10] Create ci.yaml --- .github/workflows/ci.yaml | 67 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..6f4882b --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,67 @@ +name: CI + +on: + merge_group: + pull_request: + push: + branches: + - main + +env: + CARGO_TERM_COLOR: always + +jobs: + typos: + name: Check Typos + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Run Typos + uses: crate-ci/typos@v1.34.0 + + format: + name: Check Formatting + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Install Rust toolchain with rustfmt + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + - name: Run cargo fmt --check + run: cargo fmt --all -- --check + + build_and_test: # Combined Lint, Clippy, and Test + name: Build, Lint, and Test + runs-on: ubuntu-latest + timeout-minutes: 45 # Increased timeout due to more steps + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install System Dependencies + run: | + sudo apt-get update + sudo apt-get install --no-install-recommends libasound2-dev libudev-dev + + - name: Install Rust toolchain with clippy + uses: dtolnay/rust-toolchain@stable + with: + components: clippy + + - name: Cache Cargo + uses: Swatinem/rust-cache@v2 + with: + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }} # Unified cache key + + - name: Run Clippy (Linting) + run: cargo clippy --tests --examples -- -D warnings + + - name: Run Rustdoc (Documentation Check) + run: cargo rustdoc -- -D warnings + + - name: Run Cargo Tests + run: cargo test From 8e863b988466d1e257a30f2c4c77e659dfb13083 Mon Sep 17 00:00:00 2001 From: Tony Stark Date: Tue, 15 Jul 2025 19:31:36 -0500 Subject: [PATCH 02/10] ci issue fix --- .github/workflows/ci.yaml | 2 +- examples/intro.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6f4882b..125c6e6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -45,7 +45,7 @@ jobs: - name: Install System Dependencies run: | sudo apt-get update - sudo apt-get install --no-install-recommends libasound2-dev libudev-dev + sudo apt-get install --no-install-recommends libasound2-dev libudev-dev protobuf-compiler - name: Install Rust toolchain with clippy uses: dtolnay/rust-toolchain@stable diff --git a/examples/intro.rs b/examples/intro.rs index 1c8a363..fdde2d9 100644 --- a/examples/intro.rs +++ b/examples/intro.rs @@ -202,7 +202,7 @@ fn on_dojo_events( for ev in ev_retrieve_entities.read() { info!(entity_id = ?ev.entity_id, "Torii update"); - // Felt::ZERO is being emitted once, when the subcription is initialized. + // Felt::ZERO is being emitted once, when the subscription is initialized. // We don't want to spawn a cube for this. if ev.entity_id == Felt::ZERO { continue; From 33d9d54ce18058e70a13706f1372f71f9276e057 Mon Sep 17 00:00:00 2001 From: Tony Stark Date: Tue, 15 Jul 2025 19:38:36 -0500 Subject: [PATCH 03/10] Update ci.yaml --- .github/workflows/ci.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 125c6e6..c57e515 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -34,10 +34,10 @@ jobs: - name: Run cargo fmt --check run: cargo fmt --all -- --check - build_and_test: # Combined Lint, Clippy, and Test + build_and_test: name: Build, Lint, and Test runs-on: ubuntu-latest - timeout-minutes: 45 # Increased timeout due to more steps + timeout-minutes: 45 steps: - name: Checkout sources uses: actions/checkout@v4 @@ -45,7 +45,7 @@ jobs: - name: Install System Dependencies run: | sudo apt-get update - sudo apt-get install --no-install-recommends libasound2-dev libudev-dev protobuf-compiler + sudo apt-get install --no-install-recommends libasound2-dev libudev-dev protobuf-compiler libprotobuf-dev - name: Install Rust toolchain with clippy uses: dtolnay/rust-toolchain@stable From 6e0a593d716d9258a1c604cab6233b917967ce84 Mon Sep 17 00:00:00 2001 From: Tony Stark Date: Tue, 15 Jul 2025 20:09:17 -0500 Subject: [PATCH 04/10] Add type aliases for subscription channels --- src/plugin.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/plugin.rs b/src/plugin.rs index e03ea50..03cbc79 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -77,6 +77,11 @@ pub struct StarknetConnection { >, } +type SubscriptionMessage = (Felt, Vec); + +type SubscriptionSender = Option>>>; +type SubscriptionReceiver = Option>>>; + /// Torii connection state. #[derive(Default)] pub struct ToriiConnection { @@ -85,8 +90,8 @@ pub struct ToriiConnection { pub pending_retrieve_entities: VecDeque>>, pub subscriptions: Arc>>>, - pub subscription_sender: Option)>>>>, - pub subscription_receiver: Option)>>>>, + pub subscription_sender: SubscriptionSender, + pub subscription_receiver: SubscriptionReceiver, } /// Dojo resource that embeds Starknet and Torii connection. From 8c2d2099f88d01251bd85f484a57b24e3ddf4757 Mon Sep 17 00:00:00 2001 From: Tony Stark Date: Tue, 15 Jul 2025 20:21:33 -0500 Subject: [PATCH 05/10] Remove redundant async blocks in task polling --- src/plugin.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugin.rs b/src/plugin.rs index 03cbc79..cb19e7b 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -233,7 +233,7 @@ fn check_torii_task( mut ev_initialized: EventWriter, ) { if let Some(task) = &mut dojo.torii.init_task { - if let Ok(Ok(client)) = tokio.runtime.block_on(async { task.await }) { + if let Ok(Ok(client)) = tokio.runtime.block_on(task) { info!("Torii client initialized."); dojo.torii.client = Some(Arc::new(Mutex::new(client))); dojo.torii.init_task = None; @@ -243,7 +243,7 @@ fn check_torii_task( if !dojo.torii.pending_retrieve_entities.is_empty() { if let Some(task) = dojo.torii.pending_retrieve_entities.pop_front() { - if let Ok(Ok(response)) = tokio.runtime.block_on(async { task.await }) { + if let Ok(Ok(response)) = tokio.runtime.block_on(task) { debug!("Retrieve entities response: {:?}", response); for e in response.entities { ev_retrieve_entities.write(DojoEntityUpdated { @@ -275,7 +275,7 @@ fn check_torii_task( /// that have been queued to be sent to the blockchain. fn check_sn_task(tokio: Res, mut dojo: ResMut) { if let Some(task) = &mut dojo.sn.connecting_task { - if let Ok(account) = tokio.runtime.block_on(async { task.await }) { + if let Ok(account) = tokio.runtime.block_on(task) { info!("Connected to Starknet."); dojo.sn.account = Some(account); dojo.sn.connecting_task = None; @@ -284,7 +284,7 @@ fn check_sn_task(tokio: Res, mut dojo: ResMut) { if !dojo.sn.pending_txs.is_empty() && dojo.sn.account.is_some() { if let Some(task) = dojo.sn.pending_txs.pop_front() { - match tokio.runtime.block_on(async { task.await }) { + match tokio.runtime.block_on(task) { Ok(tx_result) => match tx_result { Ok(result) => { info!("Transaction completed: {:#x}", result.transaction_hash); From 34897f781627a108a041ab8920a5f1217ca3051c Mon Sep 17 00:00:00 2001 From: Tony Stark Date: Tue, 15 Jul 2025 20:28:49 -0500 Subject: [PATCH 06/10] Update intro.rs --- examples/intro.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/intro.rs b/examples/intro.rs index fdde2d9..5fdae35 100644 --- a/examples/intro.rs +++ b/examples/intro.rs @@ -215,7 +215,7 @@ fn on_dojo_events( "di-Position" => { ev_position_updated.write(PositionUpdatedEvent(m.into())); } - name if name == "di-Moves".to_string() => {} + name if name == "di-Moves" => {} _ => { warn!("Model not handled: {:?}", m); } From 362899ac7cb92e31fefb56feaf9d6083454a7d56 Mon Sep 17 00:00:00 2001 From: Tony Stark Date: Tue, 15 Jul 2025 20:34:52 -0500 Subject: [PATCH 07/10] Simplify pattern matching for di-Moves event --- examples/intro.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/intro.rs b/examples/intro.rs index 5fdae35..fb748a8 100644 --- a/examples/intro.rs +++ b/examples/intro.rs @@ -215,7 +215,7 @@ fn on_dojo_events( "di-Position" => { ev_position_updated.write(PositionUpdatedEvent(m.into())); } - name if name == "di-Moves" => {} + "di-Moves" => {} _ => { warn!("Model not handled: {:?}", m); } From 4fe72fb869745d30d6ed29b254fcc7bbc769adac Mon Sep 17 00:00:00 2001 From: Tony Stark Date: Tue, 15 Jul 2025 20:53:34 -0500 Subject: [PATCH 08/10] Split lint and test jobs in CI workflow The combined build/lint/test job has been separated into two distinct jobs for better parallelization and clearer failure attribution. --- .github/workflows/ci.yaml | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c57e515..ca5cc5e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -34,19 +34,14 @@ jobs: - name: Run cargo fmt --check run: cargo fmt --all -- --check - build_and_test: - name: Build, Lint, and Test + lint: + name: Lint and Documentation Check runs-on: ubuntu-latest - timeout-minutes: 45 + timeout-minutes: 30 steps: - name: Checkout sources uses: actions/checkout@v4 - - name: Install System Dependencies - run: | - sudo apt-get update - sudo apt-get install --no-install-recommends libasound2-dev libudev-dev protobuf-compiler libprotobuf-dev - - name: Install Rust toolchain with clippy uses: dtolnay/rust-toolchain@stable with: @@ -55,7 +50,7 @@ jobs: - name: Cache Cargo uses: Swatinem/rust-cache@v2 with: - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }} # Unified cache key + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }} - name: Run Clippy (Linting) run: cargo clippy --tests --examples -- -D warnings @@ -63,5 +58,26 @@ jobs: - name: Run Rustdoc (Documentation Check) run: cargo rustdoc -- -D warnings + test: + name: Build and Test + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install System Dependencies + run: | + sudo apt-get update + sudo apt-get install --no-install-recommends libasound2-dev libudev-dev protobuf-compiler libprotobuf-dev + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + + - name: Cache Cargo + uses: Swatinem/rust-cache@v2 + with: + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }} + - name: Run Cargo Tests run: cargo test From f2c78f225a6cc7d63de486f8153f6c96c96762b3 Mon Sep 17 00:00:00 2001 From: Tony Stark Date: Tue, 15 Jul 2025 20:59:43 -0500 Subject: [PATCH 09/10] Update CI --- .github/workflows/ci.yaml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ca5cc5e..edc54a1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -35,7 +35,7 @@ jobs: run: cargo fmt --all -- --check lint: - name: Lint and Documentation Check + name: Lint runs-on: ubuntu-latest timeout-minutes: 30 steps: @@ -55,9 +55,6 @@ jobs: - name: Run Clippy (Linting) run: cargo clippy --tests --examples -- -D warnings - - name: Run Rustdoc (Documentation Check) - run: cargo rustdoc -- -D warnings - test: name: Build and Test runs-on: ubuntu-latest From b6933217fe0808ba5a559e254b00e3c4edad24b7 Mon Sep 17 00:00:00 2001 From: Tony Stark Date: Tue, 15 Jul 2025 21:13:10 -0500 Subject: [PATCH 10/10] Update ci.yaml --- .github/workflows/ci.yaml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index edc54a1..6472f1a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -42,6 +42,11 @@ jobs: - name: Checkout sources uses: actions/checkout@v4 + - name: Install System Dependencies + run: | + sudo apt-get update + sudo apt-get install --no-install-recommends libasound2-dev libudev-dev protobuf-compiler libprotobuf-dev + - name: Install Rust toolchain with clippy uses: dtolnay/rust-toolchain@stable with: @@ -50,11 +55,14 @@ jobs: - name: Cache Cargo uses: Swatinem/rust-cache@v2 with: - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }} + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }} # Unified cache key - name: Run Clippy (Linting) run: cargo clippy --tests --examples -- -D warnings + - name: Run Rustdoc (Documentation Check) + run: cargo rustdoc -- -D warnings + test: name: Build and Test runs-on: ubuntu-latest