From ad0a05991c4fe63abeb34dde62ec58a2c81dfd05 Mon Sep 17 00:00:00 2001 From: Naja Melan Date: Wed, 14 Aug 2019 21:51:11 +0200 Subject: [PATCH] Expose features from rand to avoid compilation breakage on WASM Current error: ``` error: target is not supported, for more information see: https://docs.rs/getrandom/#unsupported-targets --> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.1.9/src/lib.rs:249:9 | 249 | / compile_error!("\ 250 | | target is not supported, for more information see: \ 251 | | https://docs.rs/getrandom/#unsupported-targets\ 252 | | "); | |___________^ ``` In order to use `join!` and `select!` macros, we require the user to enable the `async-await` and `nightly` features. However those features will pull in rand. In order to work on WASM rand needs to have either the `wasm-bindgen` or `stdweb` feature enabled. Otherwise compile time breakage happens due to the `getrandom` crate. Explanation can be found here: https://docs.rs/getrandom/0.1.9/getrandom/#unsupported-targets This commit exposes those features through `futures-util`, allowing the end user to enable them when compiling on WASM. This means futures does not need to choose which feature to enable which would take away that decision from the end user. An alternative would be to detect the wasm32 target in Cargo.toml and to choose one of the features automatically. Current approach requires action on part of the user to enable one of those features, which means it should probably be documented somewhere. Currently the documentation of `join!` and `select!` does not mention the need for the `async-await` and `nightly` features. I propose we add some documentation changes to this PR before merging. On some quick testing this alleviates the compile error on my system, but it would be good if someone else had a look, or if we had CI testing for WASM. --- futures-util/Cargo.toml | 4 ++++ futures/Cargo.toml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/futures-util/Cargo.toml b/futures-util/Cargo.toml index 617fcff471..578d50b9d5 100644 --- a/futures-util/Cargo.toml +++ b/futures-util/Cargo.toml @@ -30,6 +30,10 @@ channel = ["std", "futures-channel-preview"] join-macro = ["async-await", "futures-join-macro-preview", "proc-macro-hack", "proc-macro-nested"] select-macro = ["async-await", "futures-select-macro-preview", "proc-macro-hack", "proc-macro-nested", "rand"] +# re-export optional WASM dependencies to avoid breakage in getrandom: +wasm-bindgen = ["rand/wasm-bindgen"] +stdweb = ["rand/stdweb"] + [dependencies] futures-core-preview = { path = "../futures-core", version = "=0.3.0-alpha.18", default-features = false } futures-channel-preview = { path = "../futures-channel", version = "=0.3.0-alpha.18", default-features = false, features = ["std"], optional = true } diff --git a/futures/Cargo.toml b/futures/Cargo.toml index 14fe4fdf1e..d38499c861 100644 --- a/futures/Cargo.toml +++ b/futures/Cargo.toml @@ -45,5 +45,9 @@ compat = ["std", "futures-util-preview/compat"] io-compat = ["compat", "futures-util-preview/io-compat"] cfg-target-has-atomic = ["futures-core-preview/cfg-target-has-atomic", "futures-channel-preview/cfg-target-has-atomic", "futures-util-preview/cfg-target-has-atomic"] +# re-export optional WASM dependencies to avoid breakage in rand: +wasm-bindgen = ["futures-util-preview/wasm-bindgen"] +stdweb = ["futures-util-preview/stdweb"] + [package.metadata.docs.rs] all-features = true