mirror of
https://github.com/ramsayleung/rspotify.git
synced 2026-04-26 07:55:55 +03:00
[GH-ISSUE #292] Support for wasm and Cloudflare Workers #90
Labels
No labels
Stale
bug
discussion
enhancement
good first issue
good first issue
help wanted
pull-request
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/rspotify#90
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @shiguma127 on GitHub (Dec 10, 2021).
Original GitHub issue: https://github.com/ramsayleung/rspotify/issues/292
I would like to use this library with Cloudflare Workers.
when I try to compile the following code
then it occurs this error
and when i use rspotify whth features=["client-ureq","ureq-rustls-tls"] on wrangler project
I can compile, but I can't deploy with this error.
I don't think there is anything that can't be done since reqwest also supports wasm.
How do you think?
Thaks.
@marioortizmanero commented on GitHub (Dec 10, 2021):
Thanks for the report. We had never tried to compile to wasm so anything could happen. It would be great to make it possible as long as it's not super complicated. I have no idea how Cloudflare Workers work, though.
It seems like
reqwest::Responseis notSendon wasm, but it is for other targets. I think this makes sense because there is no support for multi-threading in wasm yet, soSendis not necessary. In reqwest,Responsehas a completely different implementation for wasm. I rancargo doc --target=wasm32-unknown-unknownin order to see the source of the issue, and it's true:Responseis made up of aBox<Url>, which isSend, and ahttp::Response<web_sys::Response>.http::ResponseisSend, and finally,web_sys::Responseis notSend. In fact, almost nothing inweb_sysisSend, so it's not like we could just make a PR in order to make itSendupstream. And as I said, it wouldn't make sense to make itSendanyway because it's all single-threaded.The solution to this would be to just not enforce
SendorSyncin our traits, such asBaseHttpClientorBaseClient, when compiling towasm. This could be done via feature flags, and I don't think it would be too complicated. We would also have to addwasmto our CI to make sure it's always working.Unfortunately, I don't have enough free time right now for this myself right now. I'm on finals and working on my final year project. Maybe after New Years or so, I don't know. Supporting wasm seems viable, but it's definitely quite a bit of work. If you're interested in doing it yourself I could definitely review your changes from time to time or give you advice. You more or less know where to start now. Or maybe @ramsayleung wants to help out.
@ramsayleung commented on GitHub (Dec 11, 2021):
It would be great to make this crate to compile to
wasm, even though I had never tried to compile this project towasmbefore either, and I also have no idea about how Cloudflare Workers work.Is there a way to create an environment to reproduce this issue?
As Mario illustrating clearly, there are two ways to compile
reqwestto wasm:SendSendandSyncwith feature flags, and omittingSendandSynctrait when compiling towasmBoth solutions take time to work. If you can't wait to develop your project and make
rspotifycompile towasm, I think the quick-fix solution:It seems the
client-ureqcan compile towasm, but fails for some unknown reasons. Perhaps there is still a way to compilerspotifyto Cloudflare Workers when we figure out the reason why it fails@tomocrafter commented on GitHub (Dec 11, 2021):
I've managed to compile it with removing all of Send markers from signatures and maybe_async on following commit and it works on Cloudflare Wokers as expected.
github.com/shiguma127/rspotify@3313925911also tried to make it switchable with feature but seems like cargo doesn't allow us to flag features depends on arch yet so I couldn't.
If you have any workaround or idea, please let me know!
@shiguma127 commented on GitHub (Dec 11, 2021):
After looking at the commit above, I figured I didn't need to delete all sends, so I created the following commit.
github.com/shiguma127/rspotify@2d5d5cabeeHowever, there is no need to remove the Send boundary of the structure, and replacing
with
as in the commit below compiles and seems to work with cloudflere-workers.
github.com/shiguma127/rspotify@2d5d5cabeeI am not sure if this is the best solution.
Thanks for your help.
@marioortizmanero commented on GitHub (Dec 11, 2021):
Great! No need to add a feature, we can just use the target itself to configure whether it's send or not (e. g.
#[cfg(target = ...)]or#[cfg_attr(target = ...)]).What could be a problem is trying to make that switch with all the
impl IntoIterator, because there are no trait alias yet on rust. There is a known workaround for that, so it's not a problem, really: https://stackoverflow.com/a/26071172.Could you perhaps make a PR with those changes?
@tomocrafter commented on GitHub (Dec 11, 2021):
@marioortizmanero Thank you for your support!
I created the PR that switches between
maybe_async(?Send)andmaybe_asyncdepends on target_arch. but I'm not sure why some of it doesn't need to bemaybe_async(?Send)because I'm not used to Rust so much.If you have time, Can you explain why it doesn't fail on compile without changing all of it and removing all of Send makers?
@marioortizmanero commented on GitHub (Dec 11, 2021):
Notice that some of these
Senderrors may only appear when you use the data structure. So if you don't use e.g. the code auth client, you won't needmaybe_asyncon that because it's not being used anyway. Try not adding these "unnecessary" switches and then running all the tests and examples, you might see how they don't compile after that.Not 100% sure anyway, I'll have to try it myself when I have time.
@djedlajn commented on GitHub (Nov 1, 2022):
Can we have #293 reviewed and merged to enable compiling to wasm and deploying to Cloudflare?
@djedlajn commented on GitHub (Nov 1, 2022):
I have managed to make it work as per #293 will raise PR at some point this week I just need to address prior concerns related to CI and to make sure that all tests pass.
@marioortizmanero commented on GitHub (Dec 26, 2022):
Hi @djedlajn, did you end up managing to fix #293?
@github-actions[bot] commented on GitHub (Jul 2, 2023):
Message to comment on stale issues. If none provided, will not mark issues stale
@gelendir commented on GitHub (Feb 14, 2024):
Hey, wanted to let you know that I tried finishing what @shiguma127 started, PR here: https://github.com/ramsayleung/rspotify/pull/458
@ramsayleung commented on GitHub (Mar 8, 2024):
Closing this issue since the support for wasm and Cloudflare has been merged.