substrate-api-client icon indicating copy to clipboard operation
substrate-api-client copied to clipboard

Support more functionality for wasm targets

Open Niederb opened this issue 1 year ago • 4 comments

We would like to provide more functionality for webassembly targets. See the findings in #272. Ideally we could build the complete client unchanged: cargo b --target wasm32-wasi or cargo b --target wasm32-unknown-unknown

Niederb avatar Apr 04 '23 11:04 Niederb

@Niederb @haerdib hello you two - we are also interested into web assembly support and would like to ask - if there is a documentation related to what is possible for WASM target and what are the limitations regarding to substrate-api-client?

dotChris90 avatar Apr 24 '24 07:04 dotChris90

@dotChris90 Good question. In general we support in WebAssembly what is available in a no_std environment. The "no_std build" from the README documents a bit what is available. The WebAssembly eco-system is still in constant flux. I can have a look if one of our roadblocks has been removed.

Niederb avatar Apr 25 '24 06:04 Niederb

I just did a test with the latest nightly and doing a cargo update. The command cargo build --target wasm32-wasip1 gives me:

error: Only features sync,macros,io-util,rt,time are supported on wasm.
   --> /home/tniederberger/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/lib.rs:470:1
    |
470 | compile_error!("Only features sync,macros,io-util,rt,time are supported on wasm.");
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0433]: failed to resolve: use of undeclared crate or module `platform`
  --> /home/tniederberger/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustls-native-certs-0.7.0/src/lib.rs:58:42
   |
58 |     load_certs_from_env().unwrap_or_else(platform::load_native_certs)
   |                                          ^^^^^^^^ use of undeclared crate or module `platform`

For more information about this error, try `rustc --explain E0433`.
error: could not compile `rustls-native-certs` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `tokio` (lib) due to 1 previous error

Niederb avatar Apr 25 '24 08:04 Niederb

There is indeed some good news. By updating our dependencies it is now possible to compile with the following command: cargo build --target wasm32-wasi --no-default-features --features sync-api,staking-xt,contracts-xt,std I will create a PR regarding that in the next couple of days.

Niederb avatar Apr 25 '24 09:04 Niederb