-
Notifications
You must be signed in to change notification settings - Fork 207
Make the documentation for WASM targets clearer #89
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
Conversation
For people who run in a compile error because `wasm-bindgen` or `stdweb` features are not enabled, clarify that they can enable it even if getrandom gets pulled in by one of their dependencies.
Thanks for the PR — sounds like a sensible thing to do. Perhaps add a line like the following:
|
@@ -62,6 +62,10 @@ | |||
//! by enabling the `dummy` feature, which will make `getrandom` to use an | |||
//! always failing implementation. | |||
//! | |||
//! If you are seeing this compiler error even though your crate doesn't directly | |||
//! depend on getrandom (one of your dependencies pulls it in), you can still solve | |||
//! this by adding getrandom as a dependency to your `Cargo.toml` with the correct feature. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there is the feature to be enabled. Also please take a look at #87. I am not sure if enabling dummy
, stdweb
or wasm-bindgen
feature in an non-application Cargo.toml
is a correct recommendation.
So I think the problem will mainly arise in dev-builds, e.g. because benchmarks need system entropy, but not tests and CI job runs tests for [dev-dependencies]
getrandom = "0.1" And enable a needed |
@dhardy do you mean add an example line to the docs? I could add that, but I haven't yet really understood the usefulness of the "dummy" feature though. If it's being pulled in, it's because people want it to work, I suppose most users don't want to just turn compile time failure into runtime failure? Also, I have said it on the futures-rs issue, but one thing that worries me a bit is that when libraries enable this feature, the end use has to change their Cargo.toml, which means it's a breaking change. Currently futures-rs pulls this in with a feature on futures. So if an intermediate library suddenly decides to use that functionality from futures (join or select macro), that might break end user application. Meaning that features like using a join macro now becomes a breaking change, which isn't documented anywhere. This feature also isn't exactly additive. The docs say if both features are enabled
@newpavlov I don't know if it's correctly used, but in the futures library, if you turn on the feature that enables the |
From Cargo's point of view, all feature flags are additive. For the Yes, true, adding a dependency on Alternatively maybe we should just assume |
after the discussion in #63 I will try to rephrase the doc PR to be clearer. Does the following seem right (to come after the paragraph about wasm32-unkown-unknown?
|
I am not sure if need the note about breaking change. How about something like this? Library authors should not set these features in their Cargo.toml outside of dev builds. Meaning, if you test [dev-dependencies]
getrandom = { version = "0.1", features = ["wasm-bindgen"] } Note: features enabled for dev builds leak to non-dev builds (see rust-lang/cargo#1796), but only for the current workspace or path dependencies, meaning you can publish crate with such dependency to crates.io without enabling the feature for all your downstream dependencies. Alternatively you can add [dependencies]
getrandom = "0.1" And enable one of the features manually: cargo build --features=getrandom/dummy You may cascade the features by adding features like |
Closed in favor of #90. |
For people who run in a compile error because
wasm-bindgen
andstdweb
features are not enabled, clarify that they can enable them even if getrandom gets pulled in by one of their dependencies.I think this isn't necessarily obvious. I didn't realize that I could set features for indirect dependencies.
What I do wonder about though is if this is the desired workflow, why does the
rand
crate forward this feature? And should a user specifygetrandom
with saywasm-bindgen
in their Cargo.toml, or should they set the feature onrand
.Note also that library authors might have to set this at least in
dev-dependencies
to make tests and examples run.