diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 65a4d9fa..88d64053 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,22 +15,27 @@ jobs: - uses: moonrepo/setup-rust@v1 with: components: rustfmt, clippy + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - uses: pre-commit/action@v3.0.1 with: extra_args: --all-files - lint-windows: - runs-on: windows-latest + test-codspeed: + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 with: submodules: true - uses: moonrepo/setup-rust@v1 with: - components: rustfmt, clippy - - uses: pre-commit/action@v3.0.1 - with: - extra_args: --all-files + cache-target: release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - run: cargo test -p codspeed msrv-check: runs-on: ubuntu-latest @@ -41,6 +46,8 @@ jobs: - uses: moonrepo/setup-rust@v1 with: bins: cargo-msrv + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Check cospeed MSRV run: cargo msrv --path crates/codspeed verify -- cargo check --all-features --config codspeed=true - name: Check bencher_compat MSRV @@ -57,6 +64,8 @@ jobs: with: submodules: true - uses: moonrepo/setup-rust@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: cargo test --all compat-integration-test-instrumentation: @@ -76,6 +85,8 @@ jobs: - uses: moonrepo/setup-rust@v1 with: cache-target: release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: cargo install --path crates/cargo-codspeed --locked @@ -105,6 +116,8 @@ jobs: - uses: moonrepo/setup-rust@v1 with: cache-target: release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: cargo install --path crates/cargo-codspeed --locked @@ -139,6 +152,8 @@ jobs: - uses: moonrepo/setup-rust@v1 with: targets: ${{ matrix.target }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Install musl tools run: sudo apt-get update && sudo apt-get install -y musl-tools @@ -150,7 +165,7 @@ jobs: if: always() needs: - lint - - lint-windows + - test-codspeed - msrv-check - tests - compat-integration-test-instrumentation diff --git a/crates/codspeed/build.rs b/crates/codspeed/build.rs index 3eef6527..22f58401 100644 --- a/crates/codspeed/build.rs +++ b/crates/codspeed/build.rs @@ -1,6 +1,11 @@ use std::{env, path::PathBuf}; fn main() { + if cfg!(not(target_os = "linux")) { + // The instrument-hooks library is only supported on Linux. + return; + } + // Compile the C library cc::Build::new() .file("instrument-hooks/dist/core.c") diff --git a/crates/codspeed/instrument-hooks b/crates/codspeed/instrument-hooks index 0d3de57f..b3d4b78e 160000 --- a/crates/codspeed/instrument-hooks +++ b/crates/codspeed/instrument-hooks @@ -1 +1 @@ -Subproject commit 0d3de57fe46ef97714a41ed028096f6f84fdbd2a +Subproject commit b3d4b78ef68498d59afd45a9c8b2ef096652f034 diff --git a/crates/codspeed/src/instrument_hooks/mod.rs b/crates/codspeed/src/instrument_hooks/mod.rs index 12ae6164..ef4e08c1 100644 --- a/crates/codspeed/src/instrument_hooks/mod.rs +++ b/crates/codspeed/src/instrument_hooks/mod.rs @@ -1,8 +1,8 @@ -#[cfg(unix)] +#[cfg(target_os = "linux")] mod ffi; -#[cfg(unix)] -mod unix_impl { +#[cfg(target_os = "linux")] +mod linux_impl { use nix::sys::time::TimeValLike; use super::ffi; @@ -131,7 +131,7 @@ mod unix_impl { } } -#[cfg(not(unix))] +#[cfg(not(target_os = "linux"))] mod other_impl { pub struct InstrumentHooks; @@ -169,8 +169,25 @@ mod other_impl { } } -#[cfg(unix)] -pub use unix_impl::InstrumentHooks; +#[cfg(target_os = "linux")] +pub use linux_impl::InstrumentHooks; -#[cfg(not(unix))] +#[cfg(not(target_os = "linux"))] pub use other_impl::InstrumentHooks; + +#[cfg(test)] +mod tests { + use super::InstrumentHooks; + + #[test] + fn test_instrument_hooks() { + let hooks = InstrumentHooks::instance(); + assert!(!hooks.is_instrumented() || hooks.start_benchmark().is_ok()); + assert!(hooks.set_executed_benchmark("test_uri").is_ok()); + assert!(hooks.set_integration("test_integration", "1.0.0").is_ok()); + let start = InstrumentHooks::current_timestamp(); + let end = start + 1_000_000; // Simulate 1ms later + hooks.add_benchmark_timestamps(start, end); + assert!(!hooks.is_instrumented() || hooks.stop_benchmark().is_ok()); + } +}