Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension modules fail to build #98

Open
code-clash opened this issue May 15, 2024 · 1 comment
Open

Extension modules fail to build #98

code-clash opened this issue May 15, 2024 · 1 comment

Comments

@code-clash
Copy link

While trying to use a package with extension modules (py-radix in particular), I'm seeing the following error (repro fork):

../bin/clang -shared -Wl,-S -mmacos-version-min=10.11 -no-canonical-prefixes -fobjc-link-runtime -headerpad_max_install_names -lc++ -lm -L../lib build/temp.macosx-11.0-arm64-cpython-311/radix/_radix.o build/temp.macosx-11.0-arm64-cpython-311/radix/_radix/radix.o -o build/lib.macosx-11.0-arm64-cpython-311/radix/_radix.cpython-311-darwin.so
Undefined symbols for architecture arm64:
  "_PyArg_ParseTuple", referenced from:
      _Radix_nodes in _radix.o
      _Radix_prefixes in _radix.o
      _radix_Radix in _radix.o
  "_PyArg_ParseTupleAndKeywords", referenced from:
      _Radix_add in _radix.o
      _Radix_delete in _radix.o
      _Radix_search_exact in _radix.o
      _Radix_search_best in _radix.o
      _Radix_search_worst in _radix.o
      _Radix_search_covered in _radix.o
      _Radix_search_covering in _radix.o
      ...
  "_PyBytes_FromStringAndSize", referenced from:
      _newRadixNodeObject in _radix.o
  "_PyDict_GetItemString", referenced from:
      _module_initialize in _radix.o
<<<OTHER SYMBOLS>>>
ld: symbol(s) not found for architecture arm64

It looks like the python library is missing from the libs, so I tried using pycross_wheel_build with native_deps = ["@rules_python//python/cc:current_py_cc_libs"], but that seems to break even earlier due to wrong includes.

Any ideas on how this can be made to work? Thanks!

@jvolkman
Copy link
Owner

This looks related to bazelbuild/bazel#16414.

Bazel used to pass -undefined dynamic_lookup by default when linking on macos, but this was removed. py-radix builds on my machine with

bazel build @pdm_deps//:py-radix --linkopt='-undefined dynamic_lookup'

Note, I also had to include the following in the example MODULE.bazel because pycross defaults to 12.0, which may be another issue

pycross = use_extension("@rules_pycross//pycross/extensions:pycross.bzl", "pycross")
pycross.configure_environments(
    macos_version="14.0",    
)

Most of the examples and tests in this codebase utilize https://github.com/uber/hermetic_cc_toolchain which still passes -undefined dynamic_lookup by default. I think that linkopt is basically always required when building macos extensions, so I'll have to figure out how to best have it included.

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

No branches or pull requests

2 participants