Skip to content

Commit

Permalink
feat(services/azblob): available under wasm32 arch (#3806)
Browse files Browse the repository at this point in the history
  • Loading branch information
suyanhanx authored Dec 22, 2023
1 parent b9a96b8 commit 235bd9e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,13 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build
run: |
available_services=(
services-azblob
services-s3
)
IFS=","
rustup target add wasm32-unknown-unknown
cargo build --target wasm32-unknown-unknown --no-default-features --features=services-s3
cargo build --target wasm32-unknown-unknown --no-default-features --features="${available_services[*]}"
unit:
runs-on: ubuntu-latest
Expand Down
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

0 comments on commit 235bd9e

Please sign in to comment.