Skip to content

Commit 78969e5

Browse files
Instrumentation worker ffi (#27)
* Initial telemetry ffi implementation * Add telemetry header generation to build script * Using the nightly toolchain when running cbindgen to expand functions in macros
1 parent 7068677 commit 78969e5

File tree

15 files changed

+538
-21
lines changed

15 files changed

+538
-21
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ jobs:
6262
rust_version: ${{ matrix.rust_version }}
6363
build_profile: "release"
6464

65+
- name: Install nightly toolchain
66+
run: rustup install nightly
67+
6568
- name: Install Rust ${{ matrix.rust_version }}
6669
if: ${{ matrix.rust_version != '' }}
6770
run: rustup install ${{ matrix.rust_version }} && rustup default ${{ matrix.rust_version }}

Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ members = [
88
"ddcommon",
99
"ddcommon-ffi",
1010
"ddtelemetry",
11+
"ddtelemetry-ffi",
1112
"tools",
1213
]
1314
# https://doc.rust-lang.org/cargo/reference/resolver.html#feature-resolver-version-2

LICENSE-3rdparty.yml

Lines changed: 9 additions & 1 deletion
Large diffs are not rendered by default.

build-profiling-ffi.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,15 @@ echo "Building tools"
148148
cargo build --package tools --bins
149149

150150
echo "Generating $destdir/include/libdatadog headers..."
151-
cbindgen --crate ddcommon-ffi \
151+
rustup run nightly -- cbindgen --crate ddcommon-ffi \
152152
--config ddcommon-ffi/cbindgen.toml \
153153
--output "$destdir/include/datadog/common.h"
154-
cbindgen --crate "${datadog_profiling_ffi}" \
154+
rustup run nightly -- cbindgen --crate "${datadog_profiling_ffi}" \
155155
--config profiling-ffi/cbindgen.toml \
156156
--output "$destdir/include/datadog/profiling.h"
157-
./target/debug/dedup_headers "$destdir/include/datadog/common.h" "$destdir/include/datadog/profiling.h"
157+
rustup run nightly -- cbindgen --crate ddtelemetry-ffi \
158+
--config ddtelemetry-ffi/cbindgen.toml \
159+
--output "$destdir/include/datadog/telemetry.h"
160+
./target/debug/dedup_headers "$destdir/include/datadog/common.h" "$destdir/include/datadog/telemetry.h" "$destdir/include/datadog/profiling.h"
158161

159162
echo "Done."

ddcommon-ffi/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
22
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present Datadog, Inc.
33

4+
pub mod option;
45
pub mod slice;
56
pub mod tags;
67
pub mod vec;
78

8-
pub use slice::Slice;
9+
pub use option::Option;
10+
pub use slice::{CharSlice, Slice};
911
pub use vec::Vec;

ddcommon-ffi/src/option.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
2+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present Datadog, Inc.
3+
4+
#[repr(C)]
5+
#[derive(Debug, PartialEq, Eq)]
6+
pub enum Option<T> {
7+
Some(T),
8+
None,
9+
}
10+
11+
impl<T> Option<T> {
12+
pub fn to_std(self) -> std::option::Option<T> {
13+
self.into()
14+
}
15+
}
16+
17+
impl<T> From<Option<T>> for std::option::Option<T> {
18+
fn from(o: Option<T>) -> Self {
19+
match o {
20+
Option::Some(s) => Some(s),
21+
Option::None => None,
22+
}
23+
}
24+
}

ddcommon-ffi/src/vec.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@ use std::mem::ManuallyDrop;
1313
/// The names ptr and len were chosen to minimize conversion from a previous
1414
/// Buffer type which this has replaced to become more general.
1515
#[repr(C)]
16+
#[derive(Debug)]
1617
pub struct Vec<T: Sized> {
1718
ptr: *const T,
1819
len: usize,
1920
capacity: usize,
2021
_marker: PhantomData<T>,
2122
}
2223

24+
impl<T: PartialEq> PartialEq for Vec<T> {
25+
fn eq(&self, other: &Self) -> bool {
26+
self.len() == other.len() && self.into_iter().zip(other.into_iter()).all(|(s, o)| s == o)
27+
}
28+
}
29+
30+
impl<T: Eq> Eq for Vec<T> {}
31+
2332
impl<T> Drop for Vec<T> {
2433
fn drop(&mut self) {
2534
let vec =

ddtelemetry-ffi/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
2+
# This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present Datadog, Inc.
3+
4+
[package]
5+
name = "ddtelemetry-ffi"
6+
version = "0.8.0"
7+
edition = "2021"
8+
9+
[lib]
10+
# LTO is ignored if "lib" is added as crate type
11+
# cf. https://github.com/rust-lang/rust/issues/51009
12+
crate-type = ["staticlib", "cdylib"]
13+
14+
[dependencies]
15+
ddtelemetry = { path = "../ddtelemetry", version = "0.8.0" }
16+
ddcommon-ffi = { path = "../ddcommon-ffi", version = "0.8.0" }
17+
paste = "1"

ddtelemetry-ffi/cbindgen.toml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
2+
# This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present Datadog, Inc.
3+
4+
language = "C"
5+
tab_width = 2
6+
header = """// Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
7+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present Datadog, Inc.
8+
"""
9+
include_guard = "DDOG_TELEMETRY_H"
10+
style = "both"
11+
12+
no_includes = true
13+
sys_includes = ["stdbool.h", "stddef.h", "stdint.h"]
14+
includes = ["datadog/common.h"]
15+
16+
[export]
17+
prefix = "ddog_"
18+
19+
[export.mangle]
20+
rename_types="SnakeCase"
21+
22+
[enum]
23+
prefix_with_name = true
24+
rename_variants = "ScreamingSnakeCase"
25+
26+
[fn]
27+
must_use = "DDOG_CHECK_RETURN"
28+
29+
[parse]
30+
expand = ["ddtelemetry-ffi"]
31+
parse_deps = true
32+
include = ["ddcommon", "ddtelemetry", "ddcommon-ffi"]

0 commit comments

Comments
 (0)