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

Switch bindings implementation to nanobind #1526

Merged
merged 8 commits into from
Feb 6, 2023

Conversation

nicholasjng
Copy link
Contributor

Title is self-explanatory. This uses nanobind to build Python bindings for Google Benchmark instead of pybind11, with the following consequences:

  • Python 3.7 support is dropped, since nanobind needs PEP590 vectorcalls, first added in Python 3.8.
  • nanobind is checked in as a bazel dep, currently at HEAD instead of a tag, because some features used to generate the GBM binding code have not made it into a release yet.
  • The minimum MacOS version was bumped up to 10.14 (Mojave), to get full C++17 support.

For performance considerations and changes in contrast to the current implementation, see the discussion #1521.

(For reviewers: I am not sure of the options I gave in the nanobind BUILD file - I looked at what compile commands CMake generated in release mode for nanobind and went on from there.)

The bindings now also contain the state name from #1511.

Removes Python 3.7 from the support matrix, since it does not support
PEP590 vectorcalls.

Bumps the `cibuildwheel` and `pypa-publish` actions to their latest
available versions respectively.
The build file builds nanobind as a static `cc_library`. Currently,
the git SHA points to HEAD, since some necessary features have not
been included in a release yet.
Switches over the binding tool to `nanobind` from `pybind11`. Most
changes in the build setup itself were drop-in replacements of existing
code changed to nanobind names, no new concepts needed to be
implemented.

Sets the minimum required macOS to 10.14 for full C++17 support. Also,
to avoid ambiguities in Bazel, build for macOS 11 on Mac ARM64.
Guards against unknown linker option errors by selecting required
linker options for nanobind only on macOS, where they are relevant.

Other changes:
* Bump cibuildwheel action to v2.12.0
* Bump Bazel for aarch64 linux wheels to 6.0.0
* Remove C++17 flag from build files since it is present in setup.py `bazel build` command
* Bump nanobind commit to current HEAD (TBD: Bump to next stable release)
dmah42
dmah42 previously approved these changes Jan 30, 2023
@nicholasjng
Copy link
Contributor Author

Hmm, I guess I need to pass the copts to nanobind via a select as well. The cxxopt for C++17 is different as well on Windows, I will get to it asap.

Guards compiler options behind a new `select` macro choosing between
MSVC and not MSVC.

Other changes:
* Inject the proper C++17 standard cxxopt in the `setup.py` build
command.
* Bump nanobind to current HEAD.
* Make `macos` a benchmark-wide condition, with public visibility to
allow its use in the nanobind BUILD file.
Since `benchmark::Counter` only has a constructor for `double`,
the nanobind `nb::init_implicit` template cannot be used. Therefore,
to support implicit construction from ints, we fall back to the
`nb::implicitly_convertible` template instead.
@nicholasjng
Copy link
Contributor Author

I fixed the MSVC breakage, which was due to (my) user error. Should be good to go now, binding test matrix is all green, other failures are due a downed apt mirror presumably.

If you want, I can restructure the PR and split it up (e.g. carving out the CI parts), to make it easier to revert to pybind11 in the event, without touching the other changes here. Let me know what you think.

@dmah42 dmah42 merged commit 80a3c5e into google:main Feb 6, 2023
@dmah42
Copy link
Member

dmah42 commented Feb 6, 2023

thank you!

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.

2 participants