mirror of
https://github.com/ramsayleung/rspotify.git
synced 2026-04-26 16:05:53 +03:00
[PR #458] [MERGED] Support wasm32-unknown-unknown architecture #468
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#468
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?
📋 Pull Request Information
Original PR: https://github.com/ramsayleung/rspotify/pull/458
Author: @gelendir
Created: 2/14/2024
Status: ✅ Merged
Merged: 2/29/2024
Merged by: @ramsayleung
Base:
master← Head:wasm-support📝 Commits (4)
2b23e5bSupport wasm32-unknown-unknown architecture64be77dcode formatting70d5026fix clippy errors9bf39b4document wasm support📊 Changes
20 files changed (+533 additions, -93 deletions)
View changed files
📝
.github/workflows/ci.yml(+27 -0)📝
CHANGELOG.md(+5 -0)📝
Cargo.toml(+15 -2)📝
README.md(+10 -0)📝
rspotify-http/src/common.rs(+2 -1)📝
rspotify-http/src/reqwest.rs(+16 -1)📝
src/auth_code.rs(+4 -2)📝
src/auth_code_pkce.rs(+4 -2)📝
src/client_creds.rs(+2 -1)📝
src/clients/base.rs(+2 -1)📝
src/clients/oauth.rs(+2 -1)📝
src/clients/pagination/mod.rs(+10 -2)➕
src/clients/pagination/wasm_stream.rs(+62 -0)📝
src/lib.rs(+19 -1)📝
tests/test_enums.rs(+13 -0)📝
tests/test_models.rs(+23 -0)📝
tests/test_oauth2.rs(+4 -0)📝
tests/test_with_credential.rs(+100 -30)📝
tests/test_with_oauth.rs(+192 -49)➕
tests/util.rs(+21 -0)📄 Description
Description
Modifications needed to compile rspotify for a WebAssembly runtime. (i.e.
cargo build --target wasm32-unknown-unknown)Motivation and Context
I want to build an app that helps me better manage music when using spotify to DJ. I'd like to use rust + WASM to build it, however none of the maintained spotify crates support WASM.
@shiguma127 made an attempt in https://github.com/ramsayleung/rspotify/pull/293, but the PR was closed. This PR improves on what he started.
This is my most "complex" rust endeavor so far and I would be happy to get feedback on better ways of refactoring or rearchitecturing.
The code is now littered with a bunch of architecture conditionals that might be hard to maintain. I'm open to trying better alternatives if the maintainers don't like this.
One idea would be to make it easier to use the
rspotify-httptraits. One could implement theBaseHttpClienttrait outside of this crate and then build aSpotifyClient<CustomHttpClient>. Feature flags would need to be refactored since this crate forces choosing a http client through theclient-reqwestorclient-ureqfeatures.Dependencies
wasm-packfor building and running testsThe other dependencies are managed through
Cargo.tomlType of change
How has this been tested?
The
#[wasm_bindgen_test]attribute has been added to all tests. They all pass when runningwasm-pack test --node. The attribute doesn't conflict with#[test](but it does add an extra dev-dependency)wasm-pack depends on a WASM runtime to run tests. The 3 currently supported are:
NodeJS is the default, so that's what's configured in the CI job
Client ID and Client secret
Some of the tests depend on environment variables
RSPOTIFY_CLIENT_IDandRSPOTIFY_CLIENT_SECRET. However, WASM does not support the concept of environment variables. As a workaround the variables are imported at compile time only when running tests.Is this change properly documented?
I wasn't sure if wasm support warrants documentation or not. I'm happy to add documentation as part of this PR
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.