Stream: t-compiler/rust-analyzer

Topic: How do I set non-feature cfgs?


Jake Goulding (Mar 20 2021 at 17:28, on Zulip):

I want to pass --cfg spec when checking my code. I found cargo.features, but that appears to force the usage of "feature".

Jonas Schievink [he/him] (Mar 20 2021 at 17:35, on Zulip):

I think currently the only way to do this is to set it from a build script

Joshua Nelson (Mar 20 2021 at 17:40, on Zulip):

does RA allow passing arbitrary rustflags?

Jonas Schievink [he/him] (Mar 20 2021 at 17:41, on Zulip):

RUSTFLAGS is passed through, but we ignore it

Jake Goulding (Mar 20 2021 at 18:02, on Zulip):

Unfortunate. It looks like it _was_ supported at some point? https://github.com/rust-analyzer/rust-analyzer/issues/1073

Jake Goulding (Mar 20 2021 at 18:03, on Zulip):

Oh, maybe that's literally also just features

Jonas Schievink [he/him] (Mar 20 2021 at 18:05, on Zulip):

Nothing was removed here, that issue was closed when basic support for handling #[cfg] landed

Jake Goulding (Mar 20 2021 at 18:10, on Zulip):

Should I open an issue for supporting additional cfg?

Jake Goulding (Mar 20 2021 at 18:11, on Zulip):

https://github.com/rust-analyzer/rust-analyzer/issues/5421

Jake Goulding (Mar 20 2021 at 18:12, on Zulip):

I did see that there's an option for cfg when not using Cargo — https://rust-analyzer.github.io/manual.html#non-cargo-based-projects

matklad (Mar 22 2021 at 17:02, on Zulip):

Should be perhaps pares RUSTFLAGS?

matklad (Mar 22 2021 at 17:03, on Zulip):

@Jake Goulding what do you use to set this for cargo? RUSTFLAGS or something else?

bjorn3 (Mar 22 2021 at 17:04, on Zulip):

You can use rustc --print cfg $RUSTFLAGS to get the list of all enabled cfgs.

matklad (Mar 22 2021 at 17:05, on Zulip):

wow, that's nice, that means that the impl is trivial, as we are already running --print cfg

Jake Goulding (Mar 24 2021 at 12:53, on Zulip):

matklad said:

Jake Goulding what do you use to set this for cargo? RUSTFLAGS or something else?

I am running:

CARGO_BUILD_PIPELINING=false cargo rustc -- --crate-type=bin --cfg=spec
Jake Goulding (Mar 24 2021 at 12:53, on Zulip):

(sorry for long delays; been in a lot of training :wink:)

matklad (Mar 24 2021 at 12:59, on Zulip):

Hm, that's tricky -- while RUSFLAGS are global, config via rustc I think applies only to one target. Yup:

The specified args will all be passed to the final compiler invocation, not any of the dependencies.

So the config we want here would be a map from (package, target) pairs to additional cfg. It shouldn't be that hard to implement, but would be quite annoing, especially because there's no clean way to identifiy a package/target pair (cargo identifies them implicitly, via --lib, --bin, etc args)

Jake Goulding (Mar 25 2021 at 12:50, on Zulip):

For my particular case, the cfg could go to every crate. It’s the exact same concept as cfg(test).

Jake Goulding (Mar 25 2021 at 12:51, on Zulip):

People would want it to effectively always be on in their editor if they were using this.

Last update: Jul 24 2021 at 19:45UTC