Skip to content

python: use pkg-config to discover re2 link flags for static builds - #652

Open
mikedep333 wants to merge 1 commit into
google:mainfrom
mikedep333:setup-py-pkg-config
Open

python: use pkg-config to discover re2 link flags for static builds#652
mikedep333 wants to merge 1 commit into
google:mainfrom
mikedep333:setup-py-pkg-config

Conversation

@mikedep333

Copy link
Copy Markdown

Summary

When building google-re2 from source using the setuptools fallback path (i.e. without Bazel / outside of GitHub Actions), the resulting _re2.so extension 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:

>>> import re2
ImportError: /path/to/re2/_re2.cpython-312-x86_64-linux-gnu.so:
  undefined symbol: _ZN4absl12lts_2025051218container_internal19GetRefForEmptyClassERNS1_12CommonFieldsE

Root cause

setup.py hardcodes libraries=['re2']. This works when linking against a shared libre2.so (the dynamic linker resolves the abseil dependency chain at runtime), but when libre2.a is the only available library (static build via CMake with -DBUILD_SHARED_LIBS=OFF), the linker never sees the abseil archives that libre2.a depends on.

Fix

Use pkg-config --libs --static re2 to discover re2's transitive dependencies (abseil), falling back to the current libraries=['re2'] when pkg-config is unavailable. The CMake install already produces re2.pc with Requires: 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.pc is 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

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>
@google-cla

google-cla Bot commented Jul 29, 2026

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

setup.py: setuptools fallback does not link abseil when building against static libre2.a

1 participant