-
Notifications
You must be signed in to change notification settings - Fork 431
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
Stop forwarding getrandom's wasm features #886
Comments
Meanwhile you can add a comment to Also maybe add a milestone for v0.8 so it will be easier to track such breaking changes? |
I used the rand wasm-bindgen feature and am not sure how to best achieve the same thing after you removed it. Maybe this is a limitation of my understanding of cargo. I see no option to enable the feature of getrandom which is a dependency of rand which is a depency of age which is a dependency my crate. If my crate would use a different version of getrandom or one of my dependencies would use getrandom with incompatible feature flags to rand I'd have no way of activating the feature. Is this intended? As far as I see the situation cargo requires every app to forward all feture flags to the top level or there is an option to change features of dependencies of dependencies [sic] in Cargo.toml which I could not yet discover. My example is basically this https://www.reddit.com/r/rust/comments/3s48re/avoiding_different_version_of_crates/cwu174a/ . Maybe in the case of getrandom this is unlikely so its not supported/ expected to break? |
Ideally, cargo should add feature injection, ala |
@benmkw getrandom = { version = "0.1", features = ["wasm-bindgen"] } In [target.wasm32-unknown-unknown.dependencies]
wasm-bindgen-getrandom = "0.1" Farther in future |
As far as I can see they would need to forward features of deps to make it possible to enable them reliably, because..
My point was that this approach does not seem to work (I mean that I have not figured out how) if I need a version of getrandom which is incomptible with the version the dep of a dep of me is using. (This is a hypothetical situation for me at the moment) Splitting crates seems like a very rough approach to an issue which is basically what features are made to solve (I guess). |
But there are no such versions right now and in the future version there will be no features to forward! During transition period when apps will have both
The issue is not WASM specific, similar problems arise for other targets, such as embedded or UEFI. Custom crates is essentially our way to emulate |
Ok thanks for your consideration, I think at some point maybe cargo should support something like @burdges mentioned but I'm sure this approach has limitations/ other issues as well with regards to compatibility or else it would have already been considered. I think in this case a similar issue was solved with confilicting features between "dev-deps" and "direct/ own deps" vs in my example "direct/ own deps" and "deps of deps". But in their case they already knew how to specify the features. My point was basically that rand should continue forwarding the feature flags of getrandom as it makes feature selection more robust but as you described, the "hack" with requiring getrandom on the top level and thus setting its feature flags is not likely to break in the future in a way I described so its fine. |
If you want this now, then you could do a build.rs script that checked the dependencies matched. I suppose you'd need some dev dependencies of build.rs for reading the cargo.lock, which they become annoying dependencies for the library. lol I think getrandom 0.2 uses |
This was fixed with 0aa4617. |
The `rand` crate won't build properly for the `wasm32-unknown-unknown` target unless we also depend directly on the `getrandom` crate and enable its `js` feature. References: * rust-random/rand#886 * https://docs.rs/getrandom/0.2/getrandom/#webassembly-support
This is apparently the way to do it now. See also rust-random/rand#886. Closes #7 and closes #4.
For rand 0.8, I suggest we stop forwarding these features in
rand
. Since this is currently the only reason we depend on thegetrandom
crate directly, this allows us to remove thegetrandom_package
rename hack, thus also clearing up #881.This means that WASM users (who are using
wasm32-unknown-unknown
instead of the newerwasm32-wasi
target) will need to depend ongetrandom
directly (but see also rust-random/getrandom#63).Likely we would retain the
getrandom
feature:default → std → getrandom → rand_core/getrandom
, though we could also drop that (default → std → rand_core/getrandom
).This is technically a breaking change, thus we can't do so before 0.8 (which likely won't be soon).
The text was updated successfully, but these errors were encountered: