Skip to content

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

@benmkw

Description

@benmkw

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions