Commit Graph

21 Commits

Author SHA1 Message Date
Nicholas Junge 754ef08ab9
Upgrade core bazel dependencies (#1711)
Bumps `rules_foreign_cc` to v0.10.1 (October 2023), `bazel_skylib` to
v1.5.0 (November 2023), `rules_python` to v0.27.1 (December 2023).

Also syncs GoogleTest to v1.12.1 (the last C++11 supporting version) to
be the same as in MODULE.bazel.

Since the latest `rules_python` changed its setup calling convention,
that is updated also in the WORKSPACE file.
2023-12-07 15:00:43 +00:00
Nicholas Junge b93f5a5929
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 15:35:37 +00:00
Andy Christiansen aacf2b1af9
Add support for bzlmod (excluding Python bindings) (#1615)
* Migrate to bzlmod

* Update Python version to PY3, as indicated by the actual source file.

* Migrate more libraries & first draft of direct pywheel rule usage in Bazel

* Integrate with nanobind and libpfm

* Make Python toolchain a dev dependency

* Undo py_wheel usage until later

* Added support for bzlmod for C++ parts of google_benchmark.

* Make //tools:all buildable with --enable_bzlmod

---------

Co-authored-by: Andy Christiansen <achristiansen@google.com>
2023-06-27 13:03:39 +01: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 dfd2ae520a
Add a `benchmark_deps.bzl` function to Google Benchmark (#1520)
* Add `benchmark_workspace.bzl` function

This commit adds a `benchmark_workspace.bzl` function to Google
Benchmark. It is intended to be used as a means to pull in Google
Benchmark's build dependencies in its own Bazel workspace, as well
as in workspaces of downstream projects.

* Migrate WORKSPACE to use the newly created benchmark_deps.bzl

This commit changes Google Benchmark's own WORKSPACE to use the newly
created `benchmark_deps.bzl` function.
2022-12-19 11:12:32 +00:00
Raghu Raja 398a8ac2e8
[bazel] Build libpfm as a dependency to allow collection of perf counters (#1408)
* Build libpfm as a dependency to allow collection of perf counters

This commit builds libpfm using rules_foreign_cc and lets the default
build of the benchmark library support perf counter collection without
needing additional work from users.

Tested with a custom target:

```
bazel run \
        --override_repository=com_github_google_benchmark=/home/raghu/benchmark \
        -c opt :test-bench -- "--benchmark_perf_counters=INSTRUCTIONS,CYCLES"
Using profile: local

<snip>

----------------------------------------------------------------------
Benchmark            Time             CPU   Iterations UserCounters...
----------------------------------------------------------------------
BM_Test      0.279 ns        0.279 ns   1000000000 CYCLES=1.00888 INSTRUCTIONS=2

```

Signed-off-by: Raghu Raja <raghu@enfabrica.net>

* Adding myself to the CONTRIBUTORS file per CLA guidance

Enfabrica has already signed a corporate CLA.

Signed-off-by: Raghu Raja <raghu@enfabrica.net>

Signed-off-by: Raghu Raja <raghu@enfabrica.net>
2022-10-31 11:03:59 +00:00
Nicholas Junge 9265511257
Bump pybind11 version to enable Python 3.11 wheel builds (#1489)
This commit bumps the pybind11 version to 2.10.0, which is the first
pybind version coming with Python 3.11 support. This change is necessary
to facilitate wheel builds for Python 3.11 and upward, as changes to
Python internals in 3.11 broke compatibility with older pybind11
versions.

Co-authored-by: Dominic Hamon <dominichamon@users.noreply.github.com>
2022-09-13 15:01:46 +01:00
Paul Wankadia 7cb2914292
@platforms is magical; remove it from WORKSPACE. (#1356) 2022-02-24 15:06:45 +00:00
Paul Wankadia e057a7cee2
Make generate_export_header.bzl work for Windows. (#1355)
* Make generate_export_header.bzl work for Windows.

While I'm here, bring the generated code slightly closer to what CMake
would generate nowadays.

Fixes #1351.

* Fix define.

* Fix export_import_condition.

* Fix guard.
2022-02-24 14:42:59 +00:00
Dominic Hamon 1f99405076
update googletest to latest release tag 1.11.0 (#1301)
* update googletest to latest release tag 1.11.0

* fix cmake builds to the same release
2021-12-08 16:30:03 +00:00
Teodor Spæren 8401429e74
Remove bazelbuild/rules_cc dependency (#1283)
It seems according to [1] that bazelbuild/rules_cc has been put on hold
and that the recommended way for now, is to use the native cc rules.

[1]: https://github.com/bazelbuild/rules_go/pull/2950
2021-11-14 12:02:58 +00:00
Dominic Hamon bf585a2789 Fix some bazel warnings about missing sha256 on http_archives 2020-11-26 11:14:03 +00:00
Alexander 348aa2c964
bazel support for tools (#982)
* packages versions updated to be in sync with modern python versions
2020-11-06 09:10:04 +00:00
Yesudeep Mangalapilly 4751550871
Revert previous linker additions for FreeBSD as the problem is Bazel using /usr/bin/clang instead of /usr/bin/clang++ to link C++ code. (#1035) 2020-09-03 10:59:15 +01:00
Yesudeep Mangalapilly 4475ff6b8a
Adds -lm linker flag for FreeBSD/OpenBSD and uses github.com/bazelbuil… (#1032)
* Adds -lm linker flag for (Free|Open)BSD and uses github.com/bazelbuild/platforms for platform detection.

* Prefer selects.with_or to select the linkopts.

* @platforms appears to be implicitly available. @bazel_skylib would require updating every dependent repository.

* Re-enable platforms package.
2020-08-28 08:46:12 +01:00
Dominic Hamon 74b4612c73 Add absl dependency as needed 2020-06-08 15:21:52 +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
Paul Wankadia 309de5988e Switch to Starlark for C++ rules. (#887)
While I'm here, format all of the files that I touched.
2019-10-08 11:09:51 +01:00
Dominic Hamon c5b2fe9357
Load http_archive for bazel build 2019-04-09 13:02:45 +01:00
Alex Strelnikov 62a9d756ea Update bazel WORKSPACE and BUILD files to work better on Windows. (#581)
Note, bazel only supports MSVC on Windows, and not MinGW, so
linking against shlwapi.lib only needs to follow MSVC conventions.

git_repository() did not work in local testing, so is swapped for
http_archive(). The latter is also documented as the preferred way
to depend on an external library in bazel.
2018-05-02 11:23:18 +01:00
jmillikin-stripe a9beffda0b Add support for building with Bazel. (#533)
* Add myself to CONTRIBUTORS under the corp CLA for Stripe, Inc.

* Add support for building with Bazel.

Limitations compared to existing CMake rules:
* Defaults to using C++11 `<regex>`, with an override via Bazel flag
  `--define` of `google_benchmark.have_regex`. The TravisCI config sets
  the regex implementation to `posix` because it uses ancient compilers.
* Debug vs Opt mode can't be set per test. TravisCI runs all the tests
  in debug mode to satisfy `diagnostics_test`, which depends on `CHECK`
  being live.

* Set Bazel workspace name so other repos can refer to it by stable name.

This is recommended by the Bazel style guide to avoid each dependent
workspace defining its own name for the dependency.
2018-03-08 12:48:46 +00:00