paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK
https://polkadot.network/
1.82k stars 662 forks source link

Can't build for IOS if referencing sp-core/std many library std libraries that link to sp-core/std #3909

Closed blakebyrnes closed 6 months ago

blakebyrnes commented 6 months ago

Is there an existing issue?

Experiencing problems? Have you tried our Stack Exchange first?

Description of bug

I'm trying to build bindings for an IOS library, and when referencing some std libraries, they link back to sp-core/std, which has a dependency on wasmtime and will not allow building for IOS due to a lack of JIT. I have a shared crate that has references to several substrate types that I use in both the runtime and in the node. While trying to use this crate, I can't seem to unwind the dependency on sp-core/std that many libraries link back to. (The Parity Vault project is working around this by turning off std for both sp-core and sp-runtime. I would like to do this, but I have several substrate libraries, and was unable to unlink all the dependencies that eventually land one of them on linking to sp-core/std, and thus wasmtime.)

My question is - would you be open to either a flag turning off wasm in the core libraries and/or a flag that just disables linking to wasmtime on iOS. FWIW, that's what I did to resolve the issue for now (https://github.com/ulixee/polkadot-sdk/tree/release-polkadot-v1.9.0). I'm not sure if this is something that you'd be willing to support, as it might give the wrong impression that sp-core is runnable in iOS, but I'd love to have an option to include sp-core without this patch.

Steps to reproduce

  1. Link to sp-core
  2. Create a feature with sp-core/std
  3. Try to build for an iOS target
ggwpez commented 6 months ago

I'm trying to build bindings for an IOS library

Bindings for what crate? What Rust code are you trying to access rom IOS?

I would like to do this, but I have several substrate libraries, and was unable to unlink all the dependencies that eventually land one of them on linking to sp-core/std, and thus wasmtime

Can you not just set default-features = false? That should turn off std - as long as you only depend on runtime crates.
The runtime is build for our embedded Polkadot host, but if you depend on node crates, then it will pull in std i guess.

blakebyrnes commented 6 months ago

Sorry, that was a confusing way to say it. It's our own primitives library that I'm trying to link into an iOS client app. The app needs some substrate primitives and crypto functions that are linked to in the primitives library and the client that can also be run via CLI and over nodejs bindings. I'm using uniffi to create the iOS bindings. Since sp-runtime and sp-core both have primitives needed to interoperate with AccountIds, MultiSignatures, MultiSigners, Crypto primitives, etc, I've seen several projects link them in (subxt, parity-vault, our own stuff).

blakebyrnes commented 6 months ago

@ggwpez Did that make sense?

ggwpez commented 6 months ago

And with your patch it works? Maybe we can use that to disable WASMtime on IOS @bkchr ?

blakebyrnes commented 6 months ago

It does resolve my issue locally.

bkchr commented 6 months ago

https://github.com/paritytech/polkadot-sdk/pull/3954 this should also solve your issue.

blakebyrnes commented 6 months ago

@bkchr Even better. Thanks!