You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
I'm working in a project that ethers will be used within Internet Computer environment, which is using WebAssembly.
The issue
What I'm going to describe is an issue in various projects in Rust ecosystem and ethers happens to have it too. At the end I will propose a solution (which I will implement), however it is not going to be backward compatible in the case of wasm32 targets.
wasm32 is an architecture but it does not describe the environment that is going to be used. Most projects assume that the environment is always a browser. Within browser environment it is valid to use wasm-bindgen, js-sys, and web-sys, but this is not valid in any other environments. To be more correct wasm-bindgen and js-sys can be used only in environments with JavaScript and web-sys in browser environments.
getrandom solved this issue by requiring from the user to enable the js feature flag manually. Because of this a user needs to add the feature in the top-level crate otherwise they will get a compilation error.
Proposal
In my opinion something similar needs to be done in ethers too. I'm proposing the following:
Introduce two new feature gates: web-sys and ic (for Internet Computer).
Both feature gates must be disabled by default.
In case of wasm32-unknown-unknown only one of the flags must be enabled. If none of them or both of them are enabled then we trigger compile_error!.
All wasm32 dependencies must be optional and feature flags will enable what is needed.
reqwest and futures-timer crates have the same issue so we need to do the following:
In case of wasm32 we have them as optional and we enable them with web-sys flag.
In case of not(wasm32) we have them as required.
In case of wasm32 and ic flag:
reqwest will be replaced with ic-cdk.
futures-timer will be replaced with ic-cdk-timers.
wasm-bindgen-futures will be replaced with ic-cdk.
Internet Computer does not support WebSockets, so implementation will not be provided if ic is enabled.
Other notes
Should I create a crate for this compatibility layer? If yes, do you have any name in mind?
web-sys can also be named as browser. The js is not a good option since web-sys is used by reqwest.
All the above can be solved within reqwest and futures-timer, but requires much longer effort, which I plan to do in the future.
The text was updated successfully, but these errors were encountered:
Why?
I'm working in a project that ethers will be used within Internet Computer environment, which is using WebAssembly.
The issue
What I'm going to describe is an issue in various projects in Rust ecosystem and ethers happens to have it too. At the end I will propose a solution (which I will implement), however it is not going to be backward compatible in the case of
wasm32
targets.wasm32
is an architecture but it does not describe the environment that is going to be used. Most projects assume that the environment is always a browser. Within browser environment it is valid to usewasm-bindgen
,js-sys
, andweb-sys
, but this is not valid in any other environments. To be more correctwasm-bindgen
andjs-sys
can be used only in environments with JavaScript andweb-sys
in browser environments.getrandom
solved this issue by requiring from the user to enable thejs
feature flag manually. Because of this a user needs to add the feature in the top-level crate otherwise they will get a compilation error.Proposal
In my opinion something similar needs to be done in ethers too. I'm proposing the following:
web-sys
andic
(for Internet Computer).wasm32-unknown-unknown
only one of the flags must be enabled. If none of them or both of them are enabled then we triggercompile_error!
.wasm32
dependencies must be optional and feature flags will enable what is needed.reqwest
andfutures-timer
crates have the same issue so we need to do the following:wasm32
we have them as optional and we enable them withweb-sys
flag.not(wasm32)
we have them as required.wasm32
andic
flag:reqwest
will be replaced withic-cdk
.futures-timer
will be replaced withic-cdk-timers
.wasm-bindgen-futures
will be replaced withic-cdk
.ic
is enabled.Other notes
web-sys
can also be named asbrowser
. Thejs
is not a good option sinceweb-sys
is used byreqwest
.reqwest
andfutures-timer
, but requires much longer effort, which I plan to do in the future.The text was updated successfully, but these errors were encountered: