I'm developing cargo-nix, which builds Rust binaries using Nix.
I've completed implementing the minimal functionality and tried it with several crates.
I found out that some crates, like ripgrep and bat, can be built with cargo-nix, while others cannot.
I want to test cargo-nix on popular crates.
How can I get the list of binary crates and the number of downloads from crates.io?
I seriously doubt you actually can get that kind of information. Because I don't think anyone defined what a binary crate actually is. For example:
You can have a crate that has src/main.rs. This is likely a binary crate.
But you can also have multiple binaries in there.
You can have a crate that has both src/lib.rs and src/main.rs. It can serve only as a library onto itself, it can be a hybrid that can be used as a library or binary or the binary is just some useless devel thing.
Arguably, you could want to use something from the examples directory of that crate, because these are in a way binaries.
So you might develop some kind of your own heuristic on what crate you consider to be a binary crate and what not. But the list of files is probably not available in the metadata, you'd need to download the sources first to check.
I'd assume that the criterion is, in fact, rather simple: binary crate is the one which can be installed with cargo install. The question is, how does Cargo check whether it is possible or not.
FWIW, I'll normally write my executable as src/bin/main.rs so you don't open src/ and get confused by the presence of both a lib.rs and a main.rs.
A better method would be to use cargo as a library. Then you can use implementors of the Source trait to fetch packages (probably with their RegistrySource) and inspect each of the Targets in the Package to see if it includes binaries (probably with Target::is_bin()).
That would probably involve downloading the source code for each package, though. Source distributions from crates.io aren't normally that big, but I imagine it'll add up if you are trying to check every package in the registry.