-
Notifications
You must be signed in to change notification settings - Fork 246
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
Start addressing some wasm32-unknown-unknown errors for matrix-sdk-ui crate #4122
base: main
Are you sure you want to change the base?
Conversation
55f7b61
to
617c622
Compare
#[cfg(target_arch = "wasm32")] | ||
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>; | ||
#[cfg(not(target_arch = "wasm32"))] | ||
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[cfg(target_arch = "wasm32")] | |
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>; | |
#[cfg(not(target_arch = "wasm32"))] | |
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>; | |
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + SendOutsideWasm + 'a>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this definition already existed though, why did you move it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed to expose the .boxed
method on the wasm version of the code (it was present on the real future, but not the Wasm version). It seemed like this was where the wasm future was being defined, so I wanted to move the BoxFuture method here so it can be exposed in the same place.
#[cfg(not(target_arch = "wasm32"))] | ||
impl<'a, F, T> BoxFutureExt<'a, T> for F | ||
where | ||
F: Future<Output = T> + 'a + Send, | ||
T: 'a, | ||
{ | ||
fn box_future(self) -> BoxFuture<'a, T> { | ||
self.boxed() | ||
} | ||
} | ||
|
||
#[cfg(target_arch = "wasm32")] | ||
impl<'a, F, T> BoxFutureExt<'a, T> for F | ||
where | ||
F: Future<Output = T> + 'a, | ||
T: 'a, | ||
{ | ||
fn box_future(self) -> BoxFuture<'a, T> { | ||
self.boxed_local() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
impl blocks can be merged the same way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was struggling to get it to compile with the extra + Send
trait needed on the not-wasm32 version.
This commit adjusts types and traits to support targeting wasm32.
617c622
to
b93d3b7
Compare
c9def0d
to
26943b1
Compare
26943b1
to
ac6b065
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4122 +/- ##
==========================================
- Coverage 84.69% 84.67% -0.03%
==========================================
Files 269 268 -1
Lines 28816 28830 +14
==========================================
+ Hits 24405 24411 +6
- Misses 4411 4419 +8 ☔ View full report in Codecov by Sentry. |
With an additional change to relax the use of Send+Sync in the eyeball package, I have the rest of this crate building locally. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks sensible, left a couple of nits.
@@ -28,7 +28,7 @@ pub(in crate::timeline) struct LocalEventTimelineItem { | |||
pub send_state: EventSendState, | |||
/// The transaction ID. | |||
pub transaction_id: OwnedTransactionId, | |||
/// A handle to manipulate this event before it is sent, if possible. | |||
// A handle to manipulate this event before it is sent, if possible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this about? That looks like an accident.
@@ -512,7 +509,7 @@ macro_rules! impl_event_handler { | |||
impl<Ev, Fun, Fut, $($ty),*> EventHandler<Ev, ($($ty,)*)> for Fun | |||
where | |||
Ev: SyncEvent, | |||
Fun: FnOnce(Ev, $($ty),*) -> Fut + Clone + SendOutsideWasm + SyncOutsideWasm + 'static, | |||
Fun: FnOnce(Ev, $($ty),*) -> Fut + Clone + Send + Sync + 'static, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, why would you need Send
+ Sync
unconditionally here?
This change consists mostly of type-wrangling to support building the matrix-sdk-ui crate for wasm32-unknown-unknown. It is a step along the way of (ideally) supporting wasm32 throughout the entire project. The matrix-sdk-ui packages is not yet compiling due to some blocking issues, but these changes should be able to be landed now as a step towards that goal.
The changes consist of one of two main types.
Signed-off-by: Daniel Salinas