Reputation: 3729
I am writing an application targeting Wasm target (Yew platform), and I have getrandom
dependency. However recently the support changed, and according to the doc, I now need to:
wasm_js
feature--cfg getrandom_backend="linux_getrandom"
I have done it, setting RUSTFLAGS environment variable to cover 2nd case, but now it causes issue to run cargo test
or cargo clippy
as they are compiled for a different target, for which I should not use the feature nor set the flags.
I am trying to use Cargo.toml
for it and I have set this:
[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.3", features = ["wasm_js"] }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
getrandom = "0.3"
[target.wasm32-unknown-unknown]
rustflags = ["--cfg", "getrandom_backend='wasm_js'"]
The dependencies part seems to work ok, in the sense that I can run cargo clippy
, cargo test
and trunk serve
. However the part to set the flags does not work. I have this warning:
warning: unused manifest key: target.wasm32-unknown-unknown.rustflags
And for trunk serve
I still need to set rust flags manually to make it work:
RUSTFLAGS="--cfg getrandom_backend=\"wasm_js\"" trunk serve
While this is what I understand from the Cargo doc. I also tried this with no more success:
[target.'cfg(target_arch = "wasm32")']
rustflags = ["--cfg", "getrandom_backend=\"wasm_js\""]
Any idea what I am missing?
Upvotes: 0
Views: 20
Reputation: 793
The configuration for rustflags
should not be in the Cargo.toml
file, it should be in the file .cargo/config.toml
. See the documentation.
Upvotes: 0