Can I use cargo install to distribute a binary built by build.rs?

Viewed 309

Background

I have a crate that provides a CLI tool with subcommands, much like cargo itself. For example, running

tool subcommand arg1 arg2 arg3

would look for an executable called tool-subcommand on the user's PATH and run it like this:

tool-subcommand subcommand arg1 arg2 arg3

tool is implemented in src/main.rs, and I have some subcommands defined:

  • tool-foo lives in src/bin/foo.rs
  • tool-bar lives in src/bin/bar.rs

Each has a [[bin]] entry in my Cargo.toml.

When I run cargo install, all of them are installed in ~/.cargo/bin as expected.


Question

There's an executable written in C that lives in another repo. I can build it using build.rs, producing a binary called tool-baz. I'd like cargo install to build/install that for my users too.

Unfortunately, I can't find a way to point Cargo at binaries created by build.rs. I could make a custom static library build target for the C executable, wrap it in a Rust shim and distribute that, but that's both messy and a pain.

Am I missing something? Thanks!

0 Answers
Related