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

UX: set feature flags of rand for wasm target #97

Closed
benmkw opened this issue Mar 31, 2020 · 2 comments
Closed

UX: set feature flags of rand for wasm target #97

benmkw opened this issue Mar 31, 2020 · 2 comments

Comments

@benmkw
Copy link

benmkw commented Mar 31, 2020

What were you trying to do

compile to wasm

What happened

it works but I found it a bit difficult due to rand dep

We have to make sure that Os::Rand is not called in the browser cause it panics. This can be configured in rand 0.7.3 by using
rand = { version = "0.7.3", features = ["wasm-bindgen"] } however this is now deprecated in rust-random/rand#948 and I would need to do something along the same lines with getrandom now but the problem is basically the same.

This is basically a question of me not understanding how to best handle this in Cargo.toml and not sure if I need to do/ know something or if the proper way would be for this crate to make the solution easier.

As far as I understand, if I add rand as a dependency in my project explicitly (instead of it just being transitively required by age) I can specify feature flags and because both age and my crate use the same rand version, both use the one configured with my feature flag (my crate does not actually "use" rand itself, it just adds it as a dep such that it can set its features).

If however, for some reason, I would want to use a rand version incompatible with age, I could not use this solution and my create would use two rand versions at the same time (afaik this is supported by rust) (using one directly and another one as a dep of one age) and by doing this I would loose the ability to effectively set/ overwrite the feature flags of my transitive dependencies.

My suggestion is that I either don't understand how to handle this or that age might need to expose a feature flag which gets forwarded to rand.

(Performance is fine now that I compile in release mode btw. so your fix regarding os::Time was perfectly fine)

@pirate
Copy link

pirate commented Sep 11, 2020

It looks like rust-random/rand#886 was closed as fixed 🎉. Does that mean this issue can also be closed?

@benmkw
Copy link
Author

benmkw commented Sep 11, 2020

Yes I think the way cargo handles setting features of dependencies of dependencies is less than ideal but it seems to be the current way how to do it so this can be closed.

@benmkw benmkw closed this as completed Sep 11, 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

No branches or pull requests

2 participants