[rust-dev] Invoking rustc as crate?

Christoph Husse thesaint1987 at googlemail.com
Sun Jul 13 00:42:30 PDT 2014


Hmm interesting, copying the generated tests executable (that is the
exe containing my unittests, which in turn invoke the rustc compiler
through the rustc crate) into the rust-compiler's root directory
solved this problem, even though this "workflow" isn't exactly
pleasing...

So I tried various things now. Including:

1) Copying the entrie rustc root directory over the generated
executable [Same error]
2) Copying the entrie rustc root directory into the working directory
of my unit tests [Same error]
3) copying my unittest executable into the rustc root directory [Success]

Any ideas how I could make one of the first two options work too?


On Sun, Jul 13, 2014 at 9:10 AM, Christoph Husse
<thesaint1987 at googlemail.com> 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`"
>
> 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


More information about the Rust-dev mailing list