Skip to content

Commit 3fbbd84

Browse files
committed
Add standalone datadog-ipc-helper binary
Extract the sidecar into a dedicated `datadog-ipc-helper` binary (new `components-rs/sidecar-bin` crate) that is located at runtime alongside the `ddtrace.so` path, removing the `php_shared_build` cfg flag and the old `php_sidecar_mockgen` crate entirely. Build script gains platform specific RUSTFLAGS for the sidecar binary: musl disables static CRT (needed for dlopen of the AppSec helper) and mac os switches fat LTO to thin LTO to work around problems with the llvm mac os linker.
1 parent f4ce0bf commit 3fbbd84

File tree

17 files changed

+217
-251
lines changed

17 files changed

+217
-251
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[workspace]
2-
members = ["components-rs", "components-rs/php_sidecar_mockgen", "profiling"]
2+
members = ["components-rs", "components-rs/sidecar-bin", "profiling"]
3+
exclude = ["tmp"]
34
resolver = "2"
45

56
[workspace.package]
@@ -25,6 +26,7 @@ codegen-units = 1
2526
panic = "abort"
2627
inherits = "release"
2728

29+
2830
[profile.profiler-release]
2931
panic = "abort"
3032
inherits = "release"

Makefile

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ BENCHMARK_EXTRA ?=
2222
COMPONENTS_BUILD_DIR = $(PROJECT_ROOT)/tmp/build_components
2323
SO_FILE = $(BUILD_DIR)/modules/ddtrace.so
2424
AR_FILE = $(BUILD_DIR)/modules/ddtrace.a
25+
SIDECAR_BIN_DEBUG = $(BUILD_DIR)/target/debug/datadog-ipc-helper
26+
SIDECAR_BIN_RELEASE = $(BUILD_DIR)/target/tracer-release/datadog-ipc-helper
27+
SIDECAR_BIN = $(if $(RUST_DEBUG_BUILD),$(SIDECAR_BIN_DEBUG),$(SIDECAR_BIN_RELEASE))
2528
WALL_FLAGS = -Wall -Wextra
2629
CFLAGS ?= $(shell [ -n "${DD_TRACE_DOCKER_DEBUG}" ] && echo -O0 || echo -O2) -g $(WALL_FLAGS)
2730
LDFLAGS ?=
@@ -48,7 +51,7 @@ RUN_TESTS_CMD := DD_SERVICE= DD_ENV= REPORT_EXIT_STATUS=1 TEST_PHP_SRCDIR=$(PROJ
4851

4952
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 }' )
5053
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-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")
54+
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-telemetry,libdd-telemetry-ffi,libdd-tinybytes,libdd-trace-*,spawn_worker,tools/cc_utils,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")
5255
ALL_OBJECT_FILES = $(C_FILES) $(RUST_FILES) $(BUILD_DIR)/Makefile
5356
TEST_OPCACHE_FILES = $(shell find tests/opcache -name '*.php*' -o -name '.gitkeep' | awk '{ printf "$(BUILD_DIR)/%s\n", $$1 }' )
5457
TEST_STUB_FILES = $(shell find tests/ext -type d -name 'stubs' -exec find '{}' -type f \; | awk '{ printf "$(BUILD_DIR)/%s\n", $$1 }' )
@@ -63,7 +66,9 @@ else
6366
SED_I = sed -i ''
6467
endif
6568

66-
all: $(BUILD_DIR)/configure $(SO_FILE)
69+
SIDECAR_BIN_IN_MODULES = $(BUILD_DIR)/modules/datadog-ipc-helper
70+
71+
all: $(BUILD_DIR)/configure $(SO_FILE) $(SIDECAR_BIN_IN_MODULES)
6772

6873
# The following differentiation exists so we can build only (but always) the relevant files while executing tests
6974
# - when a `.phpt` changes, we only copy the file to the build dir and we DO NOT rebuild
@@ -104,8 +109,6 @@ $(BUILD_DIR)/%: %
104109

105110
JUNIT_RESULTS_DIR := $(shell pwd)
106111

107-
all: $(BUILD_DIR)/configure $(SO_FILE)
108-
109112
$(BUILD_DIR)/configure: $(M4_FILES) $(BUILD_DIR)/ddtrace.sym $(BUILD_DIR)/VERSION
110113
$(Q) (cd $(BUILD_DIR); phpize && $(SED_I) 's/\/FAILED/\/\\bFAILED/' $(BUILD_DIR)/run-tests.php) # Fix PHP 5.4 exit code bug when running selected tests (FAILED vs XFAILED)
111114

@@ -116,16 +119,23 @@ $(BUILD_DIR)/run-tests.php: $(if $(ASSUME_COMPILED),, $(BUILD_DIR)/configure)
116119
$(BUILD_DIR)/Makefile: $(BUILD_DIR)/configure
117120
$(Q) (cd $(BUILD_DIR); $(if $(ASAN),CFLAGS="${CFLAGS} -DZEND_TRACK_ARENA_ALLOC") ./configure --$(if $(RUST_DEBUG_BUILD),enable,disable)-ddtrace-rust-debug $(if $(ASAN), --enable-ddtrace-sanitize) $(EXTRA_CONFIGURE_OPTIONS))
118121

122+
119123
$(SO_FILE): $(if $(ASSUME_COMPILED),, $(ALL_OBJECT_FILES) $(BUILD_DIR)/compile_rust.sh)
120124
$(if $(ASSUME_COMPILED),,$(Q) $(MAKE) -C $(BUILD_DIR) -j)
121125

126+
$(SIDECAR_BIN_IN_MODULES): $(SO_FILE)
127+
$(Q) cp $(SIDECAR_BIN) $@
128+
122129
$(AR_FILE): $(ALL_OBJECT_FILES)
123130
$(Q) $(MAKE) -C $(BUILD_DIR) -j ./modules/ddtrace.a all
124131

125132
$(PHP_EXTENSION_DIR)/ddtrace.so: $(SO_FILE)
126133
$(Q) $(SUDO) $(if $(ASSUME_COMPILED),cp $(BUILD_DIR)/modules/ddtrace.so $(PHP_EXTENSION_DIR)/ddtrace.so,$(MAKE) -C $(BUILD_DIR) install)
127134

128-
install: $(PHP_EXTENSION_DIR)/ddtrace.so
135+
$(PHP_EXTENSION_DIR)/datadog-ipc-helper: $(SIDECAR_BIN)
136+
$(Q) $(SUDO) cp $(SIDECAR_BIN) $(PHP_EXTENSION_DIR)/datadog-ipc-helper
137+
138+
install: $(PHP_EXTENSION_DIR)/ddtrace.so $(PHP_EXTENSION_DIR)/datadog-ipc-helper
129139

130140
set_static_option:
131141
$(eval EXTRA_CONFIGURE_OPTIONS := --enable-ddtrace-rust-library-split)

appsec/tests/integration/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,14 @@ def buildTracerTask = { String version, String variant, altBaseTag = null ->
345345
],
346346
outputs: [
347347
volume: 'php-tracer',
348-
files: ['build_extension/modules/ddtrace.so'],
348+
files: ['build_extension/modules/ddtrace.so',
349+
'build_extension/modules/datadog-ipc-helper'],
349350
],
350351
command: [
351352
'-e', '-c',
352353
'''
353354
cd /project
354-
PHPRC= RUST_DEBUG_BUILD=1 make /project/tmp/build_extension/modules/ddtrace.so
355+
PHPRC= RUST_DEBUG_BUILD=1 make
355356
'''
356357
]
357358
)

compile_rust.sh

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,47 @@ cd components-rs
33

44
RUSTFLAGS="${RUSTFLAGS:-} --cfg tokio_unstable"
55

6-
if test -n "$SHARED"; then
7-
RUSTFLAGS="$RUSTFLAGS --cfg php_shared_build"
8-
fi
9-
106
case "${host_os}" in
117
darwin*)
128
RUSTFLAGS="$RUSTFLAGS -Clink-arg=-undefined -Clink-arg=dynamic_lookup";
139
;;
1410
esac
1511

16-
set -x
12+
set -ex
1713

1814
if test -n "$COMPILE_ASAN"; then
1915
# We need -lresolv due to https://github.com/llvm/llvm-project/issues/59007
2016
export LDFLAGS="-fsanitize=address $(if cc -v 2>&1 | grep -q clang; then echo "-shared-libsan -lresolv"; fi)"
2117
export CFLAGS="$LDFLAGS -fno-omit-frame-pointer" # the cc buildtools will only pick up CFLAGS it seems
2218
fi
2319

24-
SIDECAR_VERSION=$(cat ../VERSION) RUSTFLAGS="$RUSTFLAGS" RUSTC_BOOTSTRAP=1 "${DDTRACE_CARGO:-cargo}" build $(test "${PROFILE:-debug}" = "debug" || echo --profile "$PROFILE") "$@"
20+
# Choose the cargo profile.
21+
if test "${PROFILE:-debug}" = "debug"; then
22+
CARGO_PROFILE_ARG=""
23+
else
24+
CARGO_PROFILE_ARG="--profile $PROFILE"
25+
fi
26+
27+
CARGO_TARGET_DIR="${CARGO_TARGET_DIR:?CARGO_TARGET_DIR must be set}"
28+
29+
# Sidecar-specific RUSTFLAGS.
30+
# - musl: disable static CRT so dlopen works for loading the AppSec helper.
31+
# - macOS: override fat LTO (from tracer-release) to thin LTO, because the
32+
# Xcode system linker ships an older LLVM that cannot parse the bitcode
33+
# produced by the Rust toolchain's fat-LTO mode.
34+
SIDECAR_RUSTFLAGS="$RUSTFLAGS"
35+
case "${host_os}" in
36+
*musl*)
37+
SIDECAR_RUSTFLAGS="$SIDECAR_RUSTFLAGS -C target-feature=-crt-static"
38+
;;
39+
darwin*)
40+
SIDECAR_RUSTFLAGS="$SIDECAR_RUSTFLAGS -C lto=thin"
41+
;;
42+
esac
43+
44+
SIDECAR_VERSION=$(cat ../VERSION) RUSTFLAGS="$RUSTFLAGS" RUSTC_BOOTSTRAP=1 \
45+
"${DDTRACE_CARGO:-cargo}" build -p ddtrace-php $CARGO_PROFILE_ARG "$@"
46+
47+
SIDECAR_VERSION=$(cat ../VERSION) RUSTFLAGS="$SIDECAR_RUSTFLAGS" RUSTC_BOOTSTRAP=1 \
48+
"${DDTRACE_CARGO:-cargo}" build -p datadog-ipc-helper $CARGO_PROFILE_ARG "$@"
49+

components-rs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ hashbrown = "0.15"
5555
cbindgen = "0.27"
5656

5757
[lints.rust]
58-
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(php_shared_build)'] }
58+
unexpected_cfgs = { level = "warn", check-cfg = [] }

components-rs/ddtrace.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ extern ddog_VecRemoteConfigProduct DDTRACE_REMOTE_CONFIG_PRODUCTS;
1717

1818
extern ddog_VecRemoteConfigCapabilities DDTRACE_REMOTE_CONFIG_CAPABILITIES;
1919

20-
extern const uint8_t *DDOG_PHP_FUNCTION;
21-
2220
extern struct ddog_SidecarTransport *ddtrace_sidecar;
2321

2422
/**

components-rs/php_sidecar_mockgen/Cargo.toml

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)