Skip to content

Commit ab9e7f8

Browse files
committed
feat: release heaptrack with cargo-dist
1 parent 178513a commit ab9e7f8

File tree

6 files changed

+54
-20
lines changed

6 files changed

+54
-20
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ memmap2 = "0.9.5"
5757
nix = { version = "0.29.0", features = ["fs", "time", "user"] }
5858
futures = "0.3.31"
5959
runner-shared = { path = "crates/runner-shared" }
60-
heaptrack = { path = "crates/heaptrack" }
60+
heaptrack = { path = "crates/heaptrack", default-features = false }
6161
ipc-channel = "0.18"
6262
shellexpand = { version = "3.1.1", features = ["tilde"] }
6363
addr2line = "0.25"
@@ -92,6 +92,9 @@ inherits = "release"
9292
lto = "thin"
9393
strip = true
9494

95+
[package.metadata.dist]
96+
targets = ["aarch64-unknown-linux-musl", "x86_64-unknown-linux-musl"]
97+
9598
# Config for 'dist'
9699
[workspace.metadata.dist]
97100
# Whether to consider the binaries in a package for distribution (defaults true)
@@ -102,8 +105,6 @@ cargo-dist-version = "0.28.4"
102105
ci = "github"
103106
# The installers to generate for each app
104107
installers = ["shell"]
105-
# Target platforms to build apps for (Rust target-triple syntax)
106-
targets = ["aarch64-unknown-linux-musl", "x86_64-unknown-linux-musl"]
107108
# The archive format to use for non-windows builds (defaults .tar.xz)
108109
unix-archive = ".tar.gz"
109110
# Which actions to run on pull requests
@@ -114,6 +115,7 @@ post-announce-jobs = ["./bump-action"]
114115
install-path = "CARGO_HOME"
115116
# Whether to install an updater program
116117
install-updater = false
118+
precise-builds = true
117119

118120
[workspace.metadata.dist.github-custom-runners]
119121
aarch64-unknown-linux-musl = "buildjet-2vcpu-ubuntu-2204-arm"

crates/heaptrack/Cargo.toml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "heaptrack"
3-
version = "0.1.0"
3+
version = "4.4.1"
44
edition = "2024"
55
repository = "https://github.com/CodSpeedHQ/runner"
66

@@ -11,12 +11,20 @@ path = "src/lib.rs"
1111
[[bin]]
1212
name = "codspeed-heaptrack"
1313
path = "src/main.rs"
14+
required-features = ["ebpf"]
15+
16+
[features]
17+
default = ["ebpf"]
18+
ebpf = [
19+
"dep:libbpf-rs",
20+
"dep:libbpf-cargo",
21+
"dep:vmlinux",
22+
]
1423

1524
[dependencies]
1625
anyhow = "1.0"
1726
clap = { version = "4.5", features = ["derive"] }
1827
libc = "0.2"
19-
libbpf-rs = "0.25.0"
2028
log = "0.4.28"
2129
env_logger = "0.11.8"
2230
serde_json = "1.0"
@@ -25,11 +33,12 @@ runner-shared = { path = "../runner-shared" }
2533
ipc-channel = "0.18"
2634
static_assertions = "1.1"
2735
itertools = "0.14.0"
36+
libbpf-rs = { version = "0.25.0", features = ["vendored"], optional = true }
2837

2938
[build-dependencies]
30-
libbpf-cargo = "0.25.0"
39+
libbpf-cargo = { version = "0.25.0", optional = true }
40+
vmlinux = { git = "https://github.com/libbpf/vmlinux.h.git", optional = true }
3141
bindgen = "0.71"
32-
vmlinux = { git = "https://github.com/libbpf/vmlinux.h.git" }
3342

3443
[dev-dependencies]
3544
tempfile = "3.8"
@@ -39,6 +48,11 @@ test-log = "0.2"
3948
[package.metadata.dist]
4049
dist = true
4150
installers = ["shell"]
51+
targets = ["aarch64-unknown-linux-gnu", "x86_64-unknown-linux-gnu"]
52+
features = ["libbpf-rs/static"]
4253

4354
[package.metadata.dist.dependencies.apt]
44-
libelf-dev = "*"
55+
build-essential = "*"
56+
pkgconf = "*"
57+
zlib1g-dev = "*"
58+
libbpf-dev = "*"

crates/heaptrack/build.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
#[cfg(feature = "ebpf")]
12
use std::{env, path::PathBuf};
23

3-
use libbpf_cargo::SkeletonBuilder;
4+
#[cfg(feature = "ebpf")]
5+
fn build_ebpf() {
6+
use libbpf_cargo::SkeletonBuilder;
47

5-
fn main() {
68
println!("cargo:rerun-if-changed=src/bpf");
79

810
// Build the BPF program
911
let arch = env::var("CARGO_CFG_TARGET_ARCH")
1012
.expect("CARGO_CFG_TARGET_ARCH must be set in build script");
11-
let out_dir =
12-
PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR must be set in build script"));
13-
let heaptrack_out = out_dir.join("heaptrack.skel.rs");
13+
let heaptrack_out = PathBuf::from(env::var("OUT_DIR").unwrap()).join("heaptrack.skel.rs");
1414
SkeletonBuilder::new()
1515
.source("src/bpf/heaptrack.bpf.c")
1616
.clang_args([
@@ -26,7 +26,11 @@ fn main() {
2626
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
2727
.generate()
2828
.expect("Unable to generate bindings");
29-
30-
let out_file = out_dir.join("event.rs");
29+
let out_file = PathBuf::from(env::var("OUT_DIR").unwrap()).join("event.rs");
3130
std::fs::write(&out_file, bindings.to_string()).expect("Couldn't write bindings!");
3231
}
32+
33+
fn main() {
34+
#[cfg(feature = "ebpf")]
35+
build_ebpf();
36+
}

crates/heaptrack/src/ipc.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use anyhow::{Context, Result};
22
use ipc_channel::ipc::{self, IpcOneShotServer, IpcSender};
3-
use log::debug;
43
use serde::{Deserialize, Serialize};
4+
5+
#[cfg(feature = "ebpf")]
6+
use crate::Tracker;
7+
#[cfg(feature = "ebpf")]
58
use std::sync::{Arc, Mutex};
69

710
pub type HeaptrackIpcServer = IpcOneShotServer<IpcSender<IpcMessage>>;
811

9-
use crate::Tracker;
10-
1112
/// Commands sent from the runner to control heaptrack
1213
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
1314
pub enum IpcCommand {
@@ -85,7 +86,10 @@ impl HeaptrackIpcClient {
8586
}
8687

8788
/// Handle incoming IPC messages in heaptrack
89+
#[cfg(feature = "ebpf")]
8890
pub fn handle_ipc_message(msg: IpcMessage, tracker: &Arc<Mutex<Tracker>>) {
91+
use log::debug;
92+
8993
let response = match msg.command {
9094
IpcCommand::Enable => match tracker.lock() {
9195
Ok(mut t) => match t.enable() {

crates/heaptrack/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1+
#[cfg(feature = "ebpf")]
12
mod bpf;
3+
#[cfg(feature = "ebpf")]
24
mod events;
35
mod ipc;
6+
#[cfg(feature = "ebpf")]
47
mod libc;
8+
#[cfg(feature = "ebpf")]
59
mod poller;
10+
#[cfg(feature = "ebpf")]
611
mod tracker;
712

13+
#[cfg(feature = "ebpf")]
814
pub use events::{Event, EventType};
15+
#[cfg(feature = "ebpf")]
16+
pub use ipc::handle_ipc_message;
917
pub use ipc::{
1018
HeaptrackIpcClient, HeaptrackIpcServer, IpcCommand as HeaptrackIpcCommand,
11-
IpcMessage as HeaptrackIpcMessage, IpcResponse as HeaptrackIpcResponse, handle_ipc_message,
19+
IpcMessage as HeaptrackIpcMessage, IpcResponse as HeaptrackIpcResponse,
1220
};
21+
#[cfg(feature = "ebpf")]
1322
pub use poller::{EventHandler, RingBufferPoller};
23+
#[cfg(feature = "ebpf")]
1424
pub use tracker::Tracker;

0 commit comments

Comments
 (0)