This is an automated email from the ASF dual-hosted git repository.

suyanhanx pushed a commit to branch azblob-wasm
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git

commit 08c3c22a51b14e7a5fb56e93c3b5ccbda145fe27
Author: suyanhanx <[email protected]>
AuthorDate: Fri Dec 22 22:25:46 2023 +0800

    feat(services/azblob): available under wasm32 arch
    
    Signed-off-by: suyanhanx <[email protected]>
---
 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 ++++--
 5 files changed, 25 insertions(+), 11 deletions(-)

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

Reply via email to