[rust-dev] Invoking rustc as crate?

Brian Anderson banderson at mozilla.com
Mon Jul 14 11:14:14 PDT 2014


On 07/13/2014 12:10 AM, Christoph Husse wrote:
> Hi,
>
> I successfully managed to hook into the compiler so far. Or well it's
> not that successful, because it doesn't work, but at least the code is
> there ;).
>
> Now I am trying to compile an empty file, and it gives me the weird error:
>
> "error: can't find crate for `std`"

rustc guesses the 'sysroot' based on the location of the rustc binary. 
It expects a directory layout like

bin/
   rustc
lib/
   rustlib/

and will assume it can find libraries somewhere like ../lib/rustlib/... 
If your binary is not located in the correct location it will fail. 
Sysroot can be overridden in the session options somewhere.

>
> Any chance there could be more insight? Normally a C++ compiler is
> able to also tell you the library search paths at least, and in this
> case it would be helpful to print the assumed hash code suffix that
> was expected (I assume the fact that it runs in my executable instead
> of the real compiler makes it somehow look for and STD with a
> different hash suffix).
>
> To zero out the chance that I did something wrong with externalizing
> parts of the compiler driver into my own application, I wrote a simple
> main method with the following "fallback":
>
> rustc::driver::main_args(args.as_slice())
>
> It will simply do what rustc does... Invoke the rustc compiler with
> the arguments provided. This call will land inside of the compiler
> that was used to compile the very same statement (I hope). Its using
> the "rustc" crate after all.
>
> Still the same error message ;)
>
> So how could that be resolved? This is also an issue for custom Lint
> plugins I guess, because you will definitely not want to invoke rustc
> as external command and then have your plugin run in a different
> process. I basically need the AST after analysis in its pure form,
> like no JSON or something. Just want to continue where the compiler
> left off... Instead of generating LLVM & stuff, which is not needed in
> my case.
>
> best
> chris
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev



More information about the Rust-dev mailing list