Add pre-commit config and GitHub Actions job (#1688)
* Add pre-commit config and GitHub Actions job
Contains the following hooks:
* buildifier - for formatting and linting Bazel files.
* mypy, ruff, isort, black - for Python typechecking, import hygiene,
static analysis, and formatting.
The pylint CI job was changed to be a pre-commit CI job, where pre-commit
is bootstrapped via Python.
Pylint is currently no longer part of the
code checks, but can be re-added if requested. The reason to drop was
that it does not play nicely with pre-commit, and lots of its
functionality and responsibilities are actually covered in ruff.
* Add dev extra to pyproject.toml for development installs
* Clarify that pre-commit contains only Python and Bazel hooks
* Add one-line docstrings to Bazel modules
* Apply buildifier pre-commit fixes to Bazel files
* Apply pre-commit fixes to Python files
* Supply --profile=black to isort to prevent conflicts
* Fix nanobind build file formatting
* Add tooling configs to `pyproject.toml`
In particular, set line length 80 for all Python files.
* Reformat all Python files to line length 80, fix return type annotations
Also ignores the `tools/compare.py` and `tools/gbench/report.py` files
for mypy, since they emit a barrage of errors which we can deal with
later. The errors are mostly related to dynamic classmethod definition.
2023-10-30 23:35:37 +08:00
|
|
|
load("@bazel_skylib//lib:selects.bzl", "selects")
|
|
|
|
|
2023-10-24 20:04:12 +08:00
|
|
|
licenses(["notice"])
|
|
|
|
|
|
|
|
package(default_visibility = ["//visibility:public"])
|
|
|
|
|
2023-10-25 19:12:18 +08:00
|
|
|
config_setting(
|
|
|
|
name = "msvc_compiler",
|
|
|
|
flag_values = {"@bazel_tools//tools/cpp:compiler": "msvc-cl"},
|
2023-10-24 20:04:12 +08:00
|
|
|
)
|
|
|
|
|
2023-10-27 19:49:43 +08:00
|
|
|
selects.config_setting_group(
|
|
|
|
name = "winplusmsvc",
|
|
|
|
match_all = [
|
|
|
|
"@platforms//os:windows",
|
|
|
|
":msvc_compiler",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
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 21:07:17 +08:00
|
|
|
cc_library(
|
|
|
|
name = "nanobind",
|
2023-07-17 22:28:35 +08:00
|
|
|
srcs = glob([
|
2023-10-25 19:12:18 +08:00
|
|
|
"src/*.cpp",
|
2023-07-17 22:28:35 +08:00
|
|
|
]),
|
2023-10-25 19:12:18 +08:00
|
|
|
additional_linker_inputs = select({
|
|
|
|
"@platforms//os:macos": [":cmake/darwin-ld-cpython.sym"],
|
|
|
|
"//conditions:default": [],
|
|
|
|
}),
|
|
|
|
copts = select({
|
|
|
|
":msvc_compiler": [
|
|
|
|
"/EHsc", # exceptions
|
|
|
|
"/Os", # size optimizations
|
2023-10-27 19:49:43 +08:00
|
|
|
"/GL", # LTO / whole program optimization
|
2023-10-25 19:12:18 +08:00
|
|
|
],
|
|
|
|
# these should work on both clang and gcc.
|
|
|
|
"//conditions:default": [
|
|
|
|
"-fexceptions",
|
|
|
|
"-flto",
|
|
|
|
"-Os",
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
includes = [
|
|
|
|
"ext/robin_map/include",
|
|
|
|
"include",
|
|
|
|
],
|
|
|
|
linkopts = select({
|
2023-10-27 19:49:43 +08:00
|
|
|
":winplusmsvc": ["/LTGC"], # Windows + MSVC.
|
|
|
|
"@platforms//os:macos": ["-Wl,@$(location :cmake/darwin-ld-cpython.sym)"], # Apple.
|
2023-10-25 19:12:18 +08:00
|
|
|
"//conditions:default": [],
|
|
|
|
}),
|
2023-07-17 22:28:35 +08:00
|
|
|
textual_hdrs = glob(
|
|
|
|
[
|
|
|
|
"include/**/*.h",
|
|
|
|
"src/*.h",
|
|
|
|
"ext/robin_map/include/tsl/*.h",
|
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 21:07:17 +08:00
|
|
|
],
|
|
|
|
),
|
|
|
|
deps = ["@python_headers"],
|
|
|
|
)
|