Skip to content

Commit

Permalink
Pskel next (#3)
Browse files Browse the repository at this point in the history
next
  • Loading branch information
zeriyoshi authored Aug 15, 2024
1 parent 78d5f1d commit 7b490fd
Show file tree
Hide file tree
Showing 13 changed files with 218 additions and 350 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
}
},
"dockerComposeFile": "./../compose.yaml",
"service": "dev"
}
"service": "shell"
}
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"
}
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.git
**/.git
**/README.md
**/LICENSE
**/.editorconfig
34 changes: 17 additions & 17 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
arch: ["amd64", "arm64v8", "s390x"]
platform: ["linux/amd64", "linux/arm64/v8", "linux/s390x"]
version: ["8.1", "8.2", "8.3"]
type: ["cli", "zts"]
distro: ["bookworm", "alpine"]
Expand All @@ -20,38 +20,38 @@ 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 PLATFORM="${{ matrix.platform }}" --build-arg IMAGE="php" --build-arg TAG="${{ matrix.version }}-${{ matrix.type }}-${{ matrix.distro }}"
- name: Run tests
run: |
docker compose run --rm --entrypoint=/usr/bin/pskel_test --env TEST_EXTENSION=1 dev
docker compose run --rm shell pskel test
- name: Test extension with PHP Debug Build
if: matrix.arch == 'amd64'
if: matrix.platform == 'linux/amd64'
run: |
docker compose run --rm --entrypoint=/usr/bin/pskel_test --env TEST_EXTENSION_DEBUG=1 dev
docker compose run --rm shell pskel test debug
- name: Test extension with Valgrind
if: matrix.arch == 'amd64'
if: matrix.platform == 'linux/amd64'
run: |
docker compose run --rm --entrypoint=/usr/bin/pskel_test --env TEST_EXTENSION_VALGRIND=1 dev
docker compose run --rm shell pskel test valgrind
- name: Test extension with LLVM Sanitizer (MemorySanitizer)
if: matrix.arch == 'amd64' && matrix.distro != 'alpine'
if: matrix.platform == 'linux/amd64' && matrix.distro != 'alpine'
run: |
docker compose run --rm --entrypoint=/usr/bin/pskel_test --env TEST_EXTENSION_MSAN=1 dev
docker compose run --rm shell pskel test msan
- name: Test extension with LLVM Sanitizer (AddressSanitizer)
if: matrix.arch == 'amd64' && matrix.distro != 'alpine'
if: matrix.platform == 'linux/amd64' && matrix.distro != 'alpine'
run: |
docker compose run --rm --entrypoint=/usr/bin/pskel_test --env TEST_EXTENSION_ASAN=1 dev
docker compose run --rm shell pskel test asan
- name: Test extension with LLVM Sanitizer (UndefinedBehaviorSanitizer)
if: matrix.arch == 'amd64' && matrix.distro != 'alpine'
if: matrix.platform == 'linux/amd64' && matrix.distro != 'alpine'
run: |
docker compose run --rm --entrypoint=/usr/bin/pskel_test --env TEST_EXTENSION_UBSAN=1 dev
docker compose run --rm shell pskel test ubsan
# Windows:
# runs-on: windows-2022
# defaults:
# run:
# shell: cmd
# strategy:
# matrix:
# arch: ["x64"]
# .platform: ["x64"]
# version: ["8.1", "8.2", "8.3"]
# ts: ["nts", "ts"]
# steps:
Expand All @@ -61,20 +61,20 @@ jobs:
# id: setup-php
# uses: php/setup-php-sdk@v0.8
# with:
# arch: ${{ matrix.arch }}
# .platform: ${{ matrix.platform }}
# version: ${{ matrix.version }}
# ts: ${{ matrix.ts }}
# - name: Enable developer command prompt
# uses: ilammy/msvc-dev-cmd@v1
# with:
# arch: ${{ matrix.arch }}
# .platform: ${{ matrix.platform }}
# toolset: ${{ steps.setup-php.outputs.toolset }}
# - name: phpize
# working-directory: ext
# 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.

141 changes: 21 additions & 120 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,129 +1,30 @@
ARG PLATFORM=${BUILDPLATFORM:-linux/amd64}
ARG IMAGE=php
ARG TAG=8.3-cli
ARG TAG=8.3-zts-bookworm

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

ARG PSKEL_SKIP_DEBUG=""
ARG PSKEL_EXTRA_CONFIGURE_OPTIONS=""
COPY ./pskel.sh /usr/local/bin/pskel

ENV USE_ZEND_ALLOC=0
ENV USE_TRACKED_ALLOC=1
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 && \
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 docker-php-source extract \
&& if test -f "/etc/debian_version"; then \
echo "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm main" > "/etc/apt/sources.list.d/llvm.list" \
&& echo "deb-src http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm main" >> "/etc/apt/sources.list.d/llvm.list" \
&& curl -fsSL "https://apt.llvm.org/llvm-snapshot.gpg.key" -o "/etc/apt/trusted.gpg.d/apt.llvm.org.asc" \
&& apt-get update \
&& DEBIAN_FRONTEND="noninteractive" apt-get install -y "bison" "re2c" "zlib1g-dev" "libsqlite3-dev" "libxml2-dev" \
"autoconf" "pkg-config" "make" "gcc" "valgrind" "git" \
"clang-20" \
&& update-alternatives --install "/usr/bin/clang" clang "/usr/bin/clang-20" 100 \
&& update-alternatives --install "/usr/bin/clang++" clang++ "/usr/bin/clang++-20" 100; \
else \
apk add --no-cache "bison" "zlib-dev" "sqlite-dev" "libxml2-dev" \
"autoconf" "pkgconfig" "make" "gcc" "g++" "valgrind" "valgrind-dev" \
"musl-dev" "git"; \
fi

COPY ./ext /ext
26 changes: 3 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,21 @@ 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 [debug|valgrind|msan|asan|ubsan]` command for testing.

### Q&A

#### Can I set up an environment using MySQL, Redis, etc.?

Yes. Pskel comes pre-setup with MySQL as a example. If you want to add something, you can easily do so by editing the `compose.yaml`.

#### Can I use a debug version of PHP?

A debug build of PHP is included in advance. Debug builds using GCC and Clang are available, and Valgrind support is enabled. With the Clang build, you can also use MemorySanitizer.

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

- `debug-php`
- `gcc-valgrind-php`
- `clang-msan-php`
- `clang-asan-php`
- `clang-ubsan-php`

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

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

#### Can I debug using gdb?

Yes. Build using the debug version of PHP and run as follows:

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

#### Can I develop using something other than Visual Studio Code?
Expand Down
5 changes: 2 additions & 3 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
services:
dev:
shell:
build:
context: ./
dockerfile: ./Dockerfile
cap_add:
- SYS_PTRACE
- SYS_ADMIN
security_opt:
- seccomp:unconfined
privileged: true
tty: true
command: ["sleep", "infinity"]
# depends_on:
# - mysql
# mysql:
Expand Down
Loading

0 comments on commit 7b490fd

Please sign in to comment.