Cargo depending on rust library without providing source code



I have a compiled rust library which I would like to use as a dependency in a Cargo project without providing the source code of that library. How can I build the executable in Cargo which depends on my library? Any example please?


Fairly certain this isn’t supported.

Even if it was supported by Cargo, you’d run into a more fundamental problem: Rust doesn’t have a stable ABI, and every version of the compiler technically uses a different set of libraries. So you could compile a binary, but it would only work with one specific version of the compiler.

The only way around this is to treat your Rust library as a C library… at which point, you expose it to Cargo like any other C library: by writing a binding for it and using a build script to manage linkage.


If what you mean is that you only don’t want to have the code for the library somewhere public (likes, you might try using GIT dependencies from a private git repository:

However from your message it doesn’t seem all that likely this is what you’re looking for.


You should be able to add a build script that would link it in, I’d think.

That said, @DanielKeep’s points are very relevant.

This won’t work, as Cargo will place a copy of the code on your hard drive.