python: use pkg-config to discover re2 link flags for static builds - #652
Open
mikedep333 wants to merge 1 commit into
Open
python: use pkg-config to discover re2 link flags for static builds#652mikedep333 wants to merge 1 commit into
mikedep333 wants to merge 1 commit into
Conversation
When re2 is installed as a static library (e.g. built via CMake with -DBUILD_SHARED_LIBS=OFF), its transitive dependencies such as abseil-cpp must also appear on the link line. The setuptools fallback path hardcodes libraries=['re2'], which works for shared-library installs (the dynamic linker resolves the chain) but leaves abseil symbols unresolved for static builds. Use pkg-config --libs --static re2 to discover the full set of link flags, falling back to the current behaviour when pkg-config is not available or re2.pc is not installed. Fixes google#651 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Mike DePaulo <mikedep333@redhat.com>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
When building
google-re2from source using the setuptools fallback path (i.e. without Bazel / outside of GitHub Actions), the resulting_re2.soextension has unresolved abseil symbols if re2 was installed as a static library. The wheel builds successfully (shared library builds allow undefined symbols by default), but crashes at import time:Root cause
setup.pyhardcodeslibraries=['re2']. This works when linking against a sharedlibre2.so(the dynamic linker resolves the abseil dependency chain at runtime), but whenlibre2.ais the only available library (static build via CMake with-DBUILD_SHARED_LIBS=OFF), the linker never sees the abseil archives thatlibre2.adepends on.Fix
Use
pkg-config --libs --static re2to discover re2's transitive dependencies (abseil), falling back to the currentlibraries=['re2']when pkg-config is unavailable. The CMake install already producesre2.pcwithRequires: absl_..., so pkg-config can resolve the full dependency chain.This has no effect on the Bazel build path (GitHub Actions), and is backward-compatible: when pkg-config is not installed or
re2.pcis absent, the behaviour is unchanged.Context
We encountered this while building wheels for architectures where Bazel is not available (s390x, ppc64le), using CMake + setuptools as a fallback.
Fixes #651