Lookup for all invocations of the particular `proc-macro` inside another crate

240 views Asked by At

I have a build script where I have access to a lot of information about another crate via cargo_metadata.

Now I'm looking for the way to find all invocations of a specific proc-macro inside the another crate.

Theoretically, I can parse another crate's sources by myself but I prefer to avoid it in any way possible for the well known reasons :-)

Ideally, I'm looking for the crate which is used by the compiler already. Or at least the crate which somehow use compiler's output to collect that kind of information.

But any solution will be helpful!

There is how ideal solution may looks like from my code prospective:

use proc_macro::TokenStream;

use some_cool_crate::macros_lookup;
use some_cool_crate::Macros;

let path_to_another_crates_cargo_toml = "/path/to/another_crate/Cargo.toml";
let macros = Macros {
    name: "my_macro",
    crate: "macro_original_crate",
};

// The thing I'm looking for:
macros_lookup(
    path_to_another_crates_cargo_toml, 
    &macros, 
    |attr: TokenStream, input: TokenStream,| {
        // there I'll do some interesting stuff
    },
);

P.S. Currently I obtain the information from custom section of Cargo.toml's [package.metadata] but it requires me to keep Cargo.toml in sync with the sources.

P.P.S. The reason I'm doing all that "cool" stuff is broken Re-exporting C symbols for cdylib

0

There are 0 answers