I am building a Rust crate that has transitive dependencies on a few *-sys
crates wrapping native libraries. The *-sys
crates use build.rs
to build the native libraries with cmake, which is not supported in my environment.
I already have those native libraries prebuilt elsewhere in my project tree. I would like to override the build scripts to not run, and use the existing native libraries instead.
If a manifest contains a links key, then Cargo supports overriding the build script specified with a custom library. The purpose of this functionality is to prevent running the build script in question altogether and instead supply the metadata ahead of time.
To override a build script, place the following configuration in any acceptable Cargo configuration location.
[target.x86_64-unknown-linux-gnu.foo] rustc-link-search = ["/path/to/foo"] rustc-link-lib = ["foo"] root = "/path/to/foo" key = "value"
Source: Cargo Reference > Build Scripts
My initial guess based on that documentation is that I would just need to add rustc-link-lib
when declaring the dependency, but this doesn't seem to work.
[package]
# ...
[dependencies]
# ...
harfbuzz-sys = { version = "0.3", rustc-link-lib = ["harfbuzz"] }
# ...
Cargo still tries to invoke build.rs
and fails.
Is there a correct way to override harfbuzz-sys
's build.rs
for all of its transitive dependents in my project?