BCP/example for binding using system or vendored dependency


I want to bind a C library for rust. The full version is rather big, so I would like to use a system copy by default if available, but fall back to a slightly cut-down vendored version if it is not possible or the user does not want it (e.g. on Windows)?

What is the best current practice for something like that? Are there any crates that I could use as examples?


I’ve done that: https://github.com/pornel/rust-libpng-sys & https://github.com/pornel/rust-lcms2-sys

For building the C code you could call the original build system via std::process::Command (and there are even crates like cmake-rs to ease some cross-platform headaches).

I ended up ignoring the original build system using the cc crate instead to just compile a bunch of C files together. Surprisingly, it turned out just fine, and works better on Windows this way.


Thanks. I’ll probably need to do a similar feature dance.

Yes, I’ll probably also just use cc, because the original build system would be Pain™ on Windows (it’s make-based, so needs cygwin or msys and I don’t want to impose that).


… for me the disadvantage of always including the vendored copy is that it is rather big. The complete data bundle is ~29 MiB. 9 MiB of it I can probably drop without regret, but the rest, I can’t. And then if I want to have option to strip it further, I’ll have to build the C code for host too…