Skip to content

Commit

Permalink
build torii-client to wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Sep 20, 2023
1 parent 0bfc367 commit 67648de
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions crates/torii/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,25 @@ dojo-types = { path = "../../dojo-types" }
futures-util = "0.3.28"
futures.workspace = true
parking_lot.workspace = true
prost.workspace = true
serde.workspace = true
serde_json.workspace = true
starknet-crypto.workspace = true
starknet.workspace = true
thiserror.workspace = true
tonic.workspace = true
tokio = { version = "1.32.0", default-features = false, features = [ "rt" ] }
torii-grpc = { path = "../grpc", features = [ "client" ] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1.16", features = [ "time" ], default-features = false }
prost.workspace = true
tokio.workspace = true
tonic.workspace = true

[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = "0.3.64"
wasm-bindgen = "0.2.87"
wasm-bindgen-futures = "0.4.37"
wasm-prost.workspace = true
wasm-tonic.workspace = true
web-sys = { version = "0.3.4", features = [ 'Window', 'WorkerGlobalScope' ] }

[dev-dependencies]
Expand Down
5 changes: 5 additions & 0 deletions crates/torii/client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#[cfg(target_arch = "wasm32")]
extern crate wasm_prost as prost;
#[cfg(target_arch = "wasm32")]
extern crate wasm_tonic as tonic;

pub mod client;
pub mod contract;
pub mod provider;
Expand Down
3 changes: 2 additions & 1 deletion crates/torii/grpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ impl WorldClient {
})
}

// we make this function async so that we can keep the function signature similar
#[must_use]
#[cfg(target_arch = "wasm32")]
pub fn new(endpoint: String, world_address: FieldElement) -> Result<Self, Error> {
pub async fn new(endpoint: String, world_address: FieldElement) -> Result<Self, Error> {
Ok(Self {
world_address,
inner: world_client::WorldClient::new(tonic_web_wasm_client::Client::new(endpoint)),
Expand Down

0 comments on commit 67648de

Please sign in to comment.