sanitizers.yaml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ---
  2. name: Sanitizers
  3. on:
  4. pull_request:
  5. branches:
  6. - main
  7. paths-ignore:
  8. - "docs/**"
  9. push:
  10. branches:
  11. - main
  12. paths-ignore:
  13. - "docs/**"
  14. permissions:
  15. contents: read
  16. jobs:
  17. # Adapted from https://github.com/beberlei/hdrhistogram-php
  18. sanitizers:
  19. name: ${{ matrix.sanitizer }}
  20. runs-on: ubuntu-latest
  21. strategy:
  22. fail-fast: false
  23. matrix:
  24. sanitizer: ["asan", "msan"]
  25. env:
  26. CFLAGS: -g -O0 -fsanitize=${{ matrix.sanitizer == 'asan' && 'address' || 'memory' }} -DZEND_TRACK_ARENA_ALLOC
  27. LDFLAGS: -fsanitize=${{ matrix.sanitizer == 'asan' && 'address' || 'memory' }}
  28. CC: clang
  29. CXX: clang++
  30. USE_ZEND_ALLOC: 0
  31. LIBRARY_PATH: ${{ github.workspace }}/php/target/lib:${{ github.workspace }}/watcher/target/lib
  32. LD_LIBRARY_PATH: ${{ github.workspace }}/php/target/lib
  33. steps:
  34. - name: Remove local PHP
  35. run: sudo apt-get remove --purge --autoremove 'php*' 'libmemcached*'
  36. - uses: actions/checkout@v4
  37. - uses: actions/setup-go@v5
  38. with:
  39. go-version: "1.22"
  40. cache-dependency-path: |
  41. go.sum
  42. caddy/go.sum
  43. - name: Determine PHP version
  44. id: determine-php-version
  45. run: |
  46. curl -fsSL 'https://www.php.net/releases/index.php?json&max=1&version=8.4' -o version.json
  47. echo version="$(jq -r 'keys[0]' version.json)" >> "$GITHUB_OUTPUT"
  48. echo archive="$(jq -r '.[] .source[] | select(.filename |endswith(".xz")) | "https://www.php.net/distributions/" + .filename' version.json)" >> "$GITHUB_OUTPUT"
  49. - name: Cache PHP
  50. id: cache-php
  51. uses: actions/cache@v4
  52. with:
  53. path: php/target
  54. key: php-sanitizers-${{ matrix.sanitizer }}-${{ runner.arch }}-${{ steps.determine-php-version.outputs.version }}
  55. - if: steps.cache-php.outputs.cache-hit != 'true'
  56. name: Compile PHP
  57. run: |
  58. mkdir php/
  59. curl -fsSL "${{ steps.determine-php-version.outputs.archive }}" | tar -Jx -C php --strip-components=1
  60. cd php/
  61. ./configure \
  62. CFLAGS="$CFLAGS" \
  63. LDFLAGS="$LDFLAGS" \
  64. --enable-debug \
  65. --enable-embed \
  66. --enable-zts \
  67. --enable-option-checking=fatal \
  68. --disable-zend-signals \
  69. --without-sqlite3 \
  70. --without-pdo-sqlite \
  71. --without-libxml \
  72. --disable-dom \
  73. --disable-simplexml \
  74. --disable-xml \
  75. --disable-xmlreader \
  76. --disable-xmlwriter \
  77. --without-pcre-jit \
  78. --disable-opcache-jit \
  79. --disable-cli \
  80. --disable-cgi \
  81. --disable-phpdbg \
  82. --without-pear \
  83. --disable-mbregex \
  84. --enable-werror \
  85. ${{ matrix.sanitizer == 'msan' && '--enable-memory-sanitizer' || '' }} \
  86. --prefix="$(pwd)/target/"
  87. make -j"$(getconf _NPROCESSORS_ONLN)"
  88. make install
  89. - name: Add PHP to the PATH
  90. run: echo "$(pwd)/php/target/bin" >> "$GITHUB_PATH"
  91. - name: Install e-dant/watcher
  92. uses: ./.github/actions/watcher
  93. - name: Set Set CGO flags
  94. run: |
  95. {
  96. echo "CGO_CFLAGS=$CFLAGS -I${PWD}/watcher/target/include $(php-config --includes)"
  97. echo "CGO_LDFLAGS=$LDFLAGS $(php-config --ldflags) $(php-config --libs)"
  98. } >> "$GITHUB_ENV"
  99. - name: Compile tests
  100. run: go test ${{ matrix.sanitizer == 'msan' && '-tags=nowatcher' || '' }} -${{ matrix.sanitizer }} -v -x -c
  101. - name: Run tests
  102. run: ./frankenphp.test -test.v