[WIP] Remove Send bounds on wasm32 #2074
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #910
Also related: #1235
Changes
Attempting to compile to WASM produces a number of errors regarding
Send
bounds, as reported in #1235. This is becausewasm_bindgen::JsValue
is notSend
, since it's intended to run in a single-threaded JS environment.This issue was successfully addressed in the
rspotify
crate in ramsayleung/rspotify#458, although I thinkopentelemetry-rust
requires a somewhat more complex solution.I've managed to fix these errors (see other WASM errors in #1472 and #2047) by conditionally removing
Send
bounds fortarget_arch="wasm32"
.I've done this in three ways:
#[async_trait]
to#[async_trait(?Send)]
based ontarget_arch
BoxFuture
withMaybeSendBoxFuture
, which conditionally removesSend
bounds on wasmArc<dyn InstrumentProvider + Send + Sync>
withtype ArcInstrumentProvider = Arc<dyn InstrumentProvider>
on WASM andtype ArcInstrumentProvider = Arc<dyn InstrumentProvider + Send + Sync>
otherwise.I suspect that this PR is not yet complete. Initially, I only made enough changes to get my application to compile, using the following feature flags:
I then continued by replacing all instances of
#[async_trait]
that seemed relevant. But I assume that there are other crates or feature flags that would require similar changes.I'm also happy to hear your feedback on this approach, and make changes as necessary.
Thanks,
Oliver
Merge requirement checklist
CHANGELOG.md
files updated for non-trivial, user-facing changes