Skip to content

Commit

Permalink
Upgrade google/benchmark to use nanobind-bazel v2.0.0
Browse files Browse the repository at this point in the history
This enables binding extension builds with nanobind@v2.

Due to some backwards-incompatible changes in the treatment of enums,
`Counter::Flags` (a flag-based enum) needs to be explicitly marked as
arithmetic; setting flags is done as before with the logical "or"
operator (now bound like any other class method as `__or__()`, the
Python logical or operator slot).

The bindings changes were suggested by @hawkinsp in the corresponding
issue on the repo, see google#1790.
  • Loading branch information
nicholasjng committed May 29, 2024
1 parent 7f0e99a commit 7eb18fa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ use_repo(pip, "tools_pip_deps")

# -- bazel_dep definitions -- #

bazel_dep(name = "nanobind_bazel", version = "1.0.0", dev_dependency = True)
bazel_dep(name = "nanobind_bazel", version = "2.0.0", dev_dependency = True)
4 changes: 2 additions & 2 deletions bindings/python/google_benchmark/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ NB_MODULE(_benchmark, m) {
using benchmark::Counter;
nb::class_<Counter> py_counter(m, "Counter");

nb::enum_<Counter::Flags>(py_counter, "Flags")
nb::enum_<Counter::Flags>(py_counter, "Flags", nb::is_arithmetic())
.value("kDefaults", Counter::Flags::kDefaults)
.value("kIsRate", Counter::Flags::kIsRate)
.value("kAvgThreads", Counter::Flags::kAvgThreads)
Expand All @@ -130,7 +130,7 @@ NB_MODULE(_benchmark, m) {
.value("kAvgIterationsRate", Counter::Flags::kAvgIterationsRate)
.value("kInvert", Counter::Flags::kInvert)
.export_values()
.def(nb::self | nb::self);
.def("__or__", [](Counter::Flags a, Counter::Flags b) { return a | b; });

nb::enum_<Counter::OneK>(py_counter, "OneK")
.value("kIs1000", Counter::OneK::kIs1000)
Expand Down

0 comments on commit 7eb18fa

Please sign in to comment.