Skip to content

Commit

Permalink
add PHP debug build
Browse files Browse the repository at this point in the history
  • Loading branch information
zeriyoshi committed Mar 5, 2024
1 parent ac4bd50 commit 10dbf40
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 22 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ jobs:
timeout-minutes: 60
strategy:
matrix:
arch: ["amd64", "arm64v8"]
version: ["8.1", "8.2"]
arch: ["amd64", "arm64v8", "s390x"]
version: ["8.1", "8.2", "8.3"]
type: ["cli", "zts"]
distro: ["bullseye", "alpine"]
steps:
Expand All @@ -27,6 +27,10 @@ jobs:
- name: Run tests
run: |
docker compose run --rm --entrypoint=/usr/bin/ci --env TEST_EXTENSION=1 dev
- name: Test extension with PHP Debug Build
if: matrix.arch == 'amd64'
run: |
docker compose run --rm --entrypoint=/usr/bin/ci --env TEST_EXTENSION_DEBUG=1 dev
- name: Test extension with Valgrind
if: matrix.arch == 'amd64'
run: |
Expand Down
43 changes: 37 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ ARG TAG=8.2-cli
FROM ${IMAGE}:${TAG}

ARG PSKEL_SKIP_DEBUG=""
ARG PSKEL_EXTRA_CONFIGURE_OPTIONS=""

ENV USE_ZEND_ALLOC=0
ENV ZEND_DONT_UNLOAD_MODULES=1
ENV PSKEL_SKIP_DEBUG=${PSKEL_SKIP_DEBUG}
ENV PSKEL_EXTRA_CONFIGURE_OPTIONS=${PSKEL_EXTRA_CONFIGURE_OPTIONS}

RUN if test -f "/etc/debian_version"; then \
apt-get update && \
Expand All @@ -17,11 +19,12 @@ RUN if test -f "/etc/debian_version"; then \
docker-php-source extract && \
cd "/usr/src/php" && \
CFLAGS="-fpic -fpie -DZEND_TRACK_ARENA_ALLOC" LDFLAGS="-pie" ./configure --disable-all \
--includedir="/usr/local/include/gcc-debug-php" --program-prefix="gcc-debug-" \
--disable-cgi --disable-fpm --disable-phpdbg --enable-cli \
--includedir="/usr/local/include/gcc-valgrind-php" --program-prefix="gcc-valgrind-" \
--disable-cgi --disable-fpm --enable-cli \
--enable-mysqlnd --enable-pdo --with-pdo-mysql --with-pdo-sqlite \
--enable-debug --without-pcre-jit "$(php -r "echo PHP_ZTS === 1 ? '--enable-zts' : '';")" \
--with-valgrind \
${PSKEL_EXTRA_CONFIGURE_OPTIONS} \
--enable-option-checking=fatal && \
make -j$(nproc) && \
make install && \
Expand All @@ -30,11 +33,25 @@ RUN if test -f "/etc/debian_version"; then \
docker-php-source extract && \
cd "/usr/src/php" && \
CC=clang CXX=clang++ CFLAGS="-fpic -fpie -DZEND_TRACK_ARENA_ALLOC" LDFLAGS="-pie" ./configure \
--includedir="/usr/local/include/clang-debug-php" --program-prefix="clang-debug-" \
--disable-cgi --disable-all --disable-fpm --disable-phpdbg --enable-cli \
--includedir="/usr/local/include/clang-sanitizer-php" --program-prefix="clang-sanitizer-" \
--disable-cgi --disable-all --disable-fpm --enable-cli \
--enable-mysqlnd --enable-pdo --with-pdo-mysql --with-pdo-sqlite \
--enable-debug --without-pcre-jit "$(php -r "echo PHP_ZTS === 1 ? '--enable-zts' : '';")" \
--enable-memory-sanitizer \
${PSKEL_EXTRA_CONFIGURE_OPTIONS} \
--enable-option-checking=fatal && \
make -j$(nproc) && \
make install && \
cd - && \
docker-php-source delete && \
docker-php-source extract && \
cd "/usr/src/php" && \
CFLAGS="-fpic -fpie -DZEND_TRACK_ARENA_ALLOC" LDFLAGS="-pie" ./configure --disable-all \
--includedir="/usr/local/include/debug-php" --program-prefix="debug-" \
--disable-cgi --disable-fpm --enable-cli \
--enable-mysqlnd --enable-pdo --with-pdo-mysql --with-pdo-sqlite \
--enable-debug "$(php -r "echo PHP_ZTS === 1 ? '--enable-zts' : '';")" \
${PSKEL_EXTRA_CONFIGURE_OPTIONS} \
--enable-option-checking=fatal && \
make -j$(nproc) && \
make install && \
Expand All @@ -47,11 +64,25 @@ RUN if test -f "/etc/debian_version"; then \
docker-php-source extract && \
cd "/usr/src/php" && \
CFLAGS="-fpic -fpie -DZEND_TRACK_ARENA_ALLOC" LDFLAGS="-pie" ./configure --disable-all \
--includedir="/usr/local/include/gcc-debug-php" --program-prefix="gcc-debug-" \
--disable-cgi --disable-fpm --disable-phpdbg --enable-cli \
--includedir="/usr/local/include/gcc-valgrind-php" --program-prefix="gcc-valgrind-" \
--disable-cgi --disable-fpm --enable-cli \
--enable-mysqlnd --enable-pdo --with-pdo-mysql --with-pdo-sqlite \
--enable-debug --without-pcre-jit "$(php -r "echo PHP_ZTS === 1 ? '--enable-zts' : '';")" \
--with-valgrind \
${PSKEL_EXTRA_CONFIGURE_OPTIONS} \
--enable-option-checking=fatal && \
make -j$(nproc) && \
make install && \
cd - && \
docker-php-source delete && \
docker-php-source extract && \
cd "/usr/src/php" && \
CFLAGS="-fpic -fpie -DZEND_TRACK_ARENA_ALLOC" LDFLAGS="-pie" ./configure --disable-all \
--includedir="/usr/local/include/debug-php" --program-prefix="debug-" \
--disable-cgi --disable-fpm --enable-cli \
--enable-mysqlnd --enable-pdo --with-pdo-mysql --with-pdo-sqlite \
--enable-debug "$(php -r "echo PHP_ZTS === 1 ? '--enable-zts' : '';")" \
${PSKEL_EXTRA_CONFIGURE_OPTIONS} \
--enable-option-checking=fatal && \
make -j$(nproc) && \
make install && \
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ A debug build of PHP is included in advance. Debug builds using GCC and Clang ar

They each have the following binary prefixes. The build toolchains are the same.

- `gcc-debug-php`
- `clang-debug-php`
- `debug-php`
- `gcc-valgrind-php`
- `clang-sanitizer-php`

For example, the method to test the extension using GCC + Valgrind is as follows:

```
# gcc-debug-phpize
# ./configure --with-php-config=$(which gcc-debug-php-config)
# gcc-valgrind-phpize
# ./configure --with-php-config=$(which gcc-valgrind-php-config)
# TEST_PHP_ARGS="-q -m --show-diff" make -j$(nproc) test
```

Expand All @@ -37,7 +38,7 @@ For example, the method to test the extension using GCC + Valgrind is as follows
Yes. Build using the debug version of PHP and run as follows:

```
# gdb --args gcc-debug-php -dextension=./modules/your_extension_name.so example.php
# gdb --args gcc-valgrind-php -dextension=./modules/your_extension_name.so example.php
```

#### Can I develop using something other than Visual Studio Code?
Expand Down
30 changes: 21 additions & 9 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
case "${1}" in
"") ;;
"test") TEST_EXTENSION=1;;
"debug") TEST_EXTENSION_DEBUG=1;;
"gcc"|"valgrind") TEST_EXTENSION_VALGRIND=1;;
"clang"|"msan") TEST_EXTENSION_MSAN=1;;
*) printf "Pskel CI\nusage:\n\t%s\t: %s\n\t%s\t: %s\n\t%s\t: %s\n" "test" "Test extension with pre-installed PHP binary. [bin: $(which "php")]" "gcc" "Test extension with GCC binary with Valgrind. [bin: $(which "gcc-debug-php")]" "clang" "Test extension with Clang binary with MemorySanitizer. [bin: $(which "clang-debug-php")]"; exit 0;;
*) printf "Pskel CI\nusage:\n\t%s\t: %s\n\t%s\t: %s\n\t%s\t: %s\n" "test" "Test extension with pre-installed PHP binary. [bin: $(which "php")]" "gcc" "Test extension with GCC binary with Valgrind. [bin: $(which "gcc-valgrind-php")]" "clang" "Test extension with Clang binary with MemorySanitizer. [bin: $(which "clang-sanitizer-php")]"; exit 0;;
esac

echo "[Pskel CI] BEGIN TEST"
Expand All @@ -21,32 +22,43 @@ else
echo "[Pskel CI] skip: TEST_EXTENSION is not set"
fi

if test "${TEST_EXTENSION_DEBUG}" != ""; then
cd "/ext"
debug-phpize
./configure --with-php-config="$(which debug-php-config)"
make clean
make -j"$(nproc)"
TEST_PHP_ARGS="--show-diff -q" make test
else
echo "[Pskel CI] skip: TEST_EXTENSION_DEBUG is not set"
fi

if test "${TEST_EXTENSION_VALGRIND}" != ""; then
if type "gcc-debug-php" > /dev/null 2>&1; then
if type "gcc-valgrind-php" > /dev/null 2>&1; then
cd "/ext"
gcc-debug-phpize
./configure --with-php-config="$(which gcc-debug-php-config)"
gcc-valgrind-phpize
./configure --with-php-config="$(which gcc-valgrind-php-config)"
make clean
make -j"$(nproc)"
TEST_PHP_ARGS="--show-diff -q -m" make test
else
echo "[Pskel CI] missing gcc-debug-php"
echo "[Pskel CI] missing gcc-valgrind-php"
exit 1
fi
else
echo "[Pskel CI] skip: TEST_EXTENSION_VALGRIND is not set"
fi

if test "${TEST_EXTENSION_MSAN}" != ""; then
if type "clang-debug-php" > /dev/null 2>&1; then
if type "clang-sanitizer-php" > /dev/null 2>&1; then
cd "/ext"
clang-debug-phpize
CC="clang" CXX="clang++" CFLAGS="-fsanitize=memory -DZEND_TRACK_ARENA_ALLOC" CPPFLAGS="-fsanitize=memory -DZEND_TRACK_ARENA_ALLOC ${CPPFLAGS}" LDFLAGS="-fsanitize=memory" ./configure --with-php-config="$(which clang-debug-php-config)"
clang-sanitizer-phpize
CC="clang" CXX="clang++" CFLAGS="-fsanitize=memory -DZEND_TRACK_ARENA_ALLOC" CPPFLAGS="-fsanitize=memory -DZEND_TRACK_ARENA_ALLOC ${CPPFLAGS}" LDFLAGS="-fsanitize=memory" ./configure --with-php-config="$(which clang-sanitizer-php-config)"
make clean
CFLAGS="-fsanitize=memory -DZEND_TRACK_ARENA_ALLOC ${CFLAGS}" CPPFLAGS="-fsanitize=memory -DZEND_TRACK_ARENA_ALLOC ${CPPFLAGS}" LDFLAGS="-fsanitize=memory" make -j"$(nproc)"
TEST_PHP_ARGS="--show-diff -q --msan" make test
else
echo "[Pskel CI] missing clang-debug-php"
echo "[Pskel CI] missing clang-sanitizer-php"
exit 1
fi
else
Expand Down

0 comments on commit 10dbf40

Please sign in to comment.