rust-analyzer
rust-analyzer copied to clipboard
Environment variable for build.rs script
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
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.
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.
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.
You could also #[cfg(not(rust_analyzer))] the generated code, I think?