Skip to content

Commit ee4cded

Browse files
committed
Fix build
Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
1 parent 014caec commit ee4cded

9 files changed

Lines changed: 73 additions & 26 deletions

File tree

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ RUN_TESTS_CMD := DD_SERVICE= DD_ENV= REPORT_EXIT_STATUS=1 TEST_PHP_SRCDIR=$(PROJ
4848

4949
C_FILES = $(shell find components components-rs ext src/dogstatsd zend_abstract_interface -name '*.c' -o -name '*.h' | awk '{ printf "$(BUILD_DIR)/%s\n", $$1 }' )
5050
TEST_FILES = $(shell find tests/ext -name '*.php*' -o -name '*.inc' -o -name '*.json' -o -name '*.yaml' -o -name 'CONFLICTS' | awk '{ printf "$(BUILD_DIR)/%s\n", $$1 }' )
51-
RUST_FILES = $(BUILD_DIR)/Cargo.toml $(BUILD_DIR)/Cargo.lock $(shell find components-rs -name '*.c' -o -name '*.rs' -o -name 'Cargo.toml' | awk '{ printf "$(BUILD_DIR)/%s\n", $$1 }' ) $(shell find libdatadog/{build-common,datadog-ffe,datadog-ipc,datadog-ipc-macros,datadog-live-debugger,datadog-live-debugger-ffi,datadog-remote-config,datadog-sidecar,datadog-sidecar-ffi,datadog-sidecar-macros,libdd-alloc,libdd-common,libdd-common-ffi,libdd-crashtracker,libdd-crashtracker-ffi,libdd-data-pipeline,libdd-ddsketch,libdd-dogstatsd-client,libdd-library-config,libdd-library-config-ffi,libdd-log,libdd-libunwind-sys,libdd-telemetry,libdd-telemetry-ffi,libdd-tinybytes,libdd-trace-*,spawn_worker,tools/{cc_utils,sidecar_mockgen},libdd-trace-*,Cargo.toml} \( -type l -o -type f \) \( -path "*/src*" -o -path "*/examples*" -o -path "*Cargo.toml" -o -path "*/build.rs" -o -path "*/tests/dataservice.rs" -o -path "*/tests/service_functional.rs" \) -not -path "*/datadog-ipc/build.rs" -not -path "*/datadog-sidecar-ffi/build.rs")
51+
RUST_FILES = $(BUILD_DIR)/Cargo.toml $(BUILD_DIR)/Cargo.lock $(shell find components-rs -name '*.c' -o -name '*.rs' -o -name 'Cargo.toml' | awk '{ printf "$(BUILD_DIR)/%s\n", $$1 }' ) $(shell find libdatadog/{build-common,datadog-ffe,datadog-ipc,datadog-ipc-macros,datadog-live-debugger,datadog-live-debugger-ffi,datadog-remote-config,datadog-sidecar,datadog-sidecar-ffi,datadog-sidecar-macros,libdd-alloc,libdd-common,libdd-common-ffi,libdd-crashtracker,libdd-crashtracker-ffi,libdd-data-pipeline,libdd-ddsketch,libdd-dogstatsd-client,libdd-library-config,libdd-library-config-ffi,libdd-log,libdd-libunwind-sys,libdd-telemetry,libdd-telemetry-ffi,libdd-tinybytes,libdd-trace-*,spawn_worker,tools/{cc_utils,sidecar_mockgen},libdd-trace-*,Cargo.toml} \( -type l -o -type f \) \( -path "*/src*" -o -path "*/examples*" -o -path "*/libunwind*" -o -path "*Cargo.toml" -o -path "*/build.rs" -o -path "*/tests/dataservice.rs" -o -path "*/tests/service_functional.rs" \) -not -path "*/datadog-ipc/build.rs" -not -path "*/datadog-sidecar-ffi/build.rs")
5252
ALL_OBJECT_FILES = $(C_FILES) $(RUST_FILES) $(BUILD_DIR)/Makefile
5353
TEST_OPCACHE_FILES = $(shell find tests/opcache -name '*.php*' -o -name '.gitkeep' | awk '{ printf "$(BUILD_DIR)/%s\n", $$1 }' )
5454
TEST_STUB_FILES = $(shell find tests/ext -type d -name 'stubs' -exec find '{}' -type f \; | awk '{ printf "$(BUILD_DIR)/%s\n", $$1 }' )
@@ -500,7 +500,9 @@ $(PACKAGES_BUILD_DIR)/datadog-setup.php: $(PACKAGES_BUILD_DIR)
500500
$(PACKAGES_BUILD_DIR)
501501

502502
build_pecl_package:
503-
echo $(subst $(BUILD_DIR)/,,$(C_FILES) $(RUST_FILES) $(TEST_FILES) $(TEST_STUB_FILES) $(M4_FILES) Cargo.lock) | tooling/bin/pecl-build
503+
$(file >.pecl-files,$(subst $(BUILD_DIR)/,,$(C_FILES) $(RUST_FILES) $(TEST_FILES) $(TEST_STUB_FILES) $(M4_FILES) Cargo.lock))
504+
tooling/bin/pecl-build < .pecl-files
505+
@rm -f .pecl-files
504506

505507
dbgsym.tar.gz: $(PACKAGES_BUILD_DIR)
506508
$(if $(DDTRACE_MAKE_PACKAGES_ASAN), , tar -zcf $(PACKAGES_BUILD_DIR)/dd-library-php-$(VERSION)_windows_debugsymbols.tar.gz ./extensions_x86_64_debugsymbols --owner=0 --group=0)

cbindgen.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ rename_types = "PascalCase"
2323
"PushTagResult" = "ddog_Vec_Tag_PushResult"
2424
"ZendString" = "_zend_string"
2525
"FILE" = "FILE"
26+
"EndpointConfig" = "ddog_crasht_EndpointConfig"
2627

2728
[enum]
2829
prefix_with_name = true

components-rs/common.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
# define DDOG_CHECK_RETURN
4040
#endif
4141

42+
#ifdef _WIN32
43+
#define LIBDD_DLLIMPORT __declspec(dllimport)
44+
#else
45+
#define LIBDD_DLLIMPORT
46+
#endif
47+
4248
/**
4349
* Default value for the timeout field in milliseconds.
4450
*/
@@ -1283,6 +1289,14 @@ typedef struct ddog_crasht_Slice_CharSlice {
12831289
uintptr_t len;
12841290
} ddog_crasht_Slice_CharSlice;
12851291

1292+
typedef struct ddog_crasht_EndpointConfig {
1293+
ddog_CharSlice url;
1294+
ddog_CharSlice api_key;
1295+
ddog_CharSlice test_token;
1296+
uint64_t timeout;
1297+
bool use_system_resolver;
1298+
} ddog_crasht_EndpointConfig;
1299+
12861300
typedef struct ddog_crasht_Slice_I32 {
12871301
/**
12881302
* Should be non-null and suitably aligned for the underlying type. It is
@@ -1305,7 +1319,7 @@ typedef struct ddog_crasht_Config {
13051319
* The endpoint to send the crash report to (can be a file://).
13061320
* If None, the crashtracker will infer the agent host from env variables.
13071321
*/
1308-
ddog_CharSlice endpoint;
1322+
struct ddog_crasht_EndpointConfig endpoint;
13091323
/**
13101324
* Optional filename for a unix domain socket if the receiver is used asynchonously
13111325
*/

components-rs/ddtrace.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ void ddtrace_drop_rust_string(char *input, uintptr_t len);
3939

4040
struct ddog_Endpoint *ddtrace_parse_agent_url(ddog_CharSlice url);
4141

42+
void ddtrace_endpoint_as_crashtracker_config(const struct ddog_Endpoint *endpoint,
43+
void (*callback)(ddog_crasht_EndpointConfig, void*),
44+
void *userdata);
45+
4246
ddog_Configurator *ddog_library_configurator_new_dummy(bool debug_logs, ddog_CharSlice language);
4347

4448
int posix_spawn_file_actions_addchdir_np(void *file_actions, const char *path);

components-rs/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,28 @@ pub unsafe extern "C" fn ddtrace_parse_agent_url(
101101
})
102102
}
103103

104+
#[no_mangle]
105+
#[cfg(unix)]
106+
pub unsafe extern "C" fn ddtrace_endpoint_as_crashtracker_config(
107+
endpoint: &Endpoint,
108+
callback: unsafe extern "C" fn(EndpointConfig<'_>, *mut std::ffi::c_void),
109+
userdata: *mut std::ffi::c_void,
110+
) {
111+
let url_str = endpoint.url.to_string();
112+
unsafe {
113+
callback(
114+
EndpointConfig {
115+
url: CharSlice::from(url_str.as_str()),
116+
api_key: CharSlice::from(endpoint.api_key.as_deref().unwrap_or("")),
117+
test_token: CharSlice::from(endpoint.test_token.as_deref().unwrap_or("")),
118+
timeout: endpoint.timeout_ms,
119+
use_system_resolver: endpoint.use_system_resolver,
120+
},
121+
userdata,
122+
);
123+
}
124+
}
125+
104126
// Hack: Without this, the PECL build of the tracer does not contain the ddog_library_* functions
105127
// It works well without in the "normal" build
106128
#[no_mangle]

components-rs/sidecar.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ use std::ops::DerefMut;
44
use std::os::unix::ffi::OsStrExt;
55
use lazy_static::{lazy_static, LazyStatic};
66
use tracing::warn;
7-
#[cfg(windows)]
8-
use std::os::windows::ffi::OsStrExt;
97
use std::sync::Mutex;
108
use std::time::Duration;
119
use datadog_sidecar::config::{self, AppSecConfig, LogMethod};

components-rs/telemetry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use hashbrown::{Equivalent, HashMap};
55
use std::collections::HashSet;
66
use std::ffi::CString;
77
use std::path::PathBuf;
8-
use std::time::{Duration, Instant, SystemTime};
8+
use std::time::{Duration, SystemTime};
99

1010
use datadog_ipc::platform::NamedShmHandle;
1111
use datadog_sidecar::one_way_shared_memory::{open_named_shm, OneWayShmReader};

ext/signals.c

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,20 @@ static void dd_crasht_add_opcache_inis(ddog_Vec_Tag *tags) {
242242
#endif
243243
}
244244

245+
typedef struct {
246+
ddog_crasht_Config config;
247+
ddog_crasht_Metadata metadata;
248+
} dd_crasht_init_args;
249+
250+
static void dd_crasht_do_init(ddog_crasht_EndpointConfig endpoint_config, void *userdata) {
251+
dd_crasht_init_args *args = (dd_crasht_init_args *)userdata;
252+
args->config.endpoint = endpoint_config;
253+
dd_crashtracker_check_result(
254+
ddog_crasht_init_without_receiver(args->config, args->metadata),
255+
"Cannot initialize CrashTracker"
256+
);
257+
}
258+
245259
static void dd_init_crashtracker() {
246260
ddog_CharSlice socket_path = ddog_sidecar_get_crashtracker_unix_socket_path();
247261
if (socket_path.len > sizeof(crashtracker_socket_path) - 1) {
@@ -256,32 +270,24 @@ static void dd_init_crashtracker() {
256270
free((void *) socket_path.ptr);
257271
socket_path.ptr = crashtracker_socket_path;
258272

259-
char *agent_url = ddtrace_agent_url();
260-
if (!agent_url) {
273+
if (!ddtrace_endpoint) {
261274
return;
262275
}
263276

264-
ddog_crasht_Config config = {
265-
.endpoint = {.ptr = agent_url, .len = strlen(agent_url)},
266-
.timeout_ms = 5000,
267-
.resolve_frames = DDOG_CRASHT_STACKTRACE_COLLECTION_ENABLED_WITH_INPROCESS_SYMBOLS,
268-
.optional_unix_socket_filename = socket_path,
269-
.additional_files = {0},
270-
};
271-
272277
ddog_Vec_Tag tags = ddog_Vec_Tag_new();
273278
dd_crasht_add_opcache_inis(&tags);
274279

275-
const ddog_crasht_Metadata metadata = ddtrace_setup_crashtracking_metadata(&tags);
280+
dd_crasht_init_args args = {
281+
.config = {
282+
.timeout_ms = 5000,
283+
.resolve_frames = DDOG_CRASHT_STACKTRACE_COLLECTION_ENABLED_WITH_INPROCESS_SYMBOLS,
284+
.optional_unix_socket_filename = socket_path,
285+
.additional_files = {0},
286+
},
287+
.metadata = ddtrace_setup_crashtracking_metadata(&tags),
288+
};
276289

277-
dd_crashtracker_check_result(
278-
ddog_crasht_init_without_receiver(
279-
config,
280-
metadata
281-
),
282-
"Cannot initialize CrashTracker"
283-
);
284-
free(agent_url);
290+
ddtrace_endpoint_as_crashtracker_config(ddtrace_endpoint, dd_crasht_do_init, &args);
285291

286292
ddtrace_register_crashtracking_frames_collection();
287293

0 commit comments

Comments
 (0)