Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 34 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,53 @@ jobs:
with:
extra_args: --all-files

- uses: taiki-e/install-action@v2
with:
tool: [email protected]
- name: Check if bindings are up-to-date
working-directory: crates/codspeed/src/instrument_hooks
run: |
./update-bindings.sh

if ! git diff --exit-code bindings.rs; then
echo "Error: FFI bindings are out of date!"
exit 1
fi

test-codspeed:
runs-on: ${{ matrix.job.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
job:
- { os: ubuntu-latest, target: arm-unknown-linux-gnueabihf }
- { os: ubuntu-latest, target: aarch64-unknown-linux-musl }
- { os: ubuntu-latest, target: i686-unknown-linux-gnu }
- { os: ubuntu-latest, target: i686-unknown-linux-musl }
- { os: ubuntu-latest, target: x86_64-unknown-linux-gnu }
- { os: ubuntu-latest, target: x86_64-unknown-linux-musl }
- { os: macos-latest, target: aarch64-apple-darwin }
- { os: macos-latest, target: x86_64-apple-darwin }
- { os: windows-latest, target: i686-pc-windows-msvc }
- { os: windows-latest, target: x86_64-pc-windows-msvc }
- { os: windows-latest, target: aarch64-pc-windows-msvc }
steps:
- uses: actions/checkout@v4
with:
submodules: true

- uses: moonrepo/setup-rust@v1
with:
cache-target: release
targets: ${{ matrix.job.target }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- run: cargo test -p codspeed
if: runner.os == 'Linux'
- uses: taiki-e/install-action@v2
with:
tool: [email protected]

# We don't support Windows/MacOS for now, due to libclang not found on some runners:
- run: LIBCLANG_PATH= cargo test -p codspeed
if: runner.os == 'macOS'
- run: |
$env:LIBCLANG_PATH=""
cargo test -p codspeed
if: runner.os == 'Windows'
shell: powershell
- name: Build codspeed
run: cross build -p codspeed --target ${{ matrix.job.target }}

msrv-check:
runs-on: ubuntu-latest
Expand Down
89 changes: 0 additions & 89 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/codspeed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ harness = false
tempfile = { workspace = true }

[build-dependencies]
bindgen = "0.72.1"
cc = "1.0"
62 changes: 31 additions & 31 deletions crates/codspeed/build.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
use std::{env, path::PathBuf};

fn main() {
println!("cargo:rustc-check-cfg=cfg(use_instrument_hooks)");

println!("cargo:rerun-if-changed=instrument-hooks/dist/core.c");
println!("cargo:rerun-if-changed=instrument-hooks/includes/core.h");
println!("cargo:rerun-if-changed=build.rs");

if cfg!(not(target_os = "linux")) {
// The instrument-hooks library is only supported on Linux.
return;
}

let mut build = cc::Build::new();
build
.flag("-std=gnu17")
.flag("-std=c11")
.file("instrument-hooks/dist/core.c")
.include("instrument-hooks/includes")
// We generated the C code from Zig, which contains some warnings
// that can be safely ignored.
.flag("-Wno-format")
.flag("-Wno-format-security")
.flag("-Wno-unused-but-set-variable")
.flag("-Wno-unused-const-variable")
.flag("-Wno-type-limits")
.flag("-Wno-uninitialized")
// Ignore warnings when cross-compiling:
.flag("-Wno-overflow")
.flag("-Wno-unused-function")
.flag("-Wno-constant-conversion")
.flag("-Wno-incompatible-pointer-types")
// Disable warnings, as we will have lots of them
.warnings(false)
.extra_warnings(false)
.cargo_warnings(false);
.cargo_warnings(false)
.opt_level(3);

let result = build.try_compile("instrument_hooks");
if let Err(e) = result {
let compiler = build.try_get_compiler().expect("Failed to get C compiler");

eprintln!("\n\nERROR: Failed to compile instrument-hooks native library with cc-rs. Ensure you have an up-to-date C compiler installed.");
eprintln!("Compiler information: {compiler:?}");
eprintln!("Compilation error: {e}");

std::process::exit(1);
match result {
Ok(_) => println!("cargo:rustc-cfg=use_instrument_hooks"),
Err(e) => {
let compiler = build.try_get_compiler().expect("Failed to get C compiler");

eprintln!("\n\nWARNING: Failed to compile instrument-hooks native library with cc-rs.");
eprintln!("The library will still compile, but instrument-hooks functionality will be disabled.");
eprintln!("Compiler information: {compiler:?}");
eprintln!("Compilation error: {e}\n");

println!("cargo:warning=Failed to compile instrument-hooks native library with cc-rs. Continuing with noop implementation.");
}
}

let bindings = bindgen::Builder::default()
.header("instrument-hooks/includes/core.h")
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.generate()
.expect("Unable to generate bindings");

// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
60 changes: 60 additions & 0 deletions crates/codspeed/src/instrument_hooks/bindings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* automatically generated by rust-bindgen 0.72.1 */

pub const MARKER_TYPE_SAMPLE_START: u32 = 0;
pub const MARKER_TYPE_SAMPLE_END: u32 = 1;
pub const MARKER_TYPE_BENCHMARK_START: u32 = 2;
pub const MARKER_TYPE_BENCHMARK_END: u32 = 3;
pub type InstrumentHooks = *mut u64;
extern "C" {
pub fn instrument_hooks_init() -> *mut InstrumentHooks;
}
extern "C" {
pub fn instrument_hooks_deinit(arg1: *mut InstrumentHooks);
}
extern "C" {
pub fn instrument_hooks_is_instrumented(arg1: *mut InstrumentHooks) -> bool;
}
extern "C" {
pub fn instrument_hooks_start_benchmark(arg1: *mut InstrumentHooks) -> u8;
}
extern "C" {
pub fn instrument_hooks_stop_benchmark(arg1: *mut InstrumentHooks) -> u8;
}
extern "C" {
pub fn instrument_hooks_set_executed_benchmark(
arg1: *mut InstrumentHooks,
pid: i32,
uri: *const ::std::os::raw::c_char,
) -> u8;
}
extern "C" {
pub fn instrument_hooks_executed_benchmark(
arg1: *mut InstrumentHooks,
pid: i32,
uri: *const ::std::os::raw::c_char,
) -> u8;
}
extern "C" {
pub fn instrument_hooks_set_integration(
arg1: *mut InstrumentHooks,
name: *const ::std::os::raw::c_char,
version: *const ::std::os::raw::c_char,
) -> u8;
}
extern "C" {
pub fn instrument_hooks_add_marker(
arg1: *mut InstrumentHooks,
pid: u32,
marker_type: u8,
timestamp: u64,
) -> u8;
}
extern "C" {
pub fn instrument_hooks_current_timestamp() -> u64;
}
pub const instrument_hooks_feature_t_FEATURE_DISABLE_CALLGRIND_MARKERS: instrument_hooks_feature_t =
0;
pub type instrument_hooks_feature_t = ::std::os::raw::c_uint;
extern "C" {
pub fn instrument_hooks_set_feature(feature: instrument_hooks_feature_t, enabled: bool);
}
9 changes: 8 additions & 1 deletion crates/codspeed/src/instrument_hooks/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@
#![allow(non_snake_case)]
#![allow(unused)]

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
// Use pre-generated bindings instead of generating at build time so that downstream
// users don't need to install `libclang`.
//
// To regenerate bindings, run:
// ```
// ./update-bindings.sh
// ```
include!("bindings.rs");
Loading
Loading