Overriding build.rs for a c library dependency

My project uses a rust dependency which is based on C/C++ libraries.
The build.rs of this rust dependency compiles the C/C++ libraries and generates the rust bindings.

The compilation of this C/C++ is extremely time and resource consuming.

I would like to embed the pre-compiled libraries in my environment (in particular for continuous integration) to optimize/cache this step.

I was thinking about providing some metadatas in my Cargo configuration this way:


rustc-link-search = ["/xxx/yyy/zzz"]
rustc-link-lib = ["libfoo"]


foo = { version = "x.x.x", rustc-link-lib = ["foo"] }

But I have a failure when I build my project:

No such file or directory (os error 2)
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
3 | include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It makes sense because the build.rs script of foo dependency generates the rust bindings and with my new cargo config the build.rs script is skipped and so the bindings.rs is not generated.

What can I do or request to the dependency maintainers to be able to do that ?


this isn't directly what you asked for, but have you tried ccache? basically it gets added to PATH and so any attempts to run a compiler go through it, where it can cache the output. in my experience, it can make a 5min compile process take a few seconds. just add ccache's cache directory to the CI cache. I also use the content compilercheck value, which makes it check if the source files contain the same data rather than checking based on modification date and size:

export PATH="/usr/lib/ccache:$PATH"
export CCACHE_DIR="path/to/cache/for/ccache"

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.