rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.14k stars 1.58k forks source link

How to set features for different crates in a workspace? #15988

Open junderw opened 10 months ago

junderw commented 10 months ago

I have a workspace with 2 crates.

  1. A library that has various features like std which I can turn off for no_std, and also by default a rand feature that includes the rand crate.
  2. A WASM binary that targets wasm32-unknown-unknown. This depends on crate 1 with default-features = false (to allow no_std)

The WASM binary replaces the #[panic_handler] and cargo check and cargo build throw no errors.

However, rust-analyzer gives me an error on the panic handler:

found duplicate lang item `panic_impl`
the lang item is first defined in crate `std` (which `test` depends on)
first definition in `std` loaded from /home/jonathan/.rustup/toolchains/1.74.0-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd-3354d2cb1f357486.rlib
second definition in the local crate

Here's the repo: https://github.com/bitcoinjs/tiny-secp256k1/tree/wip/modular (note: the wip/modular branch) (I've committed the .cargo folder and .vscode folder)

lnicola commented 10 months ago

It might not be what you want, but you can disable the default features when working on the WASM part, which will make std go away.

The other option I can see is to use two VS Code workspaces, one with the library, and one with both, and disable the default features in the workspace settings for the latter.

Veykril commented 10 months ago

That is currently not possible, configs are global only until #13529 is done