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

wasm support #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ jobs:
uses: dtolnay/rust-toolchain@stable
- name: cargo fmt
run: cargo fmt --all -- --check

wasm:
name: wasm32 build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
- name: wasm32 build
run: cargo build --target=wasm32-unknown-unknown

clippy:
name: Clippy
Expand Down
4 changes: 4 additions & 0 deletions src/onedrive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ impl OneDrive {
/// # Panics
/// It panics if the underlying `reqwest::Client` cannot be created.
pub fn new(access_token: impl Into<String>, drive: impl Into<DriveLocation>) -> Self {
#[cfg(not(target_arch = "wasm32"))]
let client = Client::builder()
.redirect(reqwest::redirect::Policy::none())
.gzip(true)
.build()
.unwrap();
#[cfg(target_arch = "wasm32")]
let client = Client::builder().build().unwrap();
Comment on lines +65 to +72
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Do you mean gzip or redirect is unsupported on wasm32?

redirect must not be disabled because get_item_download_url requires it to correctly function. The documentation of new_with_client already mentioned this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep reqwest does not have redirect or gzip for wasm32 target.

I propose for wasm we:

  • Disable get_item_download_url
  • Add get_item_content, which follows redirects and return a Vec<u8>

What do you think?

Copy link
Owner

@oxalica oxalica May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep reqwest does not have redirect or gzip for wasm32 target.

Are there target-related difficulties about implementing them? Or is it just reqwest have not yet implemented them? It seems ClientBuilder on wasm32 is pretty incomplete (there are even placeholder documentations) and have only few methods available.

  • Disable get_item_download_url
  • Add get_item_content, which follows redirects and return a Vec<u8>

I'm not a fan of providing different (and inconsistent) APIs on different targets.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about:

  • For get_item_download_url, add a cfg_if to panic on wasm with something like not supported, please use get_item_content
  • Implement get_item_content for all platforms

I also don't quite get get_item_download_url. What benefits does it have over simply following redirects and provide get_item_content directly?


Self::new_with_client(client, access_token, drive.into())
}

Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl RequestBuilderExt for RequestBuilder {
}
}

type BoxFuture<T> = std::pin::Pin<Box<dyn std::future::Future<Output = T> + Send + 'static>>;
type BoxFuture<T> = std::pin::Pin<Box<dyn std::future::Future<Output = T> + 'static>>;

// TODO: Avoid boxing?
pub(crate) trait ResponseExt: Sized {
wooden-worm marked this conversation as resolved.
Show resolved Hide resolved
Expand Down