Commit Graph

12 Commits

Author SHA1 Message Date
Nicholas Junge 80a3c5e4d9
Switch bindings implementation to `nanobind` (#1526)
* End support for Python 3.7, update cibuildwheel and publish actions

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.

* Add nanobind to the Bazel dependencies, add a BUILD file

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.

* Delete pybind11 BUILD file

* Switch bindings implementation to nanobind

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.

* Use Bazel select for linker options

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)

* Unbreak Windows builds of nanobind-based bindings

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.

* Fall back to `nb::implicitly_convertible` for Counter construction

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.
2023-02-06 13:07:17 +00:00
Nicholas Junge f59d021ebc
Modernize setup.py, extend Python bindings CI (#1535)
distutils is deprecated and will be removed in Python 3.12, so this
commit modernizes the Python bindings `setup.py` file in order to
future-proof the code.

On top of this, type hints were added for all of the convenience
functions to make static type checking adoption easier in the future,
if desired.

A context manager was added to temporarily write the Python include
path to the Bazel WORKSPACE file - but unlike previously, the
WORKSPACE file is reverted to its previous state after the build to not
produce changes on every rebuild.

Lastly, the Python bindings test matrix was extended to all major
platforms to create a more complete picture of the current state of
the bindings, especially with regards to upcoming wheel builds.
2023-02-03 09:47:02 +00:00
Nicholas Junge 4eaa0c896d
Add information for supported Python versions to setup.py (#1502)
Adds qualifiers for Python 3.9-3.11 indicating them being supported in the Python bindings building.

Support for Python 3.6 was removed, so the indicator for Python 3.6 was removed.
2022-10-18 11:23:59 +01:00
Nicholas Junge 6f75bb5273
Shut down Bazel gracefully and revert wheel build strategy to job matrix (#1383)
This commit adds a `bazel shutdown` command to the setuptools BazelExtension. This has the effect that wheel builds shut down the Bazel server and terminate gracefully after the build, something
that was previously an issue on Windows builds.

Since the windows-specific `--no-clean` flag option to `pip wheel` becomes unnecessary due to this change, this change has the side-effect that GitHub Actions wheel builds via `cibuildwheel` can now
be written as a compact job matrix again, which leads to a lot of deduplicated code in the corresponding workflow file.

Lastly, some GitHub-provided actions (checkout, setup-python, upload/download-artifact) were bumped to the latest v3 version.
2022-04-08 15:00:46 +01:00
Nicholas Junge df7749cd09
Add long description and content type for proper PyPI presentation (#1361)
This commit adds the two fields `long_description` and `long_description_content_type` to `setup.py`. These can be used for proper project presentation on the PyPI project page, which is currently a placeholder.
2022-03-08 12:40:14 +00:00
Nicholas Junge 6d51a119ff
Fix cross compilation for macOS ARM builds in `cibuildwheel` (#1334)
This commit contains a fix for macOS ARM64 wheel buils in Google Benchmark's wheel building CI.

Previously, while `cibuildwheel` itself properly identified the need for cross-compilations and produced valid ARM platform wheels, the included shared library containing the Python bindings
built by `bazel` was built for x86, resulting in immediate errors upon import.

To fix this, logic was added to the setup.py file that adds the "--cpu=darwin_arm64" and "--macos_cpus=arm64" switches to the `bazel build` command if
1) The current system platform is macOS Darwin running on the x86_64 architecture, and
2) The ARCHFLAGS environment variable, set by wheel build systems like conda and cibuildwheel, contains the tag "arm64".

This way, bazel correctly sets the target CPU to ARM64, and produces functional wheels for the macOS ARM line of CPUs.
2022-01-26 09:13:26 +00:00
Nicholas Junge a17480dd34
Fix dependency typo and unpin cibuildwheel version in wheel building … (#1263)
* Fix dependency typo and unpin cibuildwheel version in wheel building action

* Move to monolithic build jobs, restrict to x64 architectures

As of this commit, all wheel building jobs complete on GitHub Actions. Since some platform-specific options had to be set to fix different types of build problems underway, the build job matrix was unrolled.

Still left TODO:
* Wheel testing after build (running the Python bindings test)
* Emulating bazel on other architectures to build aarch64/i686/ppc64le
* Enabling Win32 (this fails due to linker errors).

* Add binding test commands for all wheels, set macOSX deployment target to 10.9

* Add instructions for updating Python __version__ variable before release creation
2021-11-11 14:51:22 +00:00
Antoine Prouvost 73d4d5e8d6
Bind benchmark builder to Python (#1040)
* Fix setup.py and reformat

* Bind benchmark

* Add benchmark option to Python

* Add Python examples for range, complexity, and thread

* Remove invalid multithreading in Python

* Bump Python bindings version to 0.2.0

Co-authored-by: Dominic Hamon <dominichamon@users.noreply.github.com>
2020-09-11 10:55:18 +01:00
Dominic Hamon df9e2948fa
Add workflow to exercise bindings (#1041)
* Initial version to try to run python bindings example

* python indent issue in setup.py

* better naming
2020-09-10 16:32:25 +01:00
Dominic Hamon beb360d03e
Create pylint.yml (#1039)
* Create pylint.yml

* improve file matching

* fix some pylint issues

* run on PR and push (force on master only)

* more pylint fixes

* suppress noisy exit code and filter to fatals

* add conan as a dep so the module is importable

* fix lint error on unreachable branch
2020-09-09 09:43:26 +01:00
Chris Jones 39c8d58a76
Rename python bindings package to `google_benchmark`. (#999)
A few people have complained that `benchmark` is too generic. Also, add
Python 3.8.
2020-07-09 09:23:06 +01:00
Chris Jones d3ad0b9d11
Add Python bindings. (#957)
* Add Python bindings.

* Add license headers.

* Change example to a test.

* Add example usage to module docstring.
2020-05-06 17:28:29 +01:00