Skip to content

Commit eb15fc8

Browse files
authored
Introduce Rust bindings (#2221)
* add Rust bindings * clang-format * pre-commit fix * windows static builds * Rust prefers MD on windows * check in lock file to avoid source poisoning * use a rust crate name that isn't taken * add CMake target for running Rust binding tests and integrate into CI * complete crate rename * enable test dependency downloads in Rust bindings CI
1 parent 1b3abc8 commit eb15fc8

13 files changed

Lines changed: 542 additions & 3 deletions

File tree

.github/workflows/test_bindings.yml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ permissions:
1414

1515
jobs:
1616
python_bindings:
17-
name: Test GBM Python ${{ matrix.python-version }} bindings on ${{ matrix.os }}
17+
name: Test Python ${{ matrix.python-version }} bindings on ${{ matrix.os }}
1818
runs-on: ${{ matrix.os }}
1919
strategy:
2020
fail-fast: false
@@ -30,7 +30,31 @@ jobs:
3030
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
3131
with:
3232
python-version: ${{ matrix.python-version }}
33-
- name: Install GBM Python bindings on ${{ matrix.os }}
33+
- name: Install Python bindings on ${{ matrix.os }}
3434
run: python -m pip install .
3535
- name: Run example on ${{ matrix.os }} under Python ${{ matrix.python-version }}
3636
run: python bindings/python/google_benchmark/example.py
37+
38+
rust_bindings:
39+
name: Test Rust bindings on ${{ matrix.os }}
40+
runs-on: ${{ matrix.os }}
41+
strategy:
42+
fail-fast: false
43+
matrix:
44+
os: [ ubuntu-latest, macos-latest, windows-latest ]
45+
steps:
46+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
47+
with:
48+
fetch-depth: 0
49+
- name: Install Rust toolchain
50+
uses: dtolnay/rust-toolchain@stable
51+
- name: Install Ninja (macOS)
52+
if: runner.os == 'macOS'
53+
run: brew install ninja
54+
- name: Run Rust tests natively via Cargo
55+
run: cargo test
56+
working-directory: bindings/rust
57+
- name: Run Rust tests via CMake target
58+
run: |
59+
cmake -S . -B build -DBENCHMARK_ENABLE_RUST_BINDINGS=ON -DBENCHMARK_DOWNLOAD_DEPENDENCIES=ON
60+
cmake --build build --target test_rust_bindings

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,6 @@ CMakeSettings.json
6767
dist/
6868
*.egg-info*
6969
uv.lock
70+
71+
# Rust build stuff
72+
/bindings/rust/target/

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ option(BENCHMARK_ENABLE_GTEST_TESTS "Enable building the unit tests which depend
4141
option(BENCHMARK_USE_BUNDLED_GTEST "Use bundled GoogleTest. If disabled, the find_package(GTest) will be used." ON)
4242

4343
option(BENCHMARK_ENABLE_LIBPFM "Enable performance counters provided by libpfm" OFF)
44+
option(BENCHMARK_ENABLE_RUST_BINDINGS "Enable testing of the Rust bindings" OFF)
4445

4546
# Export only public symbols
4647
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

bindings/rust/Cargo.lock

Lines changed: 301 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/rust/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "google-benchmark-rs"
3+
version = "1.9.5"
4+
edition = "2021"
5+
description = "Rust bindings for google/benchmark"
6+
license = "Apache-2.0"
7+
8+
[dependencies]
9+
cxx = "1.0"
10+
11+
[build-dependencies]
12+
cmake = "0.1"
13+
cxx-build = "1.0"

0 commit comments

Comments
 (0)