Can I distribute a pre-built C executable dependency with Cargo install?

I'm working on a CLI tool that (among other functions) will provide an ergonomic user interface wrapper around an existing C executable. I'm trying to figure out how I can get my crate's binary and the C executable to be distributed via cargo install.

So far, I have:

  • Add the C tool's git repository to my crate as a git submodule.
  • Create a build.rs build script that uses the cmake library to build the C tool when I run cargo build.
  • Configure a [[bin]] target for my wrapper executable.

Naturally, running cargo install installs the wrapper exe, but not the C tool. My read of the cargo install docs tells me that the only way I can install an executable is for it to be the result of building a Rust source file.

Is there a workaround for this? Thanks!

build.rs is a bit of a hack, but it is capable of doing arbitrary things like installing precompiled libraries on the system. I don't necessarily recommend this, but it is an option.

Another option is using a separate build system in conjunction with cargo. There are a few "task runner" applications like just and cargo-make which try to fill that void.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.