Getting all sources for a particular target?

Hi all,

I’m looking to get the complete list of source (ie module and include*!) files used to build a particular target. At the moment, cargo metadata only includes the top-level source file.

rustc has the --emit deps-info option, and which cargo uses when it invokes rustc. But I couldn’t see a way to access that information (it wasn’t actually obvious to me that it uses it).

Is there some existing extension which provides this information? Or alternatively, would it make sense to extend the metadata json to include it? Or is there some fundamental reason why this wouldn’t work?

(Background: my goal is to write a tool which can take a Cargo.toml and generate build rules for a different build system, which needs all input files to be explicitly listed.)

You can’t do that in cargo metadata because you need to fully build code to get this information.

So the solution here is to run cargo build and fetch depinfo files manually from the target dir. There maybe a chance that passing —message-format=json to cargo build will output path to depinfo, but I am not sure about that.

Have you looked into the build-plan unstable feature?

1 Like

Ah, thanks for the pointer. I knew it was an area of investigation, but I wasn’t aware of how far it had got.

That’s exactly what I’m looking for, but it doesn’t have the complete sources list. I’ll look into adding it.

dep-info is written in Make-compatible format to *.d files in the target directory.

Yeah, I meant via cargo rather than reaching around.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.