nicholasjng / nanobind-bazel

Bazel defs and rules for building Python projects with nanobind extensions.
Apache License 2.0
6 stars 0 forks source link

Implement stable ABI builds #5

Closed nicholasjng closed 6 months ago

nicholasjng commented 7 months ago

Still in progress, the extension name is not correct yet (needs to be .abi3.so in the SABI case).

However, I'm not sure how this is solvable elegantly outside of a completely custom rule implementation for nanobind_extension.

Usage:

bazel build //src:my_ext --@rules_python//python/config_settings:python_version=$MAJOR.$MINOR[.$PATCH] --@nanobind_bazel//:py-limited-api=cp312

Currently only cp312 and cp313 are supported as targetable Python ABI versions.

nicholasjng commented 7 months ago

@wjakob Could you explain why only CPython>=3.12 is supported for nanobind SABI builds? The oldest Python ABI selectable is 3.2 (with -DPy_LIMITED_API=0x03020000), is the constraint due to a nanobind implementation detail?

wjakob commented 7 months ago

Because nanobind depends on functionality that hasn't become part of the SABI until 3.12.

nicholasjng commented 6 months ago

Summary:

  1. The new alias produces the correctly named .abi3.so file in the stable ABI case.
  2. The produced nanobind_example wheel is SABI 3.12 compliant, tested with python -m abi3audit dist/nanobind_example_..._.whl.
  3. I have not managed to build wheels with the correct cp312-abi3 tag with either python -m build or python -m pip wheel, only using the legacy python setup.py bdist_wheel --py-limited-api=cp312. This is no doubt my own issue, and should be configurable in the former frontends as well. (Curiously, -C--py-limited-api=cp312 does nothing.)

I'm going to merge this for now, and restructure the settings into a helper later.