-
Notifications
You must be signed in to change notification settings - Fork 957
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
Enable wasm-bindgen
feature for the parking_lot
dependency
#2143
Comments
Even better, we can dynamically enable the feature if we are compiling for wasm: [target.'cfg(target_arch = "wasm32")'.dependencies]
parking_lot = { version = "0.11", features = ["wasm-bindgen"] } What I don't quite understand is why this isn't directly done in
That is indeed strange. Maybe LTO is at work here and all the code has been optimized away because it wasn't used and your usecase is the first one where it is exposed? |
Right, good point! Although, the
The |
Might be worthwhile looking into porting our
Thanks for the detailed write-up! I guess the cleanest way would be to leave the choice up to the user again but that is not very ergonomic. Ultimately, @mxinden will have to make a decision here. |
Thanks @PhilippGackstatter and @thomaseizinger for the discussion above.
Wild guess, Substrate - the main user of the libp2p in WASM - enabled the
Well, as far as I can tell, you could do something along the lines of the above, importing the same
Agreed @thomaseizinger. I think this is worth exploring.
Bubbling up the |
Digging into this a bit, I found async-rs/futures-timer#51 which suggests that It does look like the
Even though it is not quite as ergonomic, I see now that it would be unnecessarily limiting to default to I support the idea of bubbling up the |
I considered doing that, but because of other feature resolution issues we're now using
Since opening this issue, I have also tried using Given that, I also agree with the feature based approach. However, |
I think it should be possible but I don't know of libraries in the ecosystem that allow for this much flexibility. One option would be to build our own abstractions on top of To accelerate initial development and reduce friction, the Given the complexity of the setup, I think it would be worthwhile to add dedicated tests like https://github.com/paritytech/substrate/tree/c625c2ad924a5f58fbe4efbe937255c42eb3f7eb/bin/node/browser-testing/src to our CI so we can: a) Make sure these things work across various stacks, i.e. browser wasm, nodejs wasm, etc
I am surprised by this. It is my understanding that the primary feature of the new feature-resolver is that it will for example not activate a feature of a dependency that is specified only in a
That is not quite true I think. Nodejs supports |
Sorry for the delay in response. And many thanks for spending the time on exploring this topic!
Thanks a lot for pointing that out. This led me to try this in Is that an acceptable fix for you, or do you think using With that "fixed", there is one other issue with a randomness source, but I have to investigate more and see if changing resolvers is a "fix". For node.js, there are two more issue with the JS snippet that implements websocket transports. One is that a browser environment is assumed and listening is currently not implemented:
The other is how snippets work within diff --git a/../../../rust-libp2p/transports/wasm-ext/src/websockets.js b/node/snippets/libp2p-wasm-ext-0d97e6de9e440efd/src/websockets.js
index 290af96..f7a9517 100644
--- a/../../../rust-libp2p/transports/wasm-ext/src/websockets.js
+++ b/node/snippets/libp2p-wasm-ext-0d97e6de9e440efd/src/websockets.js
@@ -18,7 +18,9 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
-export const websocket_transport = () => {
+const WebSocket = require('ws');
+
+const websocket_transport = () => {
return {
dial: dial,
listen_on: (addr) => {
@@ -29,6 +31,8 @@ export const websocket_transport = () => {
};
}
+exports.websocket_transport = websocket_transport;
+
/// Turns a string multiaddress into a WebSockets string URL.
const multiaddr_to_ws = (addr) => {
let parsed = addr.match(/^\/(ip4|ip6|dns4|dns6|dns)\/(.*?)\/tcp\/(.*?)\/(ws|wss|x-parity-ws\/(.*)|x-parity-wss\/(.*))(|\/p2p\/[a-zA-Z0-9]+)$/);
Perhaps I have misunderstood how it works 🤔. |
To follow up on this, the issue was solved by specifying the
The other things are fixed by the two PRs I just opened (see references above). We might still open a PR to add listening support in the |
To be honest, I don't know. From what I can see, naming these features For now #2180, seems to be the way forward as we basically have to follow upstream here in whatever they are doing. |
Following up on this issue and tomaka/wasm-timer#18, I would like to discuss once more, whether rust-libp2p should switch to https://github.com/sebcrozet/instant and https://github.com/async-rs/futures-timer. Not familiar with the technical barriers we might face, as a maintainer I am in favor of the move, given the larger community and the consolidation across the Rust WASM ecosystem. @PhilippGackstatter @thomaseizinger @Thoralf-M do you think this is an option worth exploring? |
I'm not familiar with the technical barriers either, unfortunately. Given that |
I am in favor of |
I'm currently trying to get the libp2p work within a web worker, where I bumped against the mentioned issue with Not sure about supporting nodejs though. |
I am building
rust-libp2p
as part of our Wasm bindings. The produced WebAssembly module ends up containing this import and call to anow
function:This import then ends up in the
wasm-bindgen
-generated JavaScript file where theenv
import is not found and an error is produced.According to this comment, this is the result of the dependency on
parking_lot
, where the fix is to enable thewasm-bindgen
feature on that crate.If the feature is enabled in
rust-libp2p
'sCargo.toml
, then the import is no longer present and the issue is fixed.I assume the best way to fix this, would be to enable the
wasm-bindgen
feature of theparking_lot
crate whenrust-libp2p
'swasm-ext
feature is enabled. However, I'm not sure if I'm not actually missing something, as this seems like an issue that should have come up in the past when compiling towasm32-unknown-unknown
.Please let me know if you would like a PR that adds this or if there's another way to work around it.
The text was updated successfully, but these errors were encountered: