Skip to content

Commit f0e634a

Browse files
authored
Merge pull request #673 from crazywhalecc/feat/xdebug-dynamic
add xdebug dynamic extension
2 parents b06db1f + 0f5f60e commit f0e634a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+497
-163
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,5 +197,5 @@ jobs:
197197
run: php src/globals/test-extensions.php build_cmd ${{ matrix.os }} ${{ matrix.php }}
198198

199199
- name: "Run Build Tests (build - embed for non-windows)"
200-
if: matrix.os != 'windows-latest'
200+
if: ${{ !startsWith(matrix.os, 'windows-') }}
201201
run: php src/globals/test-extensions.php build_embed_cmd ${{ matrix.os }} ${{ matrix.php }}

bin/spc-alpine-docker

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/pkgroot:/app/pkgroot"
122122
# shellcheck disable=SC2086
123123
# shellcheck disable=SC2090
124124
if [ "$SPC_DOCKER_DEBUG" = "yes" ]; then
125+
echo "* Debug mode enabled, run docker in interactive mode."
126+
echo "* You can use 'exit' to exit the docker container."
127+
echo "* You can use 'bin/spc' like normal builds."
128+
echo "*"
129+
echo "* Mounted directories:"
130+
echo "* ./config: $(pwd)/config"
131+
echo "* ./src: $(pwd)/src"
132+
echo "* ./buildroot: $(pwd)/buildroot"
133+
echo "* ./source: $(pwd)/source"
134+
echo "* ./dist: $(pwd)/dist"
135+
echo "* ./downloads: $(pwd)/downloads"
136+
echo "* ./pkgroot: $(pwd)/pkgroot"
137+
echo "*"
138+
125139
$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH-v2
126140
else
127141
$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH-v2 bin/spc $@

bin/spc-gnu-docker

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ DOCKER_EXECUTABLE="docker"
1212
# shellcheck disable=SC2046
1313
if [ $(id -u) -ne 0 ]; then
1414
if ! docker info > /dev/null 2>&1; then
15-
if [ "$SPC_USE_SUDO" != "yes" ]; then
15+
if [ "$SPC_USE_SUDO" != "yes" ] && [ "$SPC_DOCKER_DEBUG" != "yes" ]; then
1616
echo "Docker command requires sudo"
1717
# shellcheck disable=SC2039
1818
echo -n 'To use sudo to run docker, run "export SPC_USE_SUDO=yes" and run command again'
@@ -86,7 +86,7 @@ COPY ./composer.* /app/
8686
ADD ./bin/setup-runtime /app/bin/setup-runtime
8787
ADD ./bin/spc /app/bin/spc
8888
RUN /app/bin/setup-runtime
89-
RUN /app/bin/php /app/bin/composer install --no-dev --classmap-authoritative
89+
RUN /app/bin/php /app/bin/composer install --no-dev
9090
ENV PATH="/app/bin:/cmake/bin:$PATH"
9191
ENV SPC_LIBC=glibc
9292
@@ -146,6 +146,20 @@ echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil -lrt"'
146146
# shellcheck disable=SC2090
147147

148148
if [ "$SPC_DOCKER_DEBUG" = "yes" ]; then
149+
echo "* Debug mode enabled, run docker in interactive mode."
150+
echo "* You can use 'exit' to exit the docker container."
151+
echo "* You can use 'bin/spc' like normal builds."
152+
echo "*"
153+
echo "* Mounted directories:"
154+
echo "* ./config: $(pwd)/config"
155+
echo "* ./src: $(pwd)/src"
156+
echo "* ./buildroot: $(pwd)/buildroot"
157+
echo "* ./source: $(pwd)/source"
158+
echo "* ./dist: $(pwd)/dist"
159+
echo "* ./downloads: $(pwd)/downloads"
160+
echo "* ./pkgroot: $(pwd)/pkgroot"
161+
echo "*"
162+
149163
$DOCKER_EXECUTABLE run --rm -it --privileged $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH
150164
else
151165
$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH bin/spc $@

config/env.ini

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
; PATH: static-php-cli will add `$BUILD_BIN_PATH` to PATH.
2929
; PKG_CONFIG: static-php-cli will set `$BUILD_BIN_PATH/pkg-config` to PKG_CONFIG.
3030
; PKG_CONFIG_PATH: static-php-cli will set `$BUILD_LIB_PATH/pkgconfig` to PKG_CONFIG_PATH.
31-
; SPC_PHP_DEFAULT_OPTIMIZE_CFLAGS: the default optimization CFLAGS for compiling php. (if --no-strip option is set: `-g -O0`, else: `-g -Os`)
3231
;
3332
; * These vars are only be defined in LinuxBuilder and cannot be changed anywhere:
3433
; SPC_LINUX_DEFAULT_CC: the default compiler for linux. (For alpine linux: `gcc`, default: `$GNU_ARCH-linux-musl-gcc`)
@@ -98,9 +97,9 @@ SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}"
9897
; LIBS for configuring php
9998
SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lpthread -lm"
10099
; EXTRA_CFLAGS for `make` php
101-
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="${SPC_PHP_DEFAULT_OPTIMIZE_CFLAGS} -fno-ident -fPIE -fPIC"
100+
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fpic -fpie -Os -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -fno-ident -fPIE -fPIC"
102101
; EXTRA_LIBS for `make` php
103-
SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS=""
102+
SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm"
104103
; EXTRA_LDFLAGS_PROGRAM for `make` php
105104
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-all-static -Wl,-O1 -pie"
106105

@@ -132,7 +131,7 @@ SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS="-I${BUILD_INCLUDE_PATH}"
132131
; LDFLAGS for configuring php
133132
SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}"
134133
; EXTRA_CFLAGS for `make` php
135-
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="${SPC_PHP_DEFAULT_OPTIMIZE_CFLAGS}"
134+
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fpic -fpie -Os -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
136135
; EXTRA_LIBS for `make` php
137136
SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-lresolv"
138137
; embed type for php, static (libphp.a) or shared (libphp.dylib)

config/ext.json

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@
119119
"Linux": "partial",
120120
"BSD": "wip"
121121
},
122+
"target": [
123+
"static",
124+
"shared"
125+
],
122126
"notes": true,
123127
"arg-type": "custom",
124128
"type": "builtin",
@@ -772,6 +776,9 @@
772776
"Windows": "no",
773777
"BSD": "wip"
774778
},
779+
"target": [
780+
"static"
781+
],
775782
"notes": true,
776783
"type": "external",
777784
"source": "swoole",
@@ -919,12 +926,16 @@
919926
]
920927
},
921928
"xdebug": {
922-
"type": "builtin",
929+
"type": "external",
930+
"source": "xdebug",
931+
"target": [
932+
"shared"
933+
],
923934
"support": {
924935
"Windows": "wip",
925936
"BSD": "no",
926-
"Darwin": "no",
927-
"Linux": "no"
937+
"Darwin": "partial",
938+
"Linux": "partial"
928939
},
929940
"notes": true
930941
},
@@ -1040,6 +1051,9 @@
10401051
"support": {
10411052
"BSD": "wip"
10421053
},
1054+
"target": [
1055+
"static"
1056+
],
10431057
"type": "builtin",
10441058
"arg-type": "with-prefix",
10451059
"arg-type-windows": "enable",

config/lib.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,7 @@
281281
"headers-unix": [
282282
"ares.h",
283283
"ares_dns.h",
284-
"ares_nameser.h",
285-
"ares_rules.h"
284+
"ares_nameser.h"
286285
]
287286
},
288287
"libde265": {

config/source.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,15 @@
913913
"path": "COPYING"
914914
}
915915
},
916+
"xdebug": {
917+
"type": "url",
918+
"url": "https://pecl.php.net/get/xdebug",
919+
"filename": "xdebug.tgz",
920+
"license": {
921+
"type": "file",
922+
"path": "LICENSE"
923+
}
924+
},
916925
"xhprof": {
917926
"type": "url",
918927
"url": "https://pecl.php.net/get/xhprof",

docs/en/guide/extension-notes.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,9 @@ and this extension cannot be compiled into php by static linking, so it cannot b
8080

8181
## xdebug
8282

83-
1. Xdebug is only buildable as a shared extension. On Linux, you need to use static-php-cli with SPC_LIBC=glibc and then compile php-xdebug from source with the option `--with-php-config=/path/to/buildroot/bin/php-config`.
84-
2. The macOS platform can compile an xdebug extension under PHP compiled on the same platform,
85-
extract the `xdebug.so` file, and then use the `--no-strip` parameter in static-php-cli to retain the debug symbol table and add the `ffi` extension.
86-
The compiled `./php` binary can be configured and run by specifying the INI, eg `./php -d 'zend_extension=/path/to/xdebug.so' your-code.php`.
83+
1. Xdebug is only buildable as a shared extension. On Linux, you need to use static-php-cli with SPC_LIBC=glibc.
84+
2. When using Linux/glibc or macOS, you can compile Xdebug as a shared extension using --build-shared="xdebug".
85+
The compiled `./php` binary can be configured and run by specifying the INI, eg `./php -d 'zend_extension=/path/to/xdebug.so' your-code.php`.
8786

8887
## xml
8988

@@ -126,8 +125,8 @@ For details on the solution, see [FAQ - Unable to use ssl](../faq/#unable-to-use
126125

127126
## ffi
128127

129-
1. Due to the limitation of Linux system, you cannot use it to load other `so` extensions in the purely static compiled state (spc defaults to pure static compilation).
130-
Linux supports loading so extensions only if they are non-statically compiled. If you need to use the ffi extension, see [Compile PHP with GNU libc](./build-with-glibc).
128+
1. Due to the limitation of musl libc's static linkage, you cannot use ffi because dynamic libraries cannot be loaded.
129+
If you need to use the ffi extension, see [Compile PHP with GNU libc](./build-with-glibc).
131130
2. macOS supports the ffi extension, but errors will occur when some kernels do not contain debugging symbols.
132131
3. Windows x64 supports the ffi extension.
133132

docs/en/guide/manual-build.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ You can try to use the following commands:
314314
- `--with-suggested-exts`: Add `ext-suggests` as dependencies when compiling
315315
- `--with-suggested-libs`: Add `lib-suggests` as dependencies when compiling
316316
- `--with-upx-pack`: Use UPX to reduce the size of the binary file after compilation (you need to use `bin/spc install-pkg upx` to install upx first)
317+
- `--build-shared=XXX,YYY`: compile the specified extension into a shared library (the default is to compile into a static library)
317318

318319
For hardcoding INI options, it works for cli, micro, embed sapi. Here is a simple example where we preset a larger `memory_limit` and disable the `system` function:
319320

docs/zh/guide/extension-notes.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ bin/spc build gd --with-libs=freetype,libjpeg,libavif,libwebp --build-cli
7474

7575
## xdebug
7676

77-
1. Xdebug 只能作为共享扩展构建。在 Linux 上,您需要使用带有 `SPC_LIBC=glibc`static-php-cli,然后使用选项 `--with-php-config=/path/to/buildroot/bin/php-config` 从源代码编译 php-xdebug
78-
2. macOS 平台可以通过在相同平台编译的 PHP 下编译一个 xdebug 扩展,并提取其中的 `xdebug.so` 文件,再在 static-php-cli 中使用 `--no-strip` 参数保留调试符号表,同时加入 `ffi` 扩展
79-
编译的 `./php` 二进制可以通过指定 INI 配置并运行,例如`./php -d 'zend_extension=xdebug.so' your-code.php`
77+
1. Xdebug 只能作为共享扩展进行构建。在 Linux 上,您需要使用 static-php-cli 并设置 SPC_LIBC=glibc
78+
2. 使用 Linux/glibc 或 macOS 时,您可以使用 `--build-shared=xdebug` 将 Xdebug 编译为共享扩展
79+
编译后的 `./php` 二进制文件可以通过指定 INI 文件进行配置和运行,例如 `./php -d 'zend_extension=/path/to/xdebug.so' your-code.php`
8080

8181
## xml
8282

@@ -117,9 +117,10 @@ pgsql 16.2 修复了这个 Bug,现在正常工作了。
117117

118118
## ffi
119119

120-
1. 因为 Linux 系统的限制,纯静态编译的状态下(spc 默认编译结果为纯静态)无法使用它加载其他 `so` 扩展。Linux 支持加载 so 扩展的前提是非静态编译。如果你需要使用 ffi 扩展,请参见 [编译 GNU libc 的 PHP](./build-with-glibc)
121-
2. macOS 支持 ffi 扩展,但是部分内核下不包含调试符号时会出现错误。
122-
3. Windows 支持 ffi 扩展。
120+
1. 由于 musl libc 静态链接的限制,无法加载动态库,因此无法使用 ffi。
121+
如果您需要使用 ffi 扩展,请参阅 [使用 GNU libc 编译 PHP](./build-with-glibc)
122+
2. macOS 支持 ffi 扩展,但某些内核不包含调试符号时会出现错误。
123+
3. Windows x64 支持 ffi 扩展。
123124

124125
## xhprof
125126

0 commit comments

Comments
 (0)