Skip to content
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

Compatibility with wasm #144

Open
amiyatulu opened this issue Sep 8, 2023 · 15 comments
Open

Compatibility with wasm #144

amiyatulu opened this issue Sep 8, 2023 · 15 comments

Comments

@amiyatulu
Copy link

Can megalodon-rs support wasm so that it can used by rust framework like yew?

@h3poteto
Copy link
Owner

Please read: #53

@h3poteto
Copy link
Owner

duplicated

@h3poteto h3poteto closed this as not planned Won't fix, can't repro, duplicate, stale Sep 23, 2023
@amiyatulu
Copy link
Author

Still it doesn't support error

megalodon= {version="0.11.8"}

error[E0432]: unresolved import crate::sys::IoSourceState
--> /home/amiya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.10/src/io_source.rs:12:5
|
12 | use crate::sys::IoSourceState;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ no IoSourceState in sys

error[E0432]: unresolved import crate::sys::tcp
--> /home/amiya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.10/src/net/tcp/listener.rs:15:17
|
15 | use crate::sys::tcp::{bind, listen, new_for_addr};
| ^^^ could not find tcp in sys

error[E0432]: unresolved import crate::sys::tcp
--> /home/amiya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.10/src/net/tcp/stream.rs:13:17
|
13 | use crate::sys::tcp::{connect, new_for_addr};
| ^^^ could not find tcp in sys

error[E0433]: failed to resolve: could not find Selector in sys
--> /home/amiya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.10/src/poll.rs:312:18
|
312 | sys::Selector::new().map(|selector| Poll {
| ^^^^^^^^ could not find Selector in sys

error[E0433]: failed to resolve: could not find event in sys
--> /home/amiya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.10/src/event/event.rs:24:14
|
24 | sys::event::token(&self.inner)
| ^^^^^ could not find event in sys

error[E0433]: failed to resolve: could not find event in sys
--> /home/amiya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.10/src/event/event.rs:38:14
|
38 | sys::event::is_readable(&self.inner)
| ^^^^^ could not find event in sys

error[E0433]: failed to resolve: could not find event in sys
--> /home/amiya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.10/src/event/event.rs:43:14
|
43 | sys::event::is_writable(&self.inner)
| ^^^^^ could not find event in sys

error[E0433]: failed to resolve: could not find event in sys
--> /home/amiya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.10/src/event/event.rs:68:14
|
68 | sys::event::is_error(&self.inner)
| ^^^^^ could not find event in sys

error[E0433]: failed to resolve: could not find event in sys
--> /home/amiya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.10/src/event/event.rs:99:14
|
99 | sys::event::is_read_closed(&self.inner)
| ^^^^^ could not find event in sys

@anderspitman
Copy link

@h3poteto would you consider re-opening this? In order for megalodon to work in wasm, I believe more functionality is required. I haven't yet managed to get reqwest to work from wasm. oauth2-rs support providing your own FnOnce for making HTTP requests. Using that I was able to get oauth2-rs and openidconnect-rs to work. Does megalodon currently support any sort of similar flow?

@h3poteto h3poteto reopened this Nov 27, 2024
@h3poteto
Copy link
Owner

No.
I've tried to build megalodon with wasm, but it was the same.

@anderspitman
Copy link

In the last few weeks I found another library that follows a similar pattern to oauth2-rs/openidconnect-rs: https://github.com/sugyan/atrium. Atrium makes multiple network requests internally, but it's simple to provide your own implementations for the network calls. For example you can see here the relatively few lines of code necessary for me to implement my own HTTP client function for wasm32 (running in Extism):

https://github.com/lastlogin-net/decent-auth-rs/blob/176bb8737179de9bfeecf9424a4354d91f06cbd0/src/atproto.rs#L283

This allowed me to add Bluesky/ATProto login to my library with far less effort and increased security.

I believe this is similar to the concept of sans-io development, but I'm not an expert in that. Would you be interested in adding this sort of flexibility to megalodon?

@h3poteto
Copy link
Owner

Hmm, in the first place, why do you want to use megalodon-rs with wasm?
Why not JavaScript version megalodon? https://github.com/h3poteto/megalodon

@anderspitman
Copy link

I'm actually targeting backend, not frontend. I'm building an authentication library for multiple languages. Currently have it working for JS, Go, and Rust, but adding support for any of the Extism host languages (https://extism.org/) should be relatively straight forward.

@h3poteto
Copy link
Owner

If it's backend, why do you need to use wasm instead of compiling with rust?

@anderspitman
Copy link

You mean compile the Rust to FFI via extern C? Primarily because wasm is far more portable (especially for JS and Golang). You can run the same wasm binary unchanged on many platforms and languages.

@h3poteto
Copy link
Owner

Sorry, I don't really get it, why do you need wasm if you're targeting the backend?

@anderspitman
Copy link

anderspitman commented Dec 18, 2024

Say I'm building a JS app and want to add ATProto login. I need to find a JS library that supports that. Next imagine I'm writing a Golang app and want to do the same thing. Now I need to find a completely different library, which likely has a different feature set. The library I'm working on works in JS, Golang, Rust, and others are easy to add. It also supports login with ATProto, Fediverse, OIDC, etc. One auth library that provides a consistent feature set and API in many languages.

If I wasn't using wasm, I would have to implement each feature in every language. Using wasm I implement a feature once and it immediately works in every language. Building for wasm is the best way I've found to accomplish this.

@h3poteto
Copy link
Owner

But to do that, each library needs to be wasm-compatible, right?
It would be fine if it were very easy, but isn't this just pushing the costs of implementing it onto the libraries side?

@anderspitman
Copy link

Technically, yes. But this is becoming more and more common. ATrium and oauth2-rs already were compatible. And there are other benefits to designing APIs this way. It makes things more modular, and reduces your dependency on reqwest, while still retaining a high-level API for those who desire the default settings.

But I totally get it if this isn't a priority for you.

@h3poteto
Copy link
Owner

Hmm, I understand the situation. However, since the situation where it is needed is limited, this issue is not a high priority for me.

Also, according to my investigation, the compile errors are not coming from reqwest and oauth2. Those errors are coming from tokio-tungstenite. It depends on tokio/net. We can't compile tokio/net with wasm. If wasm environment is browser, we can use wasm-bindgen and js-sys. But I'm not sure if it will work with Extism you require.

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