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
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
workflow_dispatch:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: mlugg/setup-zig@v1
- uses: pre-commit/action@v3.0.1
with:
extra_args: --all-files

tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: mlugg/setup-zig@v1
- name: Build
run: zig build test --summary all

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: mlugg/setup-zig@v1
- name: Build
run: zig build

check:
runs-on: ubuntu-latest
if: always()
needs:
- lint
- tests
- build
steps:
- uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJson( needs ) }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.zig-cache
zig-out
target/
./main
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
exclude: ^includes/
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files

- repo: https://github.com/batmac/pre-commit-zig
rev: v0.3.0
hooks:
- id: zig-fmt
- id: zig-build
- id: zig-build-test
29 changes: 29 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
clean:
rm -rf zig-out/
rm -rf .zig-cache
rm -rf dist/

build:
zig build

release: build
test -f ./zig-out/lib/zig.h || cp "$(zig env | jq -r .lib_dir)/zig.h" ./includes/zig.h

rm -rf dist/
cp -r ./zig-out/lib dist/
echo "size of core.c: $(cat dist/core.c | wc -l)"

test:
zig build test --summary all

test-c:
clang -O3 src/tests/main.c dist/core.c -I includes/ -o clang-main && ./clang-main
valgrind ./clang-main

gcc -O3 src/tests/main.c dist/core.c -I includes/ -o gcc-main && ./gcc-main
valgrind ./gcc-main

rm -rf clang-main gcc-main

fmt:
zig fmt src
45 changes: 44 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
# core
<div align="center">
<h1>instrument-hooks</h1>

[![CI](https://github.com/CodSpeedHQ/instrument-hooks/actions/workflows/ci.yml/badge.svg)](https://github.com/CodSpeedHQ/instrument-hooks/actions/workflows/ci.yml)
[![Discord](https://img.shields.io/badge/chat%20on-discord-7289da.svg)](https://discord.com/invite/MxpaCfKSqF)

Zig library to control instrumentations via IPC.

</div>

## Requirements

- **Zig**: 0.14
- [**Just**](https://github.com/casey/just) (optional): To easily run the build, formatter or tests

## How to add new integration?

Create a new release of this library:
```shell
just release
```

You can then include build and link to the files in `dist/`. Use the `dist/core.h` header to automatically generate bindings, or create them manually.

To test if it worked, call `is_instrumented` which should return `false` when running without Codspeed. To run with Codspeed, execute the following:
```
codspeed run -- <your_cmd>
```

To make sure your integration is fully working, you have to implement all these hooks:
- start_benchmark: Call this when the benchmark starts, to start measuring the performance.
- stop_benchmark: Stop measuring the performance after the benchmark stopped.
- current_benchmark: Provide metadata about which benchmark was executed.
- set_integration: Provide metadata about the integration.

## Run tests

```
zig build test --summary all
```
or
```
just test
```
26 changes: 26 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const std = @import("std");

pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{ .default_target = .{ .ofmt = .c } });

// Core Library
//
const libcore = b.addStaticLibrary(.{
.name = "core",
.root_source_file = b.path("src/c.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.strip = true,
});
libcore.no_builtin = true;
b.installArtifact(libcore);

// Tests
//
const test_main = b.addTest(.{ .root_source_file = b.path("src/root.zig"), .optimize = optimize, .link_libc = true, .test_runner = .{ .path = b.path("src/tests/runner.zig"), .mode = .simple } });
test_main.linkLibC();
const run_test_main = b.addRunArtifact(test_main);
b.step("test", "test utility functions").dependOn(&run_test_main.step);
}
12 changes: 12 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.{
.name = .instrument_hooks,
.fingerprint = 0xd871865a9799ec8e,
.version = "0.0.1",
.minimum_zig_version = "0.14.0",
.dependencies = .{},
.paths = .{
"build.zig",
"build.zig.zon",
"src",
},
}
Loading