Skip to content

Commit

Permalink
*: Drop generic wasm32-unknown-unknown support (#2038)
Browse files Browse the repository at this point in the history
With `rand` `v0.8.0` platform support changed [1] due to its upgrade to
`getrandom` `v0.2`. With `getrandom` `v0.2` `wasm32-unknown-unknown` is no
longer supported out of the box:

> This crate fully supports the wasm32-wasi and wasm32-unknown-emscripten
> targets. However, the wasm32-unknown-unknown target is not automatically
> supported since, from the target name alone, we cannot deduce which JavaScript
> interface is in use (or if JavaScript is available at all).
>
> Instead, if the "js" Cargo feature is enabled, this crate will assume that you
> are building for an environment containing JavaScript, and will call the
> appropriate methods. Both web browser (main window and Web Workers) and
> Node.js environments are supported, invoking the methods described above using
> the wasm-bindgen toolchain.
>
> This feature has no effect on targets other than wasm32-unknown-unknown.

This commit drops support for wasm32-unknown-unknown in favor of the two more
specific targets wasm32-wasi and wasm32-unknown-emscripten.

Note on `resolver = "2"`: The new resolver is required to prevent features
being mixed, more specifically to prevent libp2p-noise to build with the
`ring-resolver` feature. See [3] for details.

---

[1] https://github.com/rust-random/rand/blob/master/CHANGELOG.md#platform-support
[2] https://docs.rs/getrandom/0.2.2/getrandom/#webassembly-support
[3] https://doc.rust-lang.org/nightly/cargo/reference/features.html#feature-resolver-version-2
  • Loading branch information
mxinden committed Apr 12, 2021
1 parent 687145d commit 8ccb96a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,18 @@ jobs:

- uses: actions/checkout@v2

- name: Install Rust
- name: Install Rust wasm32-unknown-emscripten
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: wasm32-unknown-unknown
target: wasm32-unknown-emscripten
override: true

- name: Install Rust wasm32-wasi
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: wasm32-wasi
override: true

- name: Install a recent version of clang
Expand All @@ -85,10 +92,15 @@ jobs:
path: target
key: wasm-cargo-build-target-${{ hashFiles('Cargo.toml') }}

- name: Build on WASM
- name: Build on wasm32-unknown-emscripten
# TODO: also run `cargo test`
# TODO: ideally we would build `--workspace`, but not all crates compile for WASM
run: cargo build --target=wasm32-unknown-emscripten

- name: Build on wasm32-wasi
# TODO: also run `cargo test`
# TODO: ideally we would build `--workspace`, but not all crates compile for WASM
run: cargo build --target=wasm32-unknown-unknown
run: cargo build --target=wasm32-wasi

check-rustdoc-links:
name: Check rustdoc intra-doc links
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
- `libp2p-request-response`
- `libp2p-swarm`
- `libp2p-wasm-ext`

- Drop support for `wasm32-unknown-unknown` in favor of
`wasm32-unknown-emscripten` and `wasm32-wasi` [PR
2038](https://github.com/libp2p/rust-libp2p/pull/2038).

## Version 0.36.0 [2021-03-17]

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ env_logger = "0.8.1"
tokio = { version = "1.0.1", features = ["io-util", "io-std", "macros", "rt", "rt-multi-thread"] }

[workspace]
resolver = "2"
members = [
"core",
"misc/multiaddr",
Expand Down

0 comments on commit 8ccb96a

Please sign in to comment.