-
Notifications
You must be signed in to change notification settings - Fork 18
fix: building codspeed with clang #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
not-matthias
merged 7 commits into
main
from
cod-1483-error-building-codspeed-rust-with-clang
Oct 20, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
19f5244
fix(codspeed): replace bindgen with manual bindings
not-matthias aea8b88
feat(ci): add cargo-cross tests
not-matthias 1d5c36b
fix(codspeed): switch to c11
not-matthias 19ad9f2
fix(codspeed): fallback to noop when build fails
not-matthias 61d9904
fix(codspeed): suppress warnings, but still show them with cargo
not-matthias 8b63059
feat(codspeed): build with optimizations
not-matthias 898484d
fix: build on windows
not-matthias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,5 +36,4 @@ harness = false | |
tempfile = { workspace = true } | ||
|
||
[build-dependencies] | ||
bindgen = "0.72.1" | ||
cc = "1.0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.