Skip to content

Commit dd97fbf

Browse files
committed
fix: partially fix build
1 parent aecdbcb commit dd97fbf

File tree

18 files changed

+96
-15
lines changed

18 files changed

+96
-15
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builder/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ license.workspace = true
88

99
[features]
1010
default = []
11+
common-net1 = []
1112
crashtracker = []
1213
profiling = []
1314
telemetry = []

builder/src/bin/release.rs

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ pub fn main() {
6161
let features = {
6262
#[allow(unused_mut)]
6363
let mut f: Vec<String> = vec![];
64+
#[cfg(feature = "common-net1")]
65+
f.push("ddcommon-net1-ffi".to_string());
6466
#[cfg(feature = "telemetry")]
6567
f.push("ddtelemetry-ffi".to_string());
6668
#[cfg(feature = "data-pipeline")]

builder/src/common_net1.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use crate::arch;
5+
use crate::module::Module;
6+
use crate::utils::project_root;
7+
use anyhow::Result;
8+
use std::fs;
9+
use std::path::PathBuf;
10+
use std::process::Command;
11+
use std::rc::Rc;
12+
13+
pub struct CommonNet1 {
14+
pub arch: Rc<str>,
15+
pub source_include: Rc<str>,
16+
pub target_include: Rc<str>,
17+
}
18+
19+
impl Module for CommonNet1 {
20+
fn build(&self) -> Result<()> {
21+
let mut cargo = Command::new("cargo")
22+
.env("RUSTFLAGS", arch::RUSTFLAGS.join(" "))
23+
.current_dir(project_root())
24+
.args(["build", "-p", "ddcommon-net1-ffi", "--target", &self.arch])
25+
.spawn()
26+
.expect("failed to spawn cargo");
27+
28+
cargo.wait().expect("Cargo failed");
29+
Ok(())
30+
}
31+
32+
fn install(&self) -> Result<()> {
33+
let target_path: PathBuf = [self.target_include.as_ref(), "common_net1.h"]
34+
.iter()
35+
.collect();
36+
37+
let origin_path: PathBuf = [self.source_include.as_ref(), "common_net1.h"]
38+
.iter()
39+
.collect();
40+
fs::copy(origin_path, target_path).expect("Failed to copy common_net1.h");
41+
Ok(())
42+
}
43+
}

builder/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
pub mod arch;
55
pub mod builder;
66
pub mod common;
7+
pub mod common_net1;
78
#[cfg(feature = "crashtracker")]
89
pub mod crashtracker;
910
pub mod module;

crashtracker-ffi/cbindgen.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ renaming_overrides_prefixing = true
2323
"ByteSlice" = "ddog_ByteSlice"
2424
"CancellationToken" = "ddog_CancellationToken"
2525
"CharSlice" = "ddog_CharSlice"
26-
"Endpoint" = "ddog_Endpoint"
26+
"Endpoint" = "ddog_net1_Endpoint"
2727
"Error" = "ddog_Error"
2828
"HttpStatus" = "ddog_HttpStatus"
2929
"Option_U32" = "ddog_Option_U32"

ddcommon-net1-ffi/Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ edition.workspace = true
88
version.workspace = true
99
license.workspace = true
1010

11+
[lib]
12+
crate-type = ["lib", "staticlib", "cdylib"]
13+
bench = false
14+
15+
[build-dependencies]
16+
build_common = { path = "../build-common" }
17+
1118
[dependencies]
1219
ddcommon-ffi = { path = "../ddcommon-ffi" }
1320
ddcommon-net1 = { path = "../ddcommon-net1" }

ddcommon-net1-ffi/build.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/
2+
// SPDX-License-Identifier: Apache-2.0
3+
extern crate build_common;
4+
5+
use build_common::generate_and_configure_header;
6+
7+
fn main() {
8+
let header_name = "common_net1.h";
9+
generate_and_configure_header(header_name);
10+
}

ddcommon-net1-ffi/cbindgen.toml

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ no_includes = true
1515
sys_includes = ["stdbool.h", "stddef.h", "stdint.h"]
1616

1717
[export]
18-
prefix = "ddog_net1"
18+
prefix = "ddog_net1_"
1919
renaming_overrides_prefixing = true
2020

2121
[export.mangle]
2222
rename_types = "PascalCase"
2323

2424
[export.rename]
25+
"CharSlice" = "ddog_CharSlice"
26+
"Error" = "ddog_Error"
2527

2628

2729
[enum]
@@ -32,4 +34,5 @@ rename_variants = "ScreamingSnakeCase"
3234
must_use = "DDOG_CHECK_RETURN"
3335

3436
[parse]
35-
parse_deps = true
37+
parse_deps = true
38+
include = ["ddcommon-net1"]

ddcommon-net1-ffi/src/endpoint.rs

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ use std::str::FromStr;
99

1010
use http::uri::{Authority, Parts};
1111

12+
// Bindgen doesn't understand modules, this is the same type as far as bindgen
13+
// is concerned. Using a transparent repr is important here.
14+
mod bindgen {
15+
// Create a wrapper struct for FFI, since bindgen doesn't forward declare
16+
// the struct without it.
17+
#[allow(dead_code)]
18+
#[repr(transparent)]
19+
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
20+
pub struct Endpoint(ddcommon_net1::Endpoint);
21+
}
22+
1223
pub type Endpoint = ddcommon_net1::Endpoint;
1324

1425
#[no_mangle]

ddcommon-net1/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub fn decode_uri_path_in_authority(uri: &hyper::Uri) -> anyhow::Result<PathBuf>
137137

138138
impl Endpoint {
139139
/// Default value for the timeout field in milliseconds.
140-
/// Sync with ddog_Endpoint's default manually.
140+
/// Sync with ddog_net1_Endpoint's default manually.
141141
pub const DEFAULT_TIMEOUT: u64 = 3_000;
142142

143143
/// Return a request builder with the following headers:

ddtelemetry-ffi/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ build_common = { path = "../build-common" }
2424
ddtelemetry = { path = "../ddtelemetry" }
2525
ddcommon = { path = "../ddcommon" }
2626
ddcommon-ffi = { path = "../ddcommon-ffi", default-features = false }
27-
ddcommon-net1 = { path = "../ddcommon-net1" }
2827
ddcommon-net1-ffi = { path = "../ddcommon-net1-ffi" }
2928
paste = "1"
3029
libc = "0.2"

ddtelemetry-ffi/src/builder/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// ```
1111

1212
use ddcommon_ffi as ffi;
13-
use ddcommon_net1::Endpoint;
13+
use ddcommon_net1_ffi::Endpoint;
1414
use ddtelemetry::worker::TelemetryWorkerBuilder;
1515
use ffi::slice::AsBytes;
1616

examples/ffi/crashtracking.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
#include <datadog/common.h>
5+
#include <datadog/common_net1.h>
56
#include <datadog/crashtracker.h>
67
#include <signal.h>
78
#include <stdio.h>
@@ -49,10 +50,10 @@ int main(int argc, char **argv) {
4950
.optional_stdout_filename = DDOG_CHARSLICE_C("/tmp/crashreports/stdout.txt"),
5051
};
5152

52-
struct ddog_Endpoint *endpoint =
53+
struct ddog_net1_Endpoint *endpoint =
5354
ddog_endpoint_from_filename(DDOG_CHARSLICE_C("/tmp/crashreports/crashreport.json"));
5455
// Alternatively:
55-
// struct ddog_Endpoint * endpoint =
56+
// struct ddog_net1_Endpoint * endpoint =
5657
// ddog_endpoint_from_url(DDOG_CHARSLICE_C("http://localhost:8126"));
5758

5859
ddog_crasht_Config config = {

examples/ffi/telemetry.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
#include <datadog/common.h>
5+
#include <datadog/common_net1.h>
56
#include <datadog/telemetry.h>
67
#include <stdio.h>
78
#include <stdlib.h>
@@ -24,7 +25,7 @@ int main(void) {
2425
TRY(ddog_telemetry_builder_instantiate(&builder, service, lang, lang_version, tracer_version));
2526

2627
ddog_CharSlice endpoint_char = DDOG_CHARSLICE_C("file://./examples_telemetry.out");
27-
struct ddog_Endpoint *endpoint = ddog_endpoint_from_url(endpoint_char);
28+
struct ddog_net1_Endpoint *endpoint = ddog_endpoint_from_url(endpoint_char);
2829
TRY(ddog_telemetry_builder_with_endpoint_config_endpoint(builder, endpoint));
2930
ddog_endpoint_drop(endpoint);
3031

@@ -44,4 +45,4 @@ int main(void) {
4445
ddog_telemetry_handle_wait_for_shutdown(handle);
4546

4647
return 0;
47-
}
48+
}

examples/ffi/telemetry_metrics.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
#include <datadog/common.h>
5+
#include <datadog/common_net1.h>
56
#include <datadog/telemetry.h>
67
#include <stdio.h>
78
#include <stdlib.h>
@@ -48,7 +49,7 @@ int main(void) {
4849
TRY(ddog_telemetry_builder_instantiate(&builder, service, lang, lang_version, tracer_version));
4950

5051
ddog_CharSlice endpoint_char = DDOG_CHARSLICE_C("file://./examples_telemetry_metrics.out");
51-
struct ddog_Endpoint *endpoint = ddog_endpoint_from_url(endpoint_char);
52+
struct ddog_net1_Endpoint *endpoint = ddog_endpoint_from_url(endpoint_char);
5253
TRY(ddog_telemetry_builder_with_endpoint_config_endpoint(builder, endpoint));
5354
ddog_endpoint_drop(endpoint);
5455

profiling-ffi/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ bench = false
1717
[features]
1818
default = []
1919
cbindgen = ["build_common/cbindgen", "ddcommon-ffi/cbindgen"]
20+
ddcommon-net1-ffi = ["dep:ddcommon-net1-ffi"]
2021
ddtelemetry-ffi = ["dep:ddtelemetry-ffi"]
2122
symbolizer = ["symbolizer-ffi"]
2223
data-pipeline-ffi = ["dep:data-pipeline-ffi"]
@@ -38,7 +39,7 @@ futures = { version = "0.3", default-features = false }
3839
hyper = { version = "0.14", features = ["backports", "deprecated"], default-features = false }
3940
ddcommon = { path = "../ddcommon" }
4041
ddcommon-ffi = { path = "../ddcommon-ffi", default-features = false }
41-
ddcommon-net1 = { path = "../ddcommon-net1" }
42+
ddcommon-net1-ffi = { path = "../ddcommon-net1-ffi", optional = true }
4243
ddtelemetry-ffi = { path = "../ddtelemetry-ffi", default-features = false, optional = true, features = ["expanded_builder_macros"] }
4344
libc = "0.2"
4445
tokio-util = "0.7.1"

profiling-ffi/cbindgen.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ renaming_overrides_prefixing = true
2323
"ByteSlice" = "ddog_ByteSlice"
2424
"CancellationToken" = "ddog_CancellationToken"
2525
"CharSlice" = "ddog_CharSlice"
26-
"Endpoint" = "ddog_Endpoint"
26+
"Endpoint" = "ddog_net1_Endpoint"
2727
"Error" = "ddog_Error"
2828
"HttpStatus" = "ddog_HttpStatus"
2929
"Slice_CChar" = "ddog_Slice_CChar"

0 commit comments

Comments
 (0)