rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

Environment variable for build.rs script

Open lexi-the-cute opened this issue 1 year ago • 4 comments

I've been having to figure out how to detect rust-analyzer in my build script to selectively disable a function that only needs to run during actual builds and not during code checking. I just submitted an issue about stack overflowing to the build-info crate team at https://github.com/danielschemmel/build-info/issues/16 about this very same issue.

I'm currently implementing a custom environment variable in my IDE just for rust-analyzer, but it would be nice for this to be universal

lexi-the-cute avatar Feb 21 '24 06:02 lexi-the-cute

You should be able to use cfg!(rust_analyzer) in your build script to customize behavior. Note that the cfg is only set for local crates in your workspace, not dependencies.

Veykril avatar Feb 21 '24 08:02 Veykril

Note that the proc-macro in question spews out a rather large function primarily consisting of a large (>30k lines in this case) initializer. That initalizer has a few levels of nesting (low double digits), but nothing humongous, it is just long - the tree is wide rather than deep.

The function also compiles fine (optimization takes way too long, but works fine), and should not necessarily cause rust-analyzer to overflow its stack.

danielschemmel avatar Feb 24 '24 23:02 danielschemmel

Ah, I r-a doesn't employ any stack space ensuring when inferring types (which rustc does I believe), so us overflowing in that case wouldn't be too surprising.

Veykril avatar Feb 28 '24 13:02 Veykril

You could also #[cfg(not(rust_analyzer))] the generated code, I think?

flodiebold avatar Feb 28 '24 23:02 flodiebold