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

feat(services/azblob): available under wasm32 arch #3806

Merged
merged 4 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 9 additions & 4 deletions core/src/raw/oio/write/append_object_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use std::task::Context;
use std::task::Poll;

use async_trait::async_trait;
use futures::future::BoxFuture;

use crate::raw::*;
use crate::*;
Expand All @@ -34,7 +33,8 @@ use crate::*;
/// - Services impl `AppendObjectWrite`
/// - `AppendObjectWriter` impl `Write`
/// - Expose `AppendObjectWriter` as `Accessor::Writer`
#[async_trait]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
pub trait AppendObjectWrite: Send + Sync + Unpin + 'static {
/// Get the current offset of the append object.
///
Expand All @@ -58,10 +58,15 @@ pub struct AppendObjectWriter<W: AppendObjectWrite> {

enum State<W> {
Idle(Option<W>),
Offset(BoxFuture<'static, (W, Result<u64>)>),
Append(BoxFuture<'static, (W, Result<usize>)>),
Offset(BoxedFuture<(W, Result<u64>)>),
Append(BoxedFuture<(W, Result<usize>)>),
}

/// # Safety
///
/// wasm32 is a special target that we only have one event-loop for this state.
unsafe impl<S: AppendObjectWrite> Send for State<S> {}

/// # Safety
///
/// We will only take `&mut Self` reference for State.
Expand Down
11 changes: 8 additions & 3 deletions core/src/raw/oio/write/one_shot_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use std::task::Context;
use std::task::Poll;

use async_trait::async_trait;
use futures::future::BoxFuture;

use crate::raw::*;
use crate::*;
Expand All @@ -31,7 +30,8 @@ use crate::*;
/// For example, S3 `PUT Object` and fs `write_all`.
///
/// The layout after adopting [`OneShotWrite`]:
#[async_trait]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
pub trait OneShotWrite: Send + Sync + Unpin + 'static {
/// write_once write all data at once.
///
Expand All @@ -47,9 +47,14 @@ pub struct OneShotWriter<W: OneShotWrite> {

enum State<W> {
Idle(Option<W>),
Write(BoxFuture<'static, (W, Result<()>)>),
Write(BoxedFuture<(W, Result<()>)>),
}

/// # Safety
///
/// wasm32 is a special target that we only have one event-loop for this state.
unsafe impl<S: OneShotWrite> Send for State<S> {}

/// # Safety
///
/// We will only take `&mut Self` reference for State.
Expand Down
3 changes: 2 additions & 1 deletion core/src/services/azblob/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,8 @@ pub struct AzblobBackend {
has_sas_token: bool,
}

#[async_trait]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
impl Accessor for AzblobBackend {
type Reader = IncomingAsyncBody;
type BlockingReader = ();
Expand Down
3 changes: 2 additions & 1 deletion core/src/services/azblob/lister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ impl AzblobLister {
}
}

#[async_trait]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
impl oio::PageList for AzblobLister {
async fn next_page(&self, ctx: &mut oio::PageContext) -> Result<()> {
let resp = self
Expand Down
6 changes: 4 additions & 2 deletions core/src/services/azblob/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ impl AzblobWriter {
}
}

#[async_trait]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
impl oio::OneShotWrite for AzblobWriter {
async fn write_once(&self, bs: &dyn oio::WriteBuf) -> Result<()> {
let bs = oio::ChunkedBytes::from_vec(bs.vectored_bytes(bs.remaining()));
Expand All @@ -70,7 +71,8 @@ impl oio::OneShotWrite for AzblobWriter {
}
}

#[async_trait]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
impl oio::AppendObjectWrite for AzblobWriter {
async fn offset(&self) -> Result<u64> {
let resp = self
Expand Down
Loading