Skip to content

Commit 19f5244

Browse files
committed
fix(codspeed): replace bindgen with manual bindings
1 parent 27c0199 commit 19f5244

File tree

7 files changed

+89
-107
lines changed

7 files changed

+89
-107
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ jobs:
2121
with:
2222
extra_args: --all-files
2323

24+
- uses: taiki-e/install-action@v2
25+
with:
26+
tool: bindgen-cli@0.72.1
27+
- name: Check if bindings are up-to-date
28+
working-directory: crates/codspeed/src/instrument_hooks
29+
run: |
30+
./update-bindings.sh
31+
32+
if ! git diff --exit-code bindings.rs; then
33+
echo "Error: FFI bindings are out of date!"
34+
exit 1
35+
fi
36+
2437
test-codspeed:
2538
strategy:
2639
matrix:

Cargo.lock

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

crates/codspeed/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,4 @@ harness = false
3636
tempfile = { workspace = true }
3737

3838
[build-dependencies]
39-
bindgen = "0.72.1"
4039
cc = "1.0"

crates/codspeed/build.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::{env, path::PathBuf};
2-
31
fn main() {
42
println!("cargo:rerun-if-changed=instrument-hooks/dist/core.c");
53
println!("cargo:rerun-if-changed=instrument-hooks/includes/core.h");
@@ -29,18 +27,4 @@ fn main() {
2927

3028
std::process::exit(1);
3129
}
32-
33-
let bindings = bindgen::Builder::default()
34-
.header("instrument-hooks/includes/core.h")
35-
// Tell cargo to invalidate the built crate whenever any of the
36-
// included header files changed.
37-
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
38-
.generate()
39-
.expect("Unable to generate bindings");
40-
41-
// Write the bindings to the $OUT_DIR/bindings.rs file.
42-
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
43-
bindings
44-
.write_to_file(out_path.join("bindings.rs"))
45-
.expect("Couldn't write bindings!");
4630
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* automatically generated by rust-bindgen 0.72.1 */
2+
3+
pub const MARKER_TYPE_SAMPLE_START: u32 = 0;
4+
pub const MARKER_TYPE_SAMPLE_END: u32 = 1;
5+
pub const MARKER_TYPE_BENCHMARK_START: u32 = 2;
6+
pub const MARKER_TYPE_BENCHMARK_END: u32 = 3;
7+
pub type InstrumentHooks = *mut u64;
8+
extern "C" {
9+
pub fn instrument_hooks_init() -> *mut InstrumentHooks;
10+
}
11+
extern "C" {
12+
pub fn instrument_hooks_deinit(arg1: *mut InstrumentHooks);
13+
}
14+
extern "C" {
15+
pub fn instrument_hooks_is_instrumented(arg1: *mut InstrumentHooks) -> bool;
16+
}
17+
extern "C" {
18+
pub fn instrument_hooks_start_benchmark(arg1: *mut InstrumentHooks) -> u8;
19+
}
20+
extern "C" {
21+
pub fn instrument_hooks_stop_benchmark(arg1: *mut InstrumentHooks) -> u8;
22+
}
23+
extern "C" {
24+
pub fn instrument_hooks_set_executed_benchmark(
25+
arg1: *mut InstrumentHooks,
26+
pid: i32,
27+
uri: *const ::std::os::raw::c_char,
28+
) -> u8;
29+
}
30+
extern "C" {
31+
pub fn instrument_hooks_executed_benchmark(
32+
arg1: *mut InstrumentHooks,
33+
pid: i32,
34+
uri: *const ::std::os::raw::c_char,
35+
) -> u8;
36+
}
37+
extern "C" {
38+
pub fn instrument_hooks_set_integration(
39+
arg1: *mut InstrumentHooks,
40+
name: *const ::std::os::raw::c_char,
41+
version: *const ::std::os::raw::c_char,
42+
) -> u8;
43+
}
44+
extern "C" {
45+
pub fn instrument_hooks_add_marker(
46+
arg1: *mut InstrumentHooks,
47+
pid: u32,
48+
marker_type: u8,
49+
timestamp: u64,
50+
) -> u8;
51+
}
52+
extern "C" {
53+
pub fn instrument_hooks_current_timestamp() -> u64;
54+
}
55+
pub const instrument_hooks_feature_t_FEATURE_DISABLE_CALLGRIND_MARKERS: instrument_hooks_feature_t =
56+
0;
57+
pub type instrument_hooks_feature_t = ::std::os::raw::c_uint;
58+
extern "C" {
59+
pub fn instrument_hooks_set_feature(feature: instrument_hooks_feature_t, enabled: bool);
60+
}

crates/codspeed/src/instrument_hooks/ffi.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,11 @@
33
#![allow(non_snake_case)]
44
#![allow(unused)]
55

6-
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
6+
// Use pre-generated bindings instead of generating at build time so that downstream
7+
// users don't need to install `libclang`.
8+
//
9+
// To regenerate bindings, run:
10+
// ```
11+
// ./update-bindings.sh
12+
// ```
13+
include!("bindings.rs");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
bindgen ../../instrument-hooks/includes/core.h \
5+
-o bindings.rs \
6+
--rust-target 1.74 \
7+
--allowlist-function "instrument_hooks_.*" \
8+
--allowlist-var "MARKER_TYPE_.*"

0 commit comments

Comments
 (0)