Skip to content

Parts of RA re-execute itself, making it unsuitable for use as a library #10516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aidanhs opened this issue Oct 11, 2021 · 3 comments · Fixed by #14100
Closed

Parts of RA re-execute itself, making it unsuitable for use as a library #10516

aidanhs opened this issue Oct 11, 2021 · 3 comments · Fixed by #14100
Assignees
Labels
C-Architecture Big architectural things which we need to figure up-front (or suggestions for rewrites :0) ) C-bug Category: bug

Comments

@aidanhs
Copy link
Member

aidanhs commented Oct 11, 2021

Specifically https://github.com/rust-analyzer/rust-analyzer/blob/ed4b312fa777ebb39ba1348fe3df574c441a485e/crates/rust-analyzer/src/cli/load_cargo.rs#L44-L63

I was surprised, because the comment says "this function is used by external tools that use rust-analyzer as a library" - but it then promptly re-executes RA.

I was able to work around via environment variables in my binary code, but I couldn't find this gotcha documented anywhere (in particular, in ARCHITECTURE.md).

@flodiebold
Copy link
Member

I suspect the consumers using this function don't enable proc macros. IMO the rust-analyzer crate is not really intended as a public interface. But ping @matklad

@flodiebold
Copy link
Member

Yeah: regexident/cargo-modules@5c71c97

@matklad
Copy link
Member

matklad commented Oct 11, 2021

Yeah, in general we don't give any guarantees about our API, up to potentially eating one of your socks.

That being said, it's the wrong API to just self-execute from the guts on the library. std::env::current_exe() should every be only called in main, and everything else should just get an ProcMacroServer as an argument.

@flodiebold flodiebold added C-Architecture Big architectural things which we need to figure up-front (or suggestions for rewrites :0) ) C-bug Category: bug labels Jun 28, 2022
@Veykril Veykril self-assigned this Jan 30, 2023
@bors bors closed this as completed in 512a93a Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Architecture Big architectural things which we need to figure up-front (or suggestions for rewrites :0) ) C-bug Category: bug
Projects
None yet
4 participants