Skip to content

Can't compile to wasm #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DylanVerstraete opened this issue Jul 13, 2021 · 13 comments
Closed

Can't compile to wasm #136

DylanVerstraete opened this issue Jul 13, 2021 · 13 comments

Comments

@DylanVerstraete
Copy link

  Compiling proc-macro-hack v0.5.19
   Compiling futures-core v0.3.15
   Compiling tinyvec v1.2.0
error: the wasm32-unknown-unknown target is not supported by default, you may need to enable the "js" feature. For more information see: https://docs.rs/getrandom/#webassembly-support
   --> /home/dylan/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.2.3/src/lib.rs:219:9
    |
219 | /         compile_error!("the wasm32-unknown-unknown target is not supported by \
220 | |                         default, you may need to enable the \"js\" feature. \
221 | |                         For more information see: \
222 | |                         https://docs.rs/getrandom/#webassembly-support");
    | |_________________________________________________________________________^

error[E0433]: failed to resolve: use of undeclared crate or module `imp`
   --> /home/dylan/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.2.3/src/lib.rs:246:5
    |
246 |     imp::getrandom_inner(dest)
    |     ^^^ use of undeclared crate or module `imp`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0433`.
error: could not compile `getrandom`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed
Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit status: 101
  full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"
@clangenb
Copy link
Collaborator

clangenb commented Jul 13, 2021

This is most likely due to std leakage of the dev-dependencies.

the master branch includes a fix that should solve this: #120

@clangenb
Copy link
Collaborator

The fix only solves your issue if the api-client is the top-level crate, otherwise you need to add "resolver = 2" to your top-level Cargo.toml.

@DylanVerstraete
Copy link
Author

@clangenb Does not seem to work by adding "resolver = 2"

@DylanVerstraete
Copy link
Author

@clangenb
Copy link
Collaborator

clangenb commented Jul 13, 2021

Well, when you want to compile to wasm you need to disable the std-features of the api-client with default-features = false

But this will strip most functionality.

@DylanVerstraete
Copy link
Author

I can't compile to wasm without disabling std-features?

@clangenb
Copy link
Collaborator

I have just checked up on that and found out that std does not inherently break wasm support - but some std-libs do.

So, I reckon we'd need to make some adjustments to be able to support wasm with the std feature enabled. Without should be fine - as far as I know.

@DylanVerstraete
Copy link
Author

If I disable default-features I get:

....
  Compiling sp-wasm-interface v4.0.0-dev (https://github.com/paritytech/substrate.git?branch=master#cf086eeb)
   Compiling sp-arithmetic v4.0.0-dev (https://github.com/paritytech/substrate.git?branch=master#cf086eeb)
   Compiling primitive-types v0.10.1
   Compiling sp-runtime-interface v4.0.0-dev (https://github.com/paritytech/substrate.git?branch=master#cf086eeb)
   Compiling sp-core v4.0.0-dev (https://github.com/paritytech/substrate.git?branch=master#cf086eeb)
   Compiling sp-io v4.0.0-dev (https://github.com/paritytech/substrate.git?branch=master#cf086eeb)
   Compiling frame-metadata v14.0.0-dev (https://github.com/paritytech/substrate.git?branch=master#cf086eeb)
   Compiling sp-inherents v4.0.0-dev (https://github.com/paritytech/substrate.git?branch=master#cf086eeb)
   Compiling sp-application-crypto v4.0.0-dev (https://github.com/paritytech/substrate.git?branch=master#cf086eeb)
error[E0046]: not all trait items implemented, missing: `Pair`
   --> /home/dylan/.cargo/git/checkouts/substrate-7e08433d4c370a21/cf086ee/primitives/application-crypto/src/lib.rs:241:3
    |
241 |         impl $crate::CryptoType for Public {}
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Pair` in implementation
    | 
   ::: /home/dylan/.cargo/git/checkouts/substrate-7e08433d4c370a21/cf086ee/primitives/application-crypto/src/ed25519.rs:29:5
    |
29  |     crate::app_crypto!(super, ED25519);
    |     ----------------------------------- in this macro invocation
    |
    = note: this error originates in the macro `$crate::app_crypto_public_not_full_crypto` (in Nightly builds, run with -Z macro-backtrace for more info)
    = help: implement the missing item: `type Pair = Type;`

error[E0046]: not all trait items implemented, missing: `Pair`
   --> /home/dylan/.cargo/git/checkouts/substrate-7e08433d4c370a21/cf086ee/primitives/application-crypto/src/lib.rs:442:3
    |
442 |         impl $crate::CryptoType for Signature {}
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Pair` in implementation
    | 
   ::: /home/dylan/.cargo/git/checkouts/substrate-7e08433d4c370a21/cf086ee/primitives/application-crypto/src/ed25519.rs:29:5
    |
29  |     crate::app_crypto!(super, ED25519);
    |     ----------------------------------- in this macro invocation
    |
    = note: this error originates in the macro `$crate::app_crypto_signature_not_full_crypto` (in Nightly builds, run with -Z macro-backtrace for more info)
    = help: implement the missing item: `type Pair = Type;`

error[E0046]: not all trait items implemented, missing: `Pair`
   --> /home/dylan/.cargo/git/checkouts/substrate-7e08433d4c370a21/cf086ee/primitives/application-crypto/src/lib.rs:241:3
    |
241 |         impl $crate::CryptoType for Public {}
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Pair` in implementation
    | 
   ::: /home/dylan/.cargo/git/checkouts/substrate-7e08433d4c370a21/cf086ee/primitives/application-crypto/src/sr25519.rs:29:5
    |
29  |     crate::app_crypto!(super, SR25519);
    |     ----------------------------------- in this macro invocation
    |
    = note: this error originates in the macro `$crate::app_crypto_public_not_full_crypto` (in Nightly builds, run with -Z macro-backtrace for more info)
    = help: implement the missing item: `type Pair = Type;`

error[E0046]: not all trait items implemented, missing: `Pair`
   --> /home/dylan/.cargo/git/checkouts/substrate-7e08433d4c370a21/cf086ee/primitives/application-crypto/src/lib.rs:442:3
    |
442 |         impl $crate::CryptoType for Signature {}
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Pair` in implementation
    | 
   ::: /home/dylan/.cargo/git/checkouts/substrate-7e08433d4c370a21/cf086ee/primitives/application-crypto/src/sr25519.rs:29:5
    |
29  |     crate::app_crypto!(super, SR25519);
    |     ----------------------------------- in this macro invocation
    |
    = note: this error originates in the macro `$crate::app_crypto_signature_not_full_crypto` (in Nightly builds, run with -Z macro-backtrace for more info)
    = help: implement the missing item: `type Pair = Type;`

error[E0046]: not all trait items implemented, missing: `Pair`
   --> /home/dylan/.cargo/git/checkouts/substrate-7e08433d4c370a21/cf086ee/primitives/application-crypto/src/lib.rs:241:3
    |
241 |         impl $crate::CryptoType for Public {}
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Pair` in implementation
    | 
   ::: /home/dylan/.cargo/git/checkouts/substrate-7e08433d4c370a21/cf086ee/primitives/application-crypto/src/ecdsa.rs:29:5
    |
29  |     crate::app_crypto!(super, ECDSA);
    |     --------------------------------- in this macro invocation
    |
    = note: this error originates in the macro `$crate::app_crypto_public_not_full_crypto` (in Nightly builds, run with -Z macro-backtrace for more info)
    = help: implement the missing item: `type Pair = Type;`

error[E0046]: not all trait items implemented, missing: `Pair`
   --> /home/dylan/.cargo/git/checkouts/substrate-7e08433d4c370a21/cf086ee/primitives/application-crypto/src/lib.rs:442:3
    |
442 |         impl $crate::CryptoType for Signature {}
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Pair` in implementation
    | 
   ::: /home/dylan/.cargo/git/checkouts/substrate-7e08433d4c370a21/cf086ee/primitives/application-crypto/src/ecdsa.rs:29:5
    |
29  |     crate::app_crypto!(super, ECDSA);
    |     --------------------------------- in this macro invocation
    |
    = note: this error originates in the macro `$crate::app_crypto_signature_not_full_crypto` (in Nightly builds, run with -Z macro-backtrace for more info)
    = help: implement the missing item: `type Pair = Type;`

error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0046`.
error: could not compile `sp-application-crypto`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed
Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit status: 101
  full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"

@clangenb
Copy link
Collaborator

There seemed to be a tiny feature-flag bug on our side. Fixed in #137

@DylanVerstraete
Copy link
Author

@clangenb okay, will I be able to do anything with the client without std-features?

@clangenb
Copy link
Collaborator

Currently, it is essentially the compose_extrinsic_offline! macro, which is not really much. It allows you only to compose and to sign an extrinsic.

@DylanVerstraete
Copy link
Author

@clangenb although it compiles now I get following error trying to import the API

➜ wasm-pack build
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
   Compiling rust-substrate-api-client v0.1.0 (/home/dylan/Projects/rust-substrate-api-client)
error[E0432]: unresolved import `substrate_api_client::Api`
  --> src/lib.rs:13:5
   |
13 | use substrate_api_client::Api;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^ no `Api` in the root

error: aborting due to previous error

For more information about this error, try `rustc --explain E0432`.
error: could not compile `rust-substrate-api-client`

To learn more, run the command again with --verbose.
Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit status: 101
  full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"

@clangenb
Copy link
Collaborator

If you disabled std in the client you ony get access to compose_extrinsic_offline! macro. This no part of the Api strut, but exported to top-level.

use substrate_api_client::compose_extrinsic_offline;

@brenzi brenzi closed this as completed Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants