This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
The following commit(s) were added to refs/heads/main by this push:
new 235bd9ea2 feat(services/azblob): available under wasm32 arch (#3806)
235bd9ea2 is described below
commit 235bd9ea23a33dcccc3c49c095bed00f77673ba5
Author: Suyan <[email protected]>
AuthorDate: Sat Dec 23 00:17:29 2023 +0800
feat(services/azblob): available under wasm32 arch (#3806)
---
.github/workflows/ci.yml | 7 ++++++-
core/src/raw/oio/write/append_object_write.rs | 13 +++++++++----
core/src/raw/oio/write/one_shot_write.rs | 11 ++++++++---
core/src/services/azblob/backend.rs | 3 ++-
core/src/services/azblob/lister.rs | 3 ++-
core/src/services/azblob/writer.rs | 6 ++++--
6 files changed, 31 insertions(+), 12 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 714b256a7..091893e52 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -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
diff --git a/core/src/raw/oio/write/append_object_write.rs
b/core/src/raw/oio/write/append_object_write.rs
index 93d182f40..e0f591c8a 100644
--- a/core/src/raw/oio/write/append_object_write.rs
+++ b/core/src/raw/oio/write/append_object_write.rs
@@ -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::*;
@@ -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.
///
@@ -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.
diff --git a/core/src/raw/oio/write/one_shot_write.rs
b/core/src/raw/oio/write/one_shot_write.rs
index 85357d608..453131767 100644
--- a/core/src/raw/oio/write/one_shot_write.rs
+++ b/core/src/raw/oio/write/one_shot_write.rs
@@ -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::*;
@@ -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.
///
@@ -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.
diff --git a/core/src/services/azblob/backend.rs
b/core/src/services/azblob/backend.rs
index fdce556bb..d7ae49344 100644
--- a/core/src/services/azblob/backend.rs
+++ b/core/src/services/azblob/backend.rs
@@ -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 = ();
diff --git a/core/src/services/azblob/lister.rs
b/core/src/services/azblob/lister.rs
index bcd93d3bd..6760cecb2 100644
--- a/core/src/services/azblob/lister.rs
+++ b/core/src/services/azblob/lister.rs
@@ -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
diff --git a/core/src/services/azblob/writer.rs
b/core/src/services/azblob/writer.rs
index d78ae8dc7..989684288 100644
--- a/core/src/services/azblob/writer.rs
+++ b/core/src/services/azblob/writer.rs
@@ -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()));
@@ -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