diff --git a/Cargo.lock b/Cargo.lock index d92e45e0ff..588f46425a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4255,6 +4255,7 @@ version = "0.31.0" dependencies = [ "bitvec", "frame-metadata 16.0.0", + "getrandom 0.2.10", "heck", "hex", "jsonrpsee", diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index a336f7fa7c..a48b3d546d 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -15,6 +15,7 @@ description = "Generate an API for interacting with a substrate node from FRAME [features] default = ["fetch-metadata"] fetch-metadata = ["dep:jsonrpsee", "dep:tokio", "dep:frame-metadata"] +web = ["jsonrpsee?/async-wasm-client", "jsonrpsee?/client-web-transport", "getrandom/js"] [dependencies] codec = { package = "parity-scale-codec", workspace = true, features = ["derive"] } @@ -30,6 +31,9 @@ hex = { workspace = true } tokio = { workspace = true, features = ["rt-multi-thread"], optional = true } thiserror = { workspace = true } +# Included if "web" feature is enabled, to enable its js feature. +getrandom = { workspace = true, optional = true } + [dev-dependencies] bitvec = { workspace = true } scale-info = { workspace = true, features = ["bit-vec"] } diff --git a/codegen/src/lib.rs b/codegen/src/lib.rs index 5af5a244b9..8171c2ee49 100644 --- a/codegen/src/lib.rs +++ b/codegen/src/lib.rs @@ -53,8 +53,8 @@ mod types; #[cfg(feature = "fetch-metadata")] pub mod utils; -#[cfg(all(feature = "web", feature = "fetch-metadata"))] -compile_error!("subxt-codegen: the features 'web' and 'fetch_metadata' cannot be used together."); +#[cfg(feature = "web")] +use getrandom as _; pub use self::{ api::{GenerateRuntimeApi, RuntimeGenerator}, diff --git a/macro/Cargo.toml b/macro/Cargo.toml index eeafea2872..2845e0f3c0 100644 --- a/macro/Cargo.toml +++ b/macro/Cargo.toml @@ -13,6 +13,9 @@ documentation.workspace = true homepage.workspace = true description = "Generate types and helpers for interacting with Substrate runtimes." +[features] +web = ["subxt-codegen/web"] + [lib] proc-macro = true diff --git a/subxt/Cargo.toml b/subxt/Cargo.toml index ac64287cc5..35fd8e634c 100644 --- a/subxt/Cargo.toml +++ b/subxt/Cargo.toml @@ -29,7 +29,7 @@ native = [ # Enable this for web/wasm builds. # Exactly 1 of "web" and "native" is expected. -web = ["jsonrpsee?/async-wasm-client", "jsonrpsee?/client-web-transport", "getrandom/js", "subxt-lightclient?/web"] +web = ["jsonrpsee?/async-wasm-client", "jsonrpsee?/client-web-transport", "getrandom/js", "subxt-lightclient?/web", "subxt-macro/web"] # Enable this to use jsonrpsee (allowing for example `OnlineClient::from_url`). jsonrpsee = ["dep:jsonrpsee"]