Some fixes to #[cfg] regarding Wasi #1633
Merged
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.
I've been experimenting compiling and using libp2p for the
wasm32-wasi
target, and unfortunately our#[cfg]
blocks are a bit weird regarding this platform.In
libp2p-core
andlibp2p-noise
, when compiling for wasm, we opt-out from thering
library because the library doesn't support the wasm target. This is currently detected withtarget_os = "unknown"
orany(target_os = "emscripten", target_os = "unknown")
.Considering that the problem comes from
ring
containing inline assembly, which is an architecture-related problem, I changed that totarget_arch = "wasm32"
.At the crate root, we opt-out from crates such as
libp2p-tcp
andlibp2p-mdns
because they require the operating system to support TCP/UDP sockets. Similarly, this is currently detected withany(target_os = "emscripten", target_os = "unknown")
.But here, since this is about a requirement from the operating system, I simply added
wasi
to the list, which is nowany(target_os = "emscripten", target_os = "wasi", target_os = "unknown")
.I included an unrelated change:
libp2p-uds
is currently enabled ifall(unix, not(any(target_os = "emscripten", target_os = "unknown"))
. Sincetarget_os = "unknown"
andunix
can and will, by definition, never be true at the same time, I removed it and kept onlyall(unix, not(target_os = "emscripten"))
.Unfortunately,
libp2p-secio
doesn't compile forwasi
. It does currently compile forwasm32-unknown-unknown
because we assume thatunknown
equals "the browser", which is a hack.wasi
isn't really meant to be run from the browser, therefore we can't apply the same hack.For this reason, I can't add a CI check for the changes in this PR without being more invasive, which I don't think is a good idea for a low tier platform such as
wasi
.