Cargo depending on rust library without providing source code


#1

Hi

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?


#2

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.


#3

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

http://doc.crates.io/specifying-dependencies.html#specifying-dependencies-from-git-repositories

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


#4

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.