Skip to content

Commit

Permalink
Merge branch 'main' into duncan-harvey/datadog-trace-utils-bump-hyper…
Browse files Browse the repository at this point in the history
…-rustls-version
  • Loading branch information
duncanpharvey committed Jun 26, 2024
2 parents 417cdc7 + 0a4632a commit 1276065
Show file tree
Hide file tree
Showing 19 changed files with 1,110 additions and 38 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ serverless @Datadog/serverless
sidecar @Datadog/libdatadog-php @Datadog/libdatadog-apm
sidecar-ffi @Datadog/libdatadog-php @Datadog/libdatadog-apm
data-pipeline*/ @Datadog/libdatadog-apm
ddsketch @Datadog/libdatadog-apm @Datadog/libdatadog-telemetry
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ members = [
"serverless",
"bin_tests",
"data-pipeline",
"data-pipeline-ffi"
"data-pipeline-ffi",
"ddsketch",
]
# https://doc.rust-lang.org/cargo/reference/resolver.html#feature-resolver-version-2
resolver = "2"
Expand Down
39 changes: 36 additions & 3 deletions LICENSE-3rdparty.yml

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions ddsketch/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "datadog-ddsketch"
description = "Minimal implementation of Datadog's DDSketch"
edition.workspace = true
version.workspace = true
rust-version.workspace = true
license.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
prost = "0.11.6"

[build-dependencies]
prost-build = { version = "0.11.9", optional = true }
protoc-bin-vendored = { version = "3.0.0", optional = true }

[features]
generate-protobuf = ["dep:prost-build", "dep:protoc-bin-vendored"]
52 changes: 52 additions & 0 deletions ddsketch/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2023-Present Datadog, Inc. https://www.datadoghq.com/
// SPDX-License-Identifier: Apache-2.0

use std::error::Error;

#[cfg(feature = "generate-protobuf")]
use std::{
env,
fs::File,
io::{Read, Write},
path::Path,
};

#[cfg(feature = "generate-protobuf")]
const HEADER: &str = "// Copyright 2023-Present Datadog, Inc. https://www.datadoghq.com/
// SPDX-License-Identifier: Apache-2.0
";

fn main() -> Result<(), Box<dyn Error>> {
#[cfg(feature = "generate-protobuf")]
{
// protoc is required to compile proto files. This uses protobuf_src to compile protoc
// from the source, setting the env var to tell prost_build where to find it.
std::env::set_var("PROTOC", protoc_bin_vendored::protoc_bin_path().unwrap());

let mut config = prost_build::Config::new();

let cur_working_dir = env::var("CARGO_MANIFEST_DIR")?;
let output_path = Path::new(&cur_working_dir).join("src");

config.out_dir(output_path.clone());

println!("cargo:rerun-if-changed=src/pb/DDSketch.proto");
config.compile_protos(&["src/pb/DDSketch.proto"], &["src/"])?;

prepend_to_file(HEADER.as_bytes(), &output_path.join("pb.rs"))?;
}

Ok(())
}

#[cfg(feature = "generate-protobuf")]
fn prepend_to_file(data: &[u8], file_path: &Path) -> Result<(), Box<dyn Error>> {
let mut f = File::open(file_path)?;
let mut content = data.to_owned();
f.read_to_end(&mut content)?;

let mut f = File::create(file_path)?;
f.write_all(content.as_slice())?;
Ok(())
}
Loading

0 comments on commit 1276065

Please sign in to comment.