Skip to content

Commit

Permalink
Compile sidecar and extension separately, to link them together later (
Browse files Browse the repository at this point in the history
…#2741)

* Compile sidecar and extension separately, to link them together later

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>

* Make the loader loads libddtrace_php.so if found in the package directory

* Add missing CFLAGS for linking

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>

* Also include alpine

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>

---------

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
Co-authored-by: iamluc <luc.vieillescazes@datadoghq.com>
  • Loading branch information
bwoebi and iamluc committed Jul 5, 2024
1 parent 3cdc077 commit 4ab0eb7
Show file tree
Hide file tree
Showing 12 changed files with 325 additions and 111 deletions.
238 changes: 202 additions & 36 deletions .circleci/continue_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2713,6 +2713,31 @@ jobs:
- store_artifacts:
path: /tmp/artifacts

compile_rust_alpine:
working_directory: ~/datadog
parameters:
resource_class:
type: string
default: large
<<: *BARE_DOCKER_MACHINE
steps:
- restore_cache:
keys:
- source-v1-{{ .Branch }}-{{ .Revision }}
- <<: *STEP_CHECKOUT
- <<: *STEP_ATTACH_WORKSPACE
- setup_docker:
docker_image: datadog/dd-trace-ci:php-compile-extension-alpine
- run:
name: Compile sidecar
command: |
SHARED=1 PROFILE=tracer-release host_os=linux-musl ./compile_rust.sh
cp -v ${CARGO_TARGET_DIR:-target}/tracer-release/libddtrace_php.a libddtrace_php_$(uname -m)-alpine.a
objcopy --compress-debug-sections ${CARGO_TARGET_DIR:-target}/tracer-release/libddtrace_php.so libddtrace_php_$(uname -m)-alpine.so
- persist_to_workspace:
root: '.'
paths: [ './libddtrace_php_*.*' ]

compile_alpine:
working_directory: ~/datadog
parameters:
Expand All @@ -2731,29 +2756,28 @@ jobs:
- <<: *STEP_ATTACH_WORKSPACE
- setup_docker:
docker_image: datadog/dd-trace-ci:php-compile-extension-alpine-<< parameters.php_major_minor >>
- run: mkdir -p extensions_$(uname -m) standalone_$(uname -m)
- run:
name: Build nts extension
command: |
build-dd-trace-php
make -j static CFLAGS="-std=gnu11 -O2 -g -Wall -Wextra -Werror -Wno-error=return-local-addr" ECHO_ARG="-e"
objcopy --compress-debug-sections tmp/build_extension/modules/ddtrace.so standalone_$(uname -m)/ddtrace-${PHP_API}-alpine.so
cp -v tmp/build_extension/modules/ddtrace.a extensions_$(uname -m)/ddtrace-${PHP_API}-alpine.a
if [ "<< parameters.php_major_minor >>" = "7.0" ]; then
cp -v tmp/build_extension/ddtrace.ldflags ddtrace_$(uname -m)-alpine.ldflags
fi
- run:
name: Build zts extension
command: |
. /root/.bashrc
switch_php zts
rm -r tmp/build_extension
build-dd-trace-php
- run:
name: Compress debug info
command: |
pushd extensions
for FILE in $(find . -name "*.so"); do
objcopy --compress-debug-sections $FILE
done
popd
mv extensions extensions_$(uname -m)
make -j static CFLAGS="-std=gnu11 -O2 -g -Wall -Wextra -Werror -Wno-error=return-local-addr" ECHO_ARG="-e"
objcopy --compress-debug-sections tmp/build_extension/modules/ddtrace.so standalone_$(uname -m)/ddtrace-${PHP_API}-alpine-zts.so
cp -v tmp/build_extension/modules/ddtrace.a extensions_$(uname -m)/ddtrace-${PHP_API}-alpine-zts.a
- persist_to_workspace:
root: '.'
paths: ['./extensions_*']
paths: [ './extensions_*', './standalone_*', 'ddtrace_*.ldflags' ]

compile_extension_asan:
working_directory: ~/datadog
Expand Down Expand Up @@ -2782,7 +2806,7 @@ jobs:
set -eo pipefail
switch-php debug-zts-asan
make RUST_DEBUG_BUILD=1
cp -v tmp/build_extension/.libs/ddtrace.so extensions_$(uname -m)/ddtrace-<< parameters.so_suffix >>-debug-zts.so
cp -v tmp/build_extension/modules/ddtrace.so extensions_$(uname -m)/ddtrace-<< parameters.so_suffix >>-debug-zts.so
- run:
name: Compress debug info
command: |
Expand Down Expand Up @@ -3073,6 +3097,32 @@ jobs:
cp modules/dd_library_loader-$(uname -m)-linux-musl.so modules/dd_library_loader.so
./bin/test.sh
compile_rust_centos:
working_directory: ~/datadog
parameters:
resource_class:
type: string
default: large
<<: *BARE_DOCKER_MACHINE
steps:
- restore_cache:
keys:
- source-v1-{{ .Branch }}-{{ .Revision }}
- <<: *STEP_CHECKOUT
- <<: *STEP_ATTACH_WORKSPACE
- setup_docker:
docker_image: datadog/dd-trace-ci:centos-7
- run:
name: Compile sidecar
command: |
set +eo pipefail; source scl_source enable devtoolset-7; set -eo pipefail
SHARED=1 PROFILE=tracer-release host_os=linux-gnu ./compile_rust.sh
cp -v ${CARGO_TARGET_DIR:-target}/tracer-release/libddtrace_php.a libddtrace_php_$(uname -m).a
objcopy --compress-debug-sections ${CARGO_TARGET_DIR:-target}/tracer-release/libddtrace_php.so libddtrace_php_$(uname -m).so
- persist_to_workspace:
root: '.'
paths: [ './libddtrace_php_*.*' ]

compile_extension_centos:
working_directory: ~/datadog
parameters:
Expand All @@ -3089,6 +3139,9 @@ jobs:
default: true
php_version:
type: string
persist_ldflags:
type: boolean
default: false
<<: *BARE_DOCKER_MACHINE
steps:
- restore_cache:
Expand All @@ -3098,35 +3151,67 @@ jobs:
- <<: *STEP_ATTACH_WORKSPACE
- setup_docker:
docker_image: << parameters.docker_image >>
- run: mkdir -p extensions_$(uname -m)
- run: mkdir -p extensions_$(uname -m) standalone_$(uname -m)
- run:
name: Build ndebug, nts configuration
command: |
set +eo pipefail; source scl_source enable devtoolset-7; set -eo pipefail
switch-php << parameters.php_version >>
make clean && make -j all ECHO_ARG="-e" CFLAGS="-std=gnu11 -O2 -g -Wall -Wextra <<# parameters.catch_warnings >> -Werror <</ parameters.catch_warnings >>"
cp -v tmp/build_extension/.libs/ddtrace.so extensions_$(uname -m)/ddtrace-<< parameters.so_suffix >>.so
make clean && make -j static ECHO_ARG="-e" CFLAGS="-std=gnu11 -O2 -g -Wall -Wextra <<# parameters.catch_warnings >> -Werror <</ parameters.catch_warnings >>"
objcopy --compress-debug-sections tmp/build_extension/modules/ddtrace.so standalone_$(uname -m)/ddtrace-<< parameters.so_suffix >>.so
cp -v tmp/build_extension/modules/ddtrace.a extensions_$(uname -m)/ddtrace-<< parameters.so_suffix >>.a
<<# parameters.persist_ldflags >> cp -v tmp/build_extension/ddtrace.ldflags ddtrace_$(uname -m).ldflags <</ parameters.persist_ldflags >>
- run:
name: Build debug, nts configuration
command: |
set +eo pipefail; source scl_source enable devtoolset-7; set -eo pipefail
switch-php << parameters.php_version >>-debug
make clean && make -j all ECHO_ARG="-e" CFLAGS="-std=gnu11 -O0 -g -Wall -Wextra <<# parameters.catch_warnings >> -Werror <</ parameters.catch_warnings >>"
cp -v tmp/build_extension/.libs/ddtrace.so extensions_$(uname -m)/ddtrace-<< parameters.so_suffix >>-debug.so
make clean && make -j static ECHO_ARG="-e" CFLAGS="-std=gnu11 -O0 -g -Wall -Wextra <<# parameters.catch_warnings >> -Werror <</ parameters.catch_warnings >>"
objcopy --compress-debug-sections tmp/build_extension/modules/ddtrace.so standalone_$(uname -m)/ddtrace-<< parameters.so_suffix >>-debug.so
cp -v tmp/build_extension/modules/ddtrace.a extensions_$(uname -m)/ddtrace-<< parameters.so_suffix >>-debug.a
- run:
name: Build zts configuration
command: |
set +eo pipefail; source scl_source enable devtoolset-7; set -eo pipefail
switch-php << parameters.php_version >>-zts
make clean && make -j all ECHO_ARG="-e" CFLAGS="-std=gnu11 -O2 -g -Wall -Wextra <<# parameters.catch_warnings >> -Werror <</ parameters.catch_warnings >>"
cp -v tmp/build_extension/.libs/ddtrace.so extensions_$(uname -m)/ddtrace-<< parameters.so_suffix >>-zts.so
make clean && make -j static ECHO_ARG="-e" CFLAGS="-std=gnu11 -O2 -g -Wall -Wextra <<# parameters.catch_warnings >> -Werror <</ parameters.catch_warnings >>"
objcopy --compress-debug-sections tmp/build_extension/modules/ddtrace.so standalone_$(uname -m)/ddtrace-<< parameters.so_suffix >>-zts.so
cp -v tmp/build_extension/modules/ddtrace.a extensions_$(uname -m)/ddtrace-<< parameters.so_suffix >>-zts.a
- persist_to_workspace:
root: '.'
paths: [ './extensions_*', './standalone_*', 'ddtrace_*.ldflags' ]

link_extension:
working_directory: ~/datadog
parameters:
resource_class:
type: string
default: xlarge
docker_image:
type: string
libddtrace_suffix:
type: string
default: ""
<<: *BARE_DOCKER_MACHINE
steps:
- restore_cache:
keys:
- source-v1-{{ .Branch }}-{{ .Revision }}
- <<: *STEP_CHECKOUT
- <<: *STEP_ATTACH_WORKSPACE
- setup_docker:
docker_image: << parameters.docker_image >>
- run:
name: Compress debug info
name: Link sidecar and extension
command: |
cd extensions_$(uname -m)
for FILE in $(find . -name "*.so"); do
objcopy --compress-debug-sections $FILE
sed -i 's/-export-symbols .*\/ddtrace\.sym/-Wl,--retain-symbols-file=ddtrace.sym/g' ddtrace_$(uname -m)<< parameters.libddtrace_suffix >>.ldflags
for archive in extensions_$(uname -m)/*.a; do
(
gcc -shared -Wl,-whole-archive $archive -Wl,-no-whole-archive $(cat ddtrace_$(uname -m)<< parameters.libddtrace_suffix >>.ldflags) libddtrace_php_$(uname -m)<< parameters.libddtrace_suffix >>.a -Wl,-soname -Wl,ddtrace.so -o ${archive%.a}.so
objcopy --compress-debug-sections ${archive%.a}.so
) &
done
wait
- persist_to_workspace:
root: '.'
paths: [ './extensions_*' ]
Expand Down Expand Up @@ -3840,21 +3925,77 @@ workflows:
- '8.1'
- '8.2'
- '8.3'
resource_class: "medium"
name: "Compile alpine x86_64 PHP << matrix.php_major_minor >>"
- compile_alpine:
requires: [ 'Prepare Code' ]
matrix:
parameters:
php_major_minor:
- '7.0'
- '7.1'
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
resource_class: "arm.medium"
name: "Compile alpine aarch64 PHP << matrix.php_major_minor >>"
- compile_rust_alpine:
requires: [ 'Prepare Code' ]
matrix:
parameters:
resource_class:
- "medium"
- "arm.medium"
- link_extension:
requires:
- compile_rust_alpine
- "Compile alpine x86_64 PHP 7.0"
- "Compile alpine x86_64 PHP 7.1"
- "Compile alpine x86_64 PHP 7.2"
- "Compile alpine x86_64 PHP 7.3"
- "Compile alpine x86_64 PHP 7.4"
- "Compile alpine x86_64 PHP 8.0"
- "Compile alpine x86_64 PHP 8.1"
- "Compile alpine x86_64 PHP 8.2"
- "Compile alpine x86_64 PHP 8.3"
libddtrace_suffix: "-alpine"
resource_class: "medium"
name: "Link x86_64 alpine"
docker_image: "datadog/dd-trace-ci:php-compile-extension-alpine"
- link_extension:
requires:
- compile_rust_alpine
- "Compile alpine aarch64 PHP 7.0"
- "Compile alpine aarch64 PHP 7.1"
- "Compile alpine aarch64 PHP 7.2"
- "Compile alpine aarch64 PHP 7.3"
- "Compile alpine aarch64 PHP 7.4"
- "Compile alpine aarch64 PHP 8.0"
- "Compile alpine aarch64 PHP 8.1"
- "Compile alpine aarch64 PHP 8.2"
- "Compile alpine aarch64 PHP 8.3"
libddtrace_suffix: "-alpine"
resource_class: "arm.medium"
name: "Link aarch64 alpine"
docker_image: "datadog/dd-trace-ci:php-compile-extension-alpine"
- compile_extension_centos:
requires: [ 'Prepare Code' ]
name: "Compile x86_64 PHP 70 nts + zts + debug"
php_version: "7.0"
docker_image: "datadog/dd-trace-ci:php-7.0_centos-7"
so_suffix: "20151012"
persist_ldflags: true
- compile_extension_centos:
requires: [ 'Prepare Code' ]
name: "Compile aarch64 PHP 70 nts + zts + debug"
php_version: "7.0"
docker_image: "datadog/dd-trace-ci:php-7.0_centos-7"
so_suffix: "20151012"
persist_ldflags: true
resource_class: "arm.medium"
- compile_extension_centos:
requires: [ 'Prepare Code' ]
Expand Down Expand Up @@ -4004,31 +4145,56 @@ workflows:
docker_image: "datadog/dd-trace-ci:php-8.3_windows"
php_version: "8.3"
so_suffix: "20230831"
- pecl_build:

- compile_rust_centos:
requires: [ 'Prepare Code' ]
name: "Build PECL"
name: "Compile x86_64 rust"
- compile_rust_centos:
requires: [ 'Prepare Code' ]
name: "Compile aarch64 rust"
resource_class: "arm.large"

- "package extension":
- link_extension:
requires:
- compile_alpine
- "Compile x86_64 rust"
- "Compile x86_64 PHP 70 nts + zts + debug"
- "Compile aarch64 PHP 70 nts + zts + debug"
- "Compile x86_64 PHP 71 nts + zts + debug"
- "Compile aarch64 PHP 71 nts + zts + debug"
- "Compile x86_64 PHP 72 nts + zts + debug"
- "Compile aarch64 PHP 72 nts + zts + debug"
- "Compile x86_64 PHP 73 nts + zts + debug"
- "Compile aarch64 PHP 73 nts + zts + debug"
- "Compile x86_64 PHP 74 nts + zts + debug"
- "Compile aarch64 PHP 74 nts + zts + debug"
- "Compile x86_64 PHP 80 nts + zts + debug"
- "Compile aarch64 PHP 80 nts + zts + debug"
- "Compile x86_64 PHP 81 nts + zts + debug"
- "Compile aarch64 PHP 81 nts + zts + debug"
- "Compile x86_64 PHP 82 nts + zts + debug"
- "Compile aarch64 PHP 82 nts + zts + debug"
- "Compile x86_64 PHP 83 nts + zts + debug"
name: "Link x86_64 PHP"
docker_image: "datadog/dd-trace-ci:centos-7"
- link_extension:
requires:
- "Compile aarch64 rust"
- "Compile aarch64 PHP 70 nts + zts + debug"
- "Compile aarch64 PHP 71 nts + zts + debug"
- "Compile aarch64 PHP 72 nts + zts + debug"
- "Compile aarch64 PHP 73 nts + zts + debug"
- "Compile aarch64 PHP 74 nts + zts + debug"
- "Compile aarch64 PHP 80 nts + zts + debug"
- "Compile aarch64 PHP 81 nts + zts + debug"
- "Compile aarch64 PHP 82 nts + zts + debug"
- "Compile aarch64 PHP 83 nts + zts + debug"
name: "Link aarch64 PHP"
docker_image: "datadog/dd-trace-ci:centos-7"
resource_class: "arm.xlarge"

- pecl_build:
requires: [ 'Prepare Code' ]
name: "Build PECL"

- "package extension":
requires:
- "Link x86_64 alpine"
- "Link aarch64 alpine"
- "Link x86_64 PHP"
- "Link aarch64 PHP"

- "Compile Windows PHP 72 nts + zts"
- "Compile Windows PHP 73 nts + zts"
- "Compile Windows PHP 74 nts + zts"
Expand Down
1 change: 1 addition & 0 deletions .gitlab/ci-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Alpine Compile Extension:
parallel:
matrix:
- PHP_VERSION:
- base-alpine
- 8.3-alpine
- 8.2-alpine
- 8.1-alpine
Expand Down
Loading

0 comments on commit 4ab0eb7

Please sign in to comment.