I'm not sure this question is the best fit for this forum, since it is a support question, but I haven't had any luck in spaces for general Rust users. This question is about using rustc as a library via rustc_interface
.
Essentially, I'm trying to use rustc_interface::run_compiler()
to produce HIR, where the input
is a simple rust module that contains use
statements importing other crates. I can produce HIR on a simple file with no use
statements just fine, but when I encounter a use
, I get a compiler error saying the crate is not found and I must use extern crate
. When using extern crate
, I then get a metadata_cannot_find_crate
error (actually, an error that that fluent string can't be found).
I'm wondering how I can configure the compiler to find all of the necessary crates. Do I need to list Externs? Or is this a job for SearchPath? I followed the example in rustc-dev-guide to get me this far, but can't figure out how to extend it to a multi-crate situation given my near-zero knowledge of rustc's architecture. I opened an issue linking to a minimal reproduction, for more context: Example of using rustc_interface to generate the HIR for a file referencing dependent crates? · Issue #1720 · rust-lang/rustc-dev-guide · GitHub