-
Notifications
You must be signed in to change notification settings - Fork 35
Description
It's a somewhat established convention for -sys crates to expose a cargo::metadata=include=path/to/dir metadata. Say you're creating a sys crate for a C library that requires mbedtls.
Instead of building or sourcing a separate copy of mbedtls, it's much nicer to add the mbedtls-rs-sys crate as a dependency, which then gives you access to the exposed include dir metadata in the build script.
See for example the openssl-sys crate: https://github.com/rust-openssl/rust-openssl/blob/87bf0e2e364976453fd6ae335f9c5ff34a314244/openssl-sys/build/main.rs#L214
This came up while I was hacking around on the openthread crate. Since openthread requires mbedtls I wanted it to use this crate. See:
https://github.com/inomotech-foss/openthread/blob/556e76558d68f676d65ae8d98a1f902e75f8dcc3/openthread-sys/gen/builder.rs#L434-L435
Small tangent: The dep_metadata function is from build-rs, which provides a clean interface around the build script protocol and is maintained by the Cargo team. Of course there's always the trade-off of compile times, but IMO that's entirely offset by how much more readable the build scripts are.