[PR #458] [MERGED] Support wasm32-unknown-unknown architecture #468

Closed
opened 2026-02-27 20:24:50 +03:00 by kerem · 0 comments
Owner

📋 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: masterHead: wasm-support


📝 Commits (4)

📊 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-http traits. One could implement the BaseHttpClient trait outside of this crate and then build a SpotifyClient<CustomHttpClient>. Feature flags would need to be refactored since this crate forces choosing a http client through the client-reqwest or client-ureq features.

Dependencies

  • wasm-pack for building and running tests
  • NodeJS for running tests

The other dependencies are managed through Cargo.toml

Type of change

  • New feature (non-breaking change which adds functionality)

How has this been tested?

The #[wasm_bindgen_test] attribute has been added to all tests. They all pass when running wasm-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
  • Chrome
  • Firefox

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_ID and RSPOTIFY_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.

## 📋 Pull Request Information **Original PR:** https://github.com/ramsayleung/rspotify/pull/458 **Author:** [@gelendir](https://github.com/gelendir) **Created:** 2/14/2024 **Status:** ✅ Merged **Merged:** 2/29/2024 **Merged by:** [@ramsayleung](https://github.com/ramsayleung) **Base:** `master` ← **Head:** `wasm-support` --- ### 📝 Commits (4) - [`2b23e5b`](https://github.com/ramsayleung/rspotify/commit/2b23e5bc0b452b3f9c50c3ccbf90293653803c18) Support wasm32-unknown-unknown architecture - [`64be77d`](https://github.com/ramsayleung/rspotify/commit/64be77d461383b207490f926b524b489a1c34aa2) code formatting - [`70d5026`](https://github.com/ramsayleung/rspotify/commit/70d50265031bc8b2e37b718f5e77db6ba926d374) fix clippy errors - [`9bf39b4`](https://github.com/ramsayleung/rspotify/commit/9bf39b44019cb8519a0d067a254abfc9ddc52fe7) document wasm support ### 📊 Changes **20 files changed** (+533 additions, -93 deletions) <details> <summary>View changed files</summary> 📝 `.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) </details> ### 📄 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-http` traits. One could implement the `BaseHttpClient` trait outside of this crate and then build a `SpotifyClient<CustomHttpClient>`. Feature flags would need to be refactored since this crate forces choosing a http client through the `client-reqwest` or `client-ureq` features. ## Dependencies * `wasm-pack` for building and running tests * NodeJS for running tests The other dependencies are managed through `Cargo.toml` ## Type of change - [ ] New feature (non-breaking change which adds functionality) ## How has this been tested? The `#[wasm_bindgen_test]` attribute has been added to all tests. They all pass when running `wasm-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 * Chrome * Firefox 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_ID` and `RSPOTIFY_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 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 20:24:50 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/rspotify#468
No description provided.