Specify features only under target

I'm trying to fork the reqwest crate so that it can be configured to not use the browser API on wasm32, similiar to the chrono crate at crates.io (which I just discovered that uses a default feature called "wasmbind" that can be disabled via default-features = false in Cargo.toml).

Here are the relevant dependencies:

[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = { version = "0.3.45", optional = true }
serde_json = { version = "1.0", optional = true }
wasm-bindgen = { version = "0.2.68", optional = true }
wasm-bindgen-futures = { version = "0.4.18", optional = true }
wasm-streams = { version = "0.3", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys]
version = "0.3.25"
optional = true
features = [
    "AbortController",
    "AbortSignal",
    "Headers",
    "Request",
    "RequestInit",
    "RequestMode",
    "Response",
    "Window",
    "FormData",
    "Blob",
    "BlobPropertyBag",
    "ServiceWorkerGlobalScope",
    "RequestCredentials",
    "File",
    "ReadableStream"
]

(I've added optional = true to other dev-dependencies too...)

The problem:

[features]
wasmbind = [
    "js-sys?",
    "serde_json?",
    "wasm-bingen?",
    "wasm-bindgen-futures?",
    "web-sys?",
]

I get this log:

dev-dependencies are not allowed to be optional: `wasm-bindgen`

Any idea? Can I just leave the dev-dependencies in this case as non-optional?


I still get this anyway, even removing optional from dev-dependencies:

feature `wasmbind` includes `js-sys?` which is neither a dependency nor another feature

... Would this work? It produces no log...

[target.'cfg(target_arch = "wasm32")'.features]
wasmbind = [ ... ]

Typo I think. wasmbingen => wasmbindgen

Overall, I won't be able to do this. The conditional dependencies are more trouble than imaginable. So I'll really leave this for later

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.