Including rustc_driver forces dynamic libstd linking


I am currently working on a project that interfaces with parts of the Rust compiler. To do this, I am using the rustc_driver crate, along with a few other rustc crates like session and interface. When I go to build the executable, the compiler dynamically links libstd. Is there I way that I can force it to be statically linked instead?

No. rustc_driver is only available as dylib. It is dynamically linked to libstd.

Is this If so does provide enough functionality instead?

Gotcha. I think I found something on the docs yesterday that says that I'm supposed to use rustc_interface in a library instead of rustc_driver. It just means that I have to do more work on my end I guess.

Yes, that is my fork of kythe/kythe. I am working with the team for my summer internship to bring Rust support to the tool. Our functionality is different than a language server, so we need to interface with the compiler ourselves. Thank you for the help!

Rust-analyzer isn't just a language server. It does everything from parsing to name resolution and type inference itself. It doesn't use rustc. The kind of information Kythe seems to provide to tools is pretty much what rust-analyzer has been optimized to quickly and lazily compute. Incremental recompilation in check mode with rustc can take several seconds where rust-analyzer does so in less than a second. rust-analyzer has been developed as replacement of rls, which does use rustc to compute all information. Rls is much slower however and is missing many nice features.

1 Like

Ah gotcha! I was confused because I have seen it used in language server plugins before. The main reason we have been looking at using Rustc is because we receive source and .rlib files as inputs. But if rust-analyzer can produce analysis using those files as inputs, I will definitely work to use that API in the Rust indexer.

That is indeed the main purpose. The language server protocol specific parts are strictly separated from the rest though.

Rust-analyzer doesn't know how to read rlib files. Instead it takes the source of the current crate and all dependencies.

If you have any more questions go ask at wg-rls-2.0 stream on the rust-lang zulip. This is the main place of communication regarding rust-analyzer together with the github repo.

Awesome, I will go ahead and use that for my questions! Thank you


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.