Skip to content
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

Some fixes to #[cfg] regarding Wasi #1633

Merged
merged 3 commits into from
Jun 30, 2020
Merged

Some fixes to #[cfg] regarding Wasi #1633

merged 3 commits into from
Jun 30, 2020

Conversation

tomaka
Copy link
Member

@tomaka tomaka commented Jun 28, 2020

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 and libp2p-noise, when compiling for wasm, we opt-out from the ring library because the library doesn't support the wasm target. This is currently detected with target_os = "unknown" or any(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 to target_arch = "wasm32".

At the crate root, we opt-out from crates such as libp2p-tcp and libp2p-mdns because they require the operating system to support TCP/UDP sockets. Similarly, this is currently detected with any(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 now any(target_os = "emscripten", target_os = "wasi", target_os = "unknown").

I included an unrelated change: libp2p-uds is currently enabled if all(unix, not(any(target_os = "emscripten", target_os = "unknown")). Since target_os = "unknown" and unix can and will, by definition, never be true at the same time, I removed it and kept only all(unix, not(target_os = "emscripten")).

Unfortunately, libp2p-secio doesn't compile for wasi. It does currently compile for wasm32-unknown-unknown because we assume that unknown 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.

@romanb romanb merged commit 79ff1e4 into libp2p:master Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants