ci: run sanitizers #21
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Sanitizers | |
on: | |
pull_request: | |
branches: | |
- main | |
paths-ignore: | |
- "docs/**" | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- "docs/**" | |
permissions: | |
contents: read | |
jobs: | |
# Adapted from https://github.com/beberlei/hdrhistogram-php | |
sanitizers: | |
runs-on: ubuntu-latest | |
env: | |
CFLAGS: -g -O0 -fsanitize=address -DZEND_TRACK_ARENA_ALLOC | |
LDFLAGS: -fsanitize=address | |
CC: clang-18 | |
CXX: clang++-18 | |
steps: | |
- | |
uses: actions/checkout@v4 | |
- | |
uses: actions/setup-go@v5 | |
with: | |
go-version: "1.22" | |
cache-dependency-path: | | |
go.sum | |
caddy/go.sum | |
- | |
name: Install LLVM | |
run: sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" | |
- | |
name: Determine PHP version | |
id: determine-php-version | |
run: | | |
curl -fsSL 'https://www.php.net/releases/index.php?json&max=1&version=8.3' -o version.json | |
echo version="$(jq -r 'keys[0]') version.json" >> "$GITHUB_OUTPUT" | |
echo archive="$(jq -r '.[] .source[] | select(.filename |endswith(".xz")) | "https://www.php.net/distributions/" + .filename' version.json)" >> "$GITHUB_OUTPUT" | |
- | |
name: Cache PHP | |
id: cache-php | |
uses: actions/cache@v4 | |
with: | |
path: php/target/ | |
key: php-sanitizers-${{ runner.arch }}-${{ steps.determine-php-version.outputs.version }} | |
- | |
if: steps.cache-php.outputs.cache-hit != 'true' | |
name: Compile PHP | |
run: | | |
sudo apt-get remove --purge --autoremove 'php*-*' 'libmemcached*' | |
mkdir php/ | |
curl -fsSL "${{ steps.determine-php-version.outputs.archive }}" | tar -Jx -C php --strip-components=1 | |
cd php/ | |
./configure \ | |
--enable-debug \ | |
--enable-embed \ | |
--enable-zts \ | |
--disable-zend-signals \ | |
--disable-cli \ | |
--disable-cgi \ | |
--disable-phpdbg \ | |
--prefix="$(pwd)/target/" | |
make -j"$(getconf _NPROCESSORS_ONLN)" | |
make install | |
- | |
name: Add PHP to the PATH | |
run: | | |
echo "$(pwd)/php/target/bin" >> "$GITHUB_PATH" | |
- | |
name: Set CGO flags | |
run: | | |
{ | |
echo "LIBRARY_PATH=$LIBRARY_PATH:$(pwd)/php/target/lib" | |
# https://github.com/google/sanitizers/wiki/AddressSanitizerAsDso | |
echo "LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so)" | |
echo "CGO_CFLAGS=$CFLAGS -shared-libasan $(php-config --includes)" | |
echo "CGO_LDLAGS=$LDFLAGS -shared-libasan $(php-config --ldflags || true) $(php-config --libs || true)" | |
} >> "$GITHUB_ENV" | |
- | |
name: Run library tests with sanitizers | |
run: go test -asan -v ./... |