Skip to content

Commit

Permalink
feat: put wasm-bindgen-futures dep behind the wasm-bindgen feature …
Browse files Browse the repository at this point in the history
…flag (alloy-rs#795)

* feat: put wasm-bindgen-futures dep behind the `wasm-bindgen` feature flag

* chore: move to [features], update CI

---------

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
  • Loading branch information
2 people authored and ben186 committed Jul 27, 2024
1 parent 562b539 commit 51a6d32
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 29 deletions.
43 changes: 18 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,21 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest"]
rust: [
"stable",
"nightly",
"1.76" # MSRV
]
flags: [
rust:
- "stable"
- "nightly"
- "1.76" # MSRV
flags:
# No features
"--no-default-features",
- "--no-default-features"
# Default features
"",
]
include:
# All features
- os: "ubuntu-latest"
rust: "stable"
flags: "--all-features"
- os: "ubuntu-latest"
rust: "nightly"
- ""
exclude:
# All features on MSRV
- rust: "1.76" # MSRV
flags: "--all-features"
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
Expand Down Expand Up @@ -83,7 +77,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
target: wasm32-unknown-unknown
Expand All @@ -95,7 +89,6 @@ jobs:
run: |
cargo hack build --workspace --target wasm32-unknown-unknown \
--exclude alloy-contract \
--exclude alloy-internal-test-utils \
--exclude alloy-network \
--exclude alloy-node-bindings \
--exclude alloy-provider \
Expand All @@ -111,7 +104,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
target: wasm32-wasi
Expand All @@ -134,7 +127,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
target: riscv32imac-unknown-none-elf
Expand All @@ -149,7 +142,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@cargo-hack
- uses: Swatinem/rust-cache@v2
Expand Down Expand Up @@ -178,7 +171,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: Swatinem/rust-cache@v2
with:
Expand All @@ -201,7 +194,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
Expand All @@ -211,7 +204,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: cargo deny check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: EmbarkStudios/cargo-deny-action@v1
with:
command: check all
1 change: 1 addition & 0 deletions crates/alloy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ hyper = [
"alloy-provider?/hyper",
"alloy-transport-http?/hyper",
]
wasm-bindgen = ["alloy-transport?/wasm-bindgen"]

# ---------------------------------------- Main re-exports --------------------------------------- #

Expand Down
7 changes: 5 additions & 2 deletions crates/consensus/src/receipt/receipts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::receipt::{Eip658Value, TxReceipt};
use alloy_primitives::{Bloom, Log, U128};
use alloy_primitives::{Bloom, Log};
use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable};
use core::borrow::Borrow;

Expand Down Expand Up @@ -43,7 +43,10 @@ where
let key = if self.status.is_eip658() { "status" } else { "root" };
s.serialize_field(key, &self.status)?;

s.serialize_field("cumulativeGasUsed", &U128::from(self.cumulative_gas_used))?;
s.serialize_field(
"cumulativeGasUsed",
&alloy_primitives::U128::from(self.cumulative_gas_used),
)?;
s.serialize_field("logs", &self.logs)?;

s.end()
Expand Down
5 changes: 4 additions & 1 deletion crates/transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ tower.workspace = true
url.workspace = true

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen-futures = "0.4"
wasm-bindgen-futures = { version = "0.4", optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { workspace = true, features = ["rt"] }

[features]
wasm-bindgen = ["dep:wasm-bindgen-futures"]
4 changes: 4 additions & 0 deletions crates/transport/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ where
T: Future<Output = ()> + 'static,
{
fn spawn_task(self) {
#[cfg(not(feature = "wasm-bindgen"))]
panic!("The 'wasm-bindgen' feature must be enabled");

#[cfg(feature = "wasm-bindgen")]
wasm_bindgen_futures::spawn_local(self);
}
}

0 comments on commit 51a6d32

Please sign in to comment.