Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
zeriyoshi committed Aug 14, 2024
1 parent 78d5f1d commit bde5714
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 320 deletions.
3 changes: 1 addition & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@
}
},
"dockerComposeFile": "./../compose.yaml",
"service": "dev"
}
}
44 changes: 22 additions & 22 deletions .devcontainer/local/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"name": "pskel (for Local)",
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack",
"maelvalais.autoconf",
"ms-azuretools.vscode-docker",
"editorconfig.editorconfig"
]
}
},
"dockerComposeFile": "./../../compose.yaml",
"service": "dev",
"mounts": [
{
"type": "bind",
"source": "./",
"target": "/workspace/pskel"
}
],
"workspaceFolder": "/workspace/pskel"
"name": "pskel (for Local)",
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack",
"maelvalais.autoconf",
"ms-azuretools.vscode-docker",
"editorconfig.editorconfig"
]
}
},
"dockerComposeFile": "./../../compose.yaml",
"service": "shell",
"mounts": [
{
"type": "bind",
"source": "./",
"target": "/workspace/pskel"
}
],
"workspaceFolder": "/workspace/pskel"
}
16 changes: 8 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,30 @@ jobs:
uses: docker/setup-buildx-action@v3
- name: Build container
run: |
docker compose build --pull --no-cache --build-arg IMAGE=${{ matrix.arch }}/php --build-arg TAG=${{ matrix.version }}-${{ matrix.type }}-${{ matrix.distro }} --build-arg PSKEL_SKIP_DEBUG=${{ matrix.arch != 'amd64' && '1' || '' }}
docker compose build --pull --no-cache --build-arg IMAGE=${{ matrix.arch }}/php --build-arg TAG=${{ matrix.version }}-${{ matrix.type }}-${{ matrix.distro }} --build-arg PSKEL_SKIP_BUILD=${{ matrix.arch != 'amd64' && '1' || '' }}
- name: Run tests
run: |
docker compose run --rm --entrypoint=/usr/bin/pskel_test --env TEST_EXTENSION=1 dev
docker compose run --rm shell test php
- name: Test extension with PHP Debug Build
if: matrix.arch == 'amd64'
run: |
docker compose run --rm --entrypoint=/usr/bin/pskel_test --env TEST_EXTENSION_DEBUG=1 dev
docker compose run --rm shell test debug-php
- name: Test extension with Valgrind
if: matrix.arch == 'amd64'
run: |
docker compose run --rm --entrypoint=/usr/bin/pskel_test --env TEST_EXTENSION_VALGRIND=1 dev
docker compose run --rm --env TEST_PHP_ARGS="-m" shell test gcc-valgrind-php
- name: Test extension with LLVM Sanitizer (MemorySanitizer)
if: matrix.arch == 'amd64' && matrix.distro != 'alpine'
run: |
docker compose run --rm --entrypoint=/usr/bin/pskel_test --env TEST_EXTENSION_MSAN=1 dev
docker compose run --rm --env TEST_PHP_ARGS="--msan" --env CC="/usr/bin/clang" --env CXX="/usr/bin/clang++" --env CFLAGS="-fsanitize=memory -DZEND_TRACK_ARENA_ALLOC" --env CPPFLAGS="-fsanitize=memory -DZEND_TRACK_ARENA_ALLOC" shell test clang-msan-php
- name: Test extension with LLVM Sanitizer (AddressSanitizer)
if: matrix.arch == 'amd64' && matrix.distro != 'alpine'
run: |
docker compose run --rm --entrypoint=/usr/bin/pskel_test --env TEST_EXTENSION_ASAN=1 dev
docker compose run --rm --env TEST_PHP_ARGS="--asan" --env CC="/usr/bin/clang" --env CXX="/usr/bin/clang++" --env CFLAGS="-fsanitize=address -DZEND_TRACK_ARENA_ALLOC" --env CPPFLAGS="-fsanitize=address -DZEND_TRACK_ARENA_ALLOC" shell test clang-asan-php
- name: Test extension with LLVM Sanitizer (UndefinedBehaviorSanitizer)
if: matrix.arch == 'amd64' && matrix.distro != 'alpine'
run: |
docker compose run --rm --entrypoint=/usr/bin/pskel_test --env TEST_EXTENSION_UBSAN=1 dev
docker compose run --rm --env CC="/usr/bin/clang" --env CXX="/usr/bin/clang++" --env CFLAGS="-fsanitize=undefined -DZEND_TRACK_ARENA_ALLOC" --env CPPFLAGS="-fsanitize=undefined -DZEND_TRACK_ARENA_ALLOC" shell test clang-ubsan-php
# Windows:
# runs-on: windows-2022
# defaults:
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
# run: phpize
# - name: configure
# working-directory: ext
# run: configure --enable-skeleton --with-prefix=${{ steps.setup-php.outputs.prefix }}
# run: configure --enable-SKELETON_NAME --with-prefix=${{ steps.setup-php.outputs.prefix }}
# - name: make
# working-directory: ext
# run: nmake
Expand Down
21 changes: 0 additions & 21 deletions .vscode/c_cpp_properties.json

This file was deleted.

14 changes: 0 additions & 14 deletions .vscode/settings.json

This file was deleted.

153 changes: 31 additions & 122 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,129 +1,38 @@
ARG PLATFORM=linux/arm64/v8
ARG IMAGE=php
ARG TAG=8.3-cli
ARG TAG=8.3-cli-bookworm

FROM ${IMAGE}:${TAG}
FROM --platform=${PLATFORM} ${IMAGE}:${TAG}

ARG PSKEL_SKIP_DEBUG=""
ARG PSKEL_EXTRA_CONFIGURE_OPTIONS=""
ARG PSKEL_SKIP_BUILD=""

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}
COPY ./pskel.sh /usr/local/bin/pskel

RUN if test -f "/etc/debian_version"; then \
apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get install -y \
"build-essential" "bison" "valgrind" "llvm" "clang" "zlib1g-dev" "libsqlite3-dev" "git" && \
if test "${PSKEL_SKIP_DEBUG}" = ""; 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-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" && \
CC=clang CXX=clang++ CFLAGS="-fsanitize=memory -fno-sanitize-recover -DZEND_TRACK_ARENA_ALLOC" LDFLAGS="-fsanitize=memory" ./configure \
--includedir="/usr/local/include/clang-msan-php" --program-prefix="clang-msan-" \
--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" && \
CC=clang CXX=clang++ CFLAGS="-fsanitize=address -fno-sanitize-recover -DZEND_TRACK_ARENA_ALLOC" LDFLAGS="-fsanitize=address" ./configure \
--includedir="/usr/local/include/clang-asan-php" --program-prefix="clang-asan-" \
--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-address-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" && \
CC=clang CXX=clang++ CFLAGS="-fsanitize=undefined -fno-sanitize-recover -DZEND_TRACK_ARENA_ALLOC" LDFLAGS="-fsanitize=undefined" ./configure \
--includedir="/usr/local/include/clang-ubsan-php" --program-prefix="clang-ubsan-" \
--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-undefined-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 && \
cd - && \
docker-php-source delete; \
fi; \
elif test -f "/etc/alpine-release"; then \
apk add --no-cache ${PHPIZE_DEPS} "bison" "valgrind" "valgrind-dev" "zlib-dev" "sqlite-dev" "git" && \
if test "${PSKEL_SKIP_DEBUG}" = ""; 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-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 && \
cd - && \
docker-php-source delete; \
fi; \
fi && \
docker-php-source extract && \
ln -s "/usr/src/php/build/gen_stub.php" "/usr/local/bin/gen_stub.php"

WORKDIR "/usr/src/php"

COPY ./pskel_test.sh /usr/bin/pskel_test
COPY ./pskel_init_extension.sh /usr/bin/pskel_init_extension
RUN export CFLAGS="-fPIE -DZEND_TRACK_ARENA_ALLOC" \
&& export CPPFLAGS="${CFLAGS}" \
&& export BASE_OPTS="--enable-option-checking=fatal --enable-debug --disable-phpdbg --disable-cgi --disable-fpm --enable-cli --without-pcre-jit --disable-opcache-jit" \
&& if test "x${PSKEL_SKIP_BUILD}" = "x"; then \
if test -f "/etc/debian_version"; then \
apt-get update \
&& DEBIAN_FRONTEND="noninteractive" apt-get install -y "bison" "re2c" "zlib1g-dev" "libsqlite3-dev" "libxml2-dev" \
"autoconf" "pkg-config" "make" "gcc" "valgrind" "llvm" "clang" \
&& CC="$(which "clang")" CXX="$(which "clang++")" CONFIGURE_OPTS="${BASE_OPTS} --enable-memory-sanitizer" pskel build "clang-msan" \
&& CC="$(which "clang")" CXX="$(which "clang++")" CONFIGURE_OPTS="${BASE_OPTS} --enable-address-sanitizer" pskel build "clang-asan" \
&& CC="$(which "clang")" CXX="$(which "clang++")" CONFIGURE_OPTS="${BASE_OPTS} --enable-undefined-sanitizer" pskel build "clang-ubsan"; \
else \
apk add --no-cache "bison" "zlib-dev" "sqlite-dev" "libxml2-dev" \
"autoconf" "pkgconfig" "make" "gcc" "valgrind" "valgrind-dev" \
"musl-dev"; \
fi \
&& CC="$(which "gcc")" CXX="$(which "g+++")" CONFIGURE_OPTS="${BASE_OPTS}" pskel build "debug" \
&& CC="$(which "gcc")" CXX="$(which "g+++")" CONFIGURE_OPTS="${BASE_OPTS} --with-valgrind" pskel build "gcc-valgrind"; \
fi \
&& if test -f "/etc/debian_version"; then \
apt-get update && apt-get install -y "git"; \
else \
apk add --no-cache "git"; \
fi

COPY ./ext /ext

ENTRYPOINT [ "/usr/local/bin/pskel" ]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ A skeleton project for quickly setting up an environment to develop extensions f
1. Install [Visual Studio Code](https://code.visualstudio.com/) and Docker Desktop (or an alternative engine).
1. Install the [Remote Container](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension in VSCode.
1. Open the directory and open it with the `Remote Container` extension.
1. Run `pskel_init_extension` command.
2. Run `pskel_test` command for testing.
1. Run `pskel init <extension_name>` .
2. Run `pskel test <testing php binary name>` command for testing.

### Q&A

Expand Down
3 changes: 1 addition & 2 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
dev:
shell:
build:
context: ./
dockerfile: ./Dockerfile
Expand All @@ -9,7 +9,6 @@ services:
- seccomp:unconfined
privileged: true
tty: true
command: ["sleep", "infinity"]
# depends_on:
# - mysql
# mysql:
Expand Down
2 changes: 1 addition & 1 deletion ext/.gitkeep
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pskel_uninitialized
pskel_uninitialized
Loading

0 comments on commit bde5714

Please sign in to comment.