Make path to pre-built version of librdkafka more flexible #788
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sister PR to #787.
The build script currently expects a very specific filesystem layout in order to statically link. If you check out the source code for librdkafka somewhere and compile it with
./configure
andmake
, the build artifacts will exist in thesrc/
directory under the project directory and everything will work. The rdkafka-sys crate does something similar behind the scenes by default.However, sometimes we already have librdkafka built for us. For example, when installed via a package manager like Homebrew or APT, we will have the build artifacts available somewhere like
/opt/homebrew/lib
or/usr/lib/aarch64-linux-gnu
. In those cases, the automatic appending ofsrc/
to the path inDEP_LIBRDKAFKA_STATIC_ROOT
is problematic.Taking a page from jemallocator1, another Rust crate that wraps a C/C++ library, we can instead accept a path to the static library file and pass its parent (the directory in which it resides) to
cargo:rustc-link-search
. This supports both the case where we have the library installed via a package manager (by settingDEP_LIBRDKAFKA_STATIC_ROOT
to something like/opt/homebrew/lib/librdkafka.a
) and the case where we're building from source ourselves (by pointing to something like~/Downloads/librdkafka/src/librdkafka.a
).Footnotes
https://github.com/tikv/jemallocator/blob/5c5a9f79b3be3c19e253527f16a091132a455c2e/jemalloc-sys/build.rs#L126-L137 ↩