Skip to content

Commit bf53bdf

Browse files
authored
No longer compile the mockgen as part of the rust build (#2512)
* No longer compile the mockgen as part of the rust build Instead we run a separate rust executable to produce it, and it will be included as a normal .c file in the ddtrace C build This will allow us to compile the sidecar once for all versions as well as have the debug symbols for the sidecar just once Signed-off-by: Bob Weinand <[email protected]> * Allow separate compilation of Rust artifacts Signed-off-by: Bob Weinand <[email protected]> * Compress debug sections Export full debug symbols of sidecar (for a 50% artifact siye overhead, instead of 500%) Signed-off-by: Bob Weinand <[email protected]> --------- Signed-off-by: Bob Weinand <[email protected]>
1 parent 39eb121 commit bf53bdf

File tree

13 files changed

+221
-107
lines changed

13 files changed

+221
-107
lines changed

.circleci/continue_config.yml

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ commands:
550550
cargo build --release
551551
cd -
552552
cp -v "${CARGO_TARGET_DIR}/release/libdatadog_php_profiling.so" "${prefix}/datadog-profiling.so"
553+
objcopy --compress-debug-sections "${prefix}/datadog-profiling.so"
553554
- run:
554555
name: Build Profiler ZTS
555556
command: |
@@ -568,6 +569,7 @@ commands:
568569
cargo build --release
569570
cd -
570571
cp -v "${CARGO_TARGET_DIR}/release/libdatadog_php_profiling.so" "${prefix}/datadog-profiling-zts.so"
572+
objcopy --compress-debug-sections "${prefix}/datadog-profiling-zts.so"
571573
572574
executors:
573575
with_agent:
@@ -756,7 +758,7 @@ jobs:
756758
name: Run unit tests with xdebug
757759
command: |
758760
if [[ "<<parameters.xdebug_version_one>>" != "2.7.2" ]]; then
759-
TEST_EXTRA_INI='-d zend_extension=xdebug-<< parameters.xdebug_version_one >>.so' make test_unit RUST_DEBUG_SYMBOLS=1 PHPUNIT_OPTS="--log-junit test-results/php-unit/results_unit.xml"
761+
TEST_EXTRA_INI='-d zend_extension=xdebug-<< parameters.xdebug_version_one >>.so' make test_unit RUST_DEBUG_BUILD=1 PHPUNIT_OPTS="--log-junit test-results/php-unit/results_unit.xml"
760762
fi
761763
- <<: *STEP_STORE_TEST_RESULTS
762764

@@ -801,7 +803,7 @@ jobs:
801803
name: Run tests
802804
command: |
803805
set -euo pipefail
804-
make << parameters.make_target >> RUST_DEBUG_SYMBOLS=1 PHPUNIT_OPTS="--log-junit test-results/php-unit/results.xml" 2>&1 | tee /dev/stderr | { ! grep -qe "=== Total [0-9]+ memory leaks detected ==="; }
806+
make << parameters.make_target >> RUST_DEBUG_BUILD=1 PHPUNIT_OPTS="--log-junit test-results/php-unit/results.xml" 2>&1 | tee /dev/stderr | { ! grep -qe "=== Total [0-9]+ memory leaks detected ==="; }
805807
rm -rf tmp/build_extension/tests/opcache/file_cache/* || true
806808
- <<: *STEP_STORE_TEST_RESULTS
807809
- run:
@@ -851,7 +853,7 @@ jobs:
851853
name: Run tests
852854
command: |
853855
set -euo pipefail
854-
DD_TRACE_SIDECAR_TRACE_SENDER=1 make test_c RUST_DEBUG_SYMBOLS=1 PHPUNIT_OPTS="--log-junit test-results/php-unit/results.xml" TESTS=tests/ext/background-sender 2>&1 | tee /dev/stderr | { ! grep -qe "=== Total [0-9]+ memory leaks detected ==="; }
856+
DD_TRACE_SIDECAR_TRACE_SENDER=1 make test_c RUST_DEBUG_BUILD=1 PHPUNIT_OPTS="--log-junit test-results/php-unit/results.xml" TESTS=tests/ext/background-sender 2>&1 | tee /dev/stderr | { ! grep -qe "=== Total [0-9]+ memory leaks detected ==="; }
855857
- <<: *STEP_STORE_TEST_RESULTS
856858
- run:
857859
command: |
@@ -897,7 +899,7 @@ jobs:
897899
name: Run tests
898900
command: |
899901
set -euo pipefail
900-
make test_c_observer RUST_DEBUG_SYMBOLS=1 PHPUNIT_OPTS="--log-junit test-results/php-unit/results.xml" 2>&1 | tee /dev/stderr | { ! grep -qe "=== Total [0-9]+ memory leaks detected ==="; }
902+
make test_c_observer RUST_DEBUG_BUILD=1 PHPUNIT_OPTS="--log-junit test-results/php-unit/results.xml" 2>&1 | tee /dev/stderr | { ! grep -qe "=== Total [0-9]+ memory leaks detected ==="; }
901903
- <<: *STEP_STORE_TEST_RESULTS
902904
- run:
903905
command: |
@@ -954,7 +956,7 @@ jobs:
954956
-e PHP_VARIANT=<< parameters.switch_php_version >> \
955957
-e PHPUNIT_OPTS="--log-junit test-results/php-unit/results.xml" \
956958
<< parameters.php_major_minor >>-buster-arm64 \
957-
./tooling/bin/run-in-docker-with-ext.sh make fix_socket_permissions << parameters.make_target >> RUST_DEBUG_SYMBOLS=1
959+
./tooling/bin/run-in-docker-with-ext.sh make fix_socket_permissions << parameters.make_target >> RUST_DEBUG_BUILD=1
958960
# - <<: *STEP_COMPOSER_TESTS_UPDATE
959961
# - <<: *STEP_PREPARE_TEST_RESULTS_DIR
960962
# - <<: *STEP_EXPORT_CI_ENV
@@ -1009,7 +1011,7 @@ jobs:
10091011
command: |
10101012
set -euo pipefail
10111013
if [[ << parameters.switch_php_version >> == *asan* ]]; then export TEST_PHP_JUNIT=$(pwd)/asan-extension-test.xml; fi
1012-
make << parameters.make_target >> RUST_DEBUG_SYMBOLS=1 2>&1 | tee /dev/stderr | { ! grep -qe "=== Total [0-9]+ memory leaks detected ==="; }
1014+
make << parameters.make_target >> RUST_DEBUG_BUILD=1 2>&1 | tee /dev/stderr | { ! grep -qe "=== Total [0-9]+ memory leaks detected ==="; }
10131015
- when:
10141016
# codecov uploader only on amd64
10151017
condition:
@@ -1565,7 +1567,7 @@ jobs:
15651567
- <<: *STEP_WAIT_TEST_AGENT
15661568
- run:
15671569
name: Run tests
1568-
command: DD_TRACE_AGENT_TIMEOUT=1000 <<# parameters.disable_runner_distributed_tracing >> DD_DISTRIBUTED_TRACING=false <</ parameters.disable_runner_distributed_tracing >> DD_TRACE_TEST_SAPI=<< parameters.sapi >> make << parameters.make_target >> RUST_DEBUG_SYMBOLS=1 PHPUNIT_OPTS="--log-junit test-results/php-composer/results.xml"
1570+
command: DD_TRACE_AGENT_TIMEOUT=1000 <<# parameters.disable_runner_distributed_tracing >> DD_DISTRIBUTED_TRACING=false <</ parameters.disable_runner_distributed_tracing >> DD_TRACE_TEST_SAPI=<< parameters.sapi >> make << parameters.make_target >> RUST_DEBUG_BUILD=1 PHPUNIT_OPTS="--log-junit test-results/php-composer/results.xml"
15691571
- when:
15701572
# codecov uploader only on amd64
15711573
condition:
@@ -1737,7 +1739,7 @@ jobs:
17371739
- <<: *STEP_WAIT_TEST_AGENT
17381740
- run:
17391741
name: Run << parameters.integration_testsuite >> integration test
1740-
command: DD_TRACE_AGENT_TIMEOUT=1000 <<# parameters.disable_runner_distributed_tracing >> DD_DISTRIBUTED_TRACING=false <</ parameters.disable_runner_distributed_tracing >> DD_TRACE_TEST_SAPI=<< parameters.sapi >> make << parameters.integration_testsuite >> RUST_DEBUG_SYMBOLS=1
1742+
command: DD_TRACE_AGENT_TIMEOUT=1000 <<# parameters.disable_runner_distributed_tracing >> DD_DISTRIBUTED_TRACING=false <</ parameters.disable_runner_distributed_tracing >> DD_TRACE_TEST_SAPI=<< parameters.sapi >> make << parameters.integration_testsuite >> RUST_DEBUG_BUILD=1
17411743
- run:
17421744
command: |
17431745
mkdir -p /tmp/artifacts
@@ -1790,7 +1792,7 @@ jobs:
17901792
name: Run << parameters.ext_name >> integration tests with ext/<< parameters.ext_name >> as shared lib + leak detection
17911793
command: |
17921794
make test_extension_ci \
1793-
RUST_DEBUG_SYMBOLS=1 \
1795+
RUST_DEBUG_BUILD=1 \
17941796
BUILD_DIR=$(pwd)/tmp/build_extension \
17951797
JUNIT_RESULTS_DIR=$(pwd)/test-results \
17961798
RUN_TESTS_EXTRA_ARGS="-d extension=mbstring.so -d extension=<< parameters.ext_name >>.so" \
@@ -1800,7 +1802,7 @@ jobs:
18001802
for curlVersion in 7.72.0 7.77.0
18011803
do
18021804
make test_c \
1803-
RUST_DEBUG_SYMBOLS=1 \
1805+
RUST_DEBUG_BUILD=1 \
18041806
BUILD_DIR=$(pwd)/tmp/build_extension \
18051807
JUNIT_RESULTS_DIR=$(pwd)/test-results \
18061808
RUN_TESTS_EXTRA_ARGS="-d extension=mbstring.so -d extension=<< parameters.ext_name >>-${curlVersion}.so" \
@@ -2646,6 +2648,13 @@ jobs:
26462648
fi
26472649
build-dd-trace-php
26482650
mv extensions extensions_$(uname -m)
2651+
- run:
2652+
name: Compress debug info
2653+
command: |
2654+
cd extensions_$(uname -m)
2655+
for FILE in $(find . -name "*.so"); do
2656+
objcopy --compress-debug-sections $FILE
2657+
done
26492658
- persist_to_workspace:
26502659
root: '.'
26512660
paths: ['./extensions_*']
@@ -2676,8 +2685,15 @@ jobs:
26762685
command: |
26772686
set -eo pipefail
26782687
switch-php debug-zts-asan
2679-
make RUST_DEBUG_SYMBOLS=1
2688+
make RUST_DEBUG_BUILD=1
26802689
cp -v tmp/build_extension/.libs/ddtrace.so extensions_$(uname -m)/ddtrace-<< parameters.so_suffix >>-debug-zts.so
2690+
- run:
2691+
name: Compress debug info
2692+
command: |
2693+
cd extensions_$(uname -m)
2694+
for FILE in $(find . -name "*.so"); do
2695+
objcopy --compress-debug-sections $FILE
2696+
done
26812697
- persist_to_workspace:
26822698
root: '.'
26832699
paths: ['./extensions_*']
@@ -2871,6 +2887,13 @@ jobs:
28712887
switch-php << parameters.php_version >>-zts
28722888
make clean && make -j all ECHO_ARG="-e" CFLAGS="-std=gnu11 -O2 -g -Wall -Wextra <<# parameters.catch_warnings >> -Werror <</ parameters.catch_warnings >>"
28732889
cp -v tmp/build_extension/.libs/ddtrace.so extensions_$(uname -m)/ddtrace-<< parameters.so_suffix >>-zts.so
2890+
- run:
2891+
name: Compress debug info
2892+
command: |
2893+
cd extensions_$(uname -m)
2894+
for FILE in $(find . -name "*.so"); do
2895+
objcopy --compress-debug-sections $FILE
2896+
done
28742897
- persist_to_workspace:
28752898
root: '.'
28762899
paths: [ './extensions_*' ]
@@ -2918,6 +2941,13 @@ jobs:
29182941
mkdir -p appsec/build-release-zts ; cd appsec/build-release-zts
29192942
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDD_APPSEC_BUILD_HELPER=OFF -DDD_APPSEC_TESTING=OFF ; make -j $(nproc)
29202943
cp -v ddappsec.so ../../appsec_$(uname -m)/ddappsec-$PHP_API-zts.so
2944+
- run:
2945+
name: Compress debug info
2946+
command: |
2947+
cd appsec_$(uname -m)
2948+
for FILE in $(find . -name "*.so"); do
2949+
objcopy --compress-debug-sections $FILE
2950+
done
29212951
- persist_to_workspace:
29222952
root: '.'
29232953
paths: [ './appsec_*' ]
@@ -2949,6 +2979,13 @@ jobs:
29492979
mkdir -p appsec/build ; cd appsec/build
29502980
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDD_APPSEC_BUILD_HELPER=OFF -DDD_APPSEC_TESTING=OFF ; make -j $(nproc)
29512981
cp -v ddappsec.so ../../appsec_$(uname -m)/ddappsec-$PHP_API-alpine.so
2982+
- run:
2983+
name: Compress debug info
2984+
command: |
2985+
cd appsec_$(uname -m)
2986+
for FILE in $(find . -name "*.so"); do
2987+
objcopy --compress-debug-sections $FILE
2988+
done
29522989
- persist_to_workspace:
29532990
root: '.'
29542991
paths: [ './appsec_*' ]
@@ -2979,6 +3016,7 @@ jobs:
29793016
mkdir -p appsec/build ; cd appsec/build
29803017
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDD_APPSEC_BUILD_EXTENSION=OFF -DCMAKE_TOOLCHAIN_FILE=$(pwd)/../cmake/Toolchain.$(uname -m).cmake
29813018
make -j $(nproc)
3019+
objcopy --compress-debug-sections ddappsec-helper
29823020
cp -v ddappsec-helper ../../appsec_$(uname -m)/ddappsec-helper
29833021
- run:
29843022
name: Test

Cargo.lock

Lines changed: 15 additions & 9 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["components-rs", "profiling"]
2+
members = ["components-rs", "components-rs/php_sidecar_mockgen", "profiling"]
33
resolver = "2"
44

55
[workspace.package]

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ PHP_EXTENSION_DIR = $(shell ASAN_OPTIONS=detect_leaks=0 php -r 'print ini_get("e
1818
PHP_MAJOR_MINOR = $(shell ASAN_OPTIONS=detect_leaks=0 php -r 'echo PHP_MAJOR_VERSION . PHP_MINOR_VERSION;')
1919
ARCHITECTURE = $(shell uname -m)
2020
QUIET_TESTS := ${CIRCLE_SHA1}
21-
RUST_DEBUG_SYMBOLS ?= $(shell [ -n "${DD_TRACE_DOCKER_DEBUG}" ] && echo 1)
21+
RUST_DEBUG_BUILD ?= $(shell [ -n "${DD_TRACE_DOCKER_DEBUG}" ] && echo 1)
2222

2323
VERSION := $(shell awk -F\' '/const VERSION/ {print $$2}' < src/DDTrace/Tracer.php)
2424
PROFILING_RELEASE_URL := https://github.com/DataDog/dd-prof-php/releases/download/v0.7.2/datadog-profiling.tar.gz
@@ -85,9 +85,9 @@ $(BUILD_DIR)/configure: $(M4_FILES) $(BUILD_DIR)/ddtrace.sym
8585
$(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)
8686

8787
$(BUILD_DIR)/Makefile: $(BUILD_DIR)/configure
88-
$(Q) (cd $(BUILD_DIR); ./configure --$(if $(RUST_DEBUG_SYMBOLS),enable,disable)-ddtrace-rust-debug --$(if $(RUST_DEBUG_SYMBOLS),enable,disable)-ddtrace-rust-symbols)
88+
$(Q) (cd $(BUILD_DIR); ./configure --$(if $(RUST_DEBUG_BUILD),enable,disable)-ddtrace-rust-debug)
8989

90-
$(SO_FILE): $(C_FILES) $(RUST_FILES) $(BUILD_DIR)/Makefile
90+
$(SO_FILE): $(C_FILES) $(RUST_FILES) $(BUILD_DIR)/Makefile $(BUILD_DIR)/compile_rust.sh
9191
$(Q) $(MAKE) -C $(BUILD_DIR) -j CFLAGS="$(CFLAGS)$(if $(ASAN), -fsanitize=address)" LDFLAGS="$(LDFLAGS)$(if $(ASAN), -fsanitize=address)"
9292

9393
$(PHP_EXTENSION_DIR)/ddtrace.so: $(SO_FILE)

compile_rust.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
cd components-rs
3+
4+
RUSTFLAGS="${RUSTFLAGS:-} --cfg tokio_unstable"
5+
if if test -z "${host_os:-}"; then case "${host_os}" in linux*) true;; *) false; esac else test "$(uname -s)" = "Linux"; fi then
6+
RUSTFLAGS="$RUSTFLAGS --cfg tokio_taskdump"
7+
fi
8+
if test -n "$SHARED"; then
9+
RUSTFLAGS="$RUSTFLAGS --cfg php_shared_build"
10+
fi
11+
12+
RUSTFLAGS="$RUSTFLAGS" RUSTC_BOOTSTRAP=1 "${DDTRACE_CARGO:-cargo}" build $(test "${PROFILE:-debug}" = "debug" || echo --profile "$PROFILE") "$@"

components-rs/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,3 @@ tracing-subscriber = { version = "0.3", default-features = false, features = [
3333

3434
[build-dependencies]
3535
cbindgen = "0.24"
36-
cc_utils = { path = "../libdatadog/tools/cc_utils" }
37-
sidecar_mockgen = { path = "../libdatadog/tools/sidecar_mockgen" }

components-rs/build.rs

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
edition = "2021"
3+
name = "php_sidecar_mockgen"
4+
version = "0.1.0"
5+
6+
[dependencies]
7+
cc_utils = { path = "../../libdatadog/tools/cc_utils" }
8+
sidecar_mockgen = { path = "../../libdatadog/tools/sidecar_mockgen" }
9+
10+
[[bin]]
11+
name = "php_sidecar_mockgen"

0 commit comments

Comments
 (0)