sanitizers.yaml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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
  32. LD_LIBRARY_PATH: ${{ github.workspace }}/php/target/lib
  33. steps:
  34. -
  35. name: Remove local PHP
  36. run: sudo apt-get remove --purge --autoremove 'php*' 'libmemcached*'
  37. -
  38. uses: actions/checkout@v4
  39. -
  40. uses: actions/setup-go@v5
  41. with:
  42. go-version: '1.22'
  43. cache-dependency-path: |
  44. go.sum
  45. caddy/go.sum
  46. -
  47. name: Determine PHP version
  48. id: determine-php-version
  49. run: |
  50. curl -fsSL 'https://www.php.net/releases/index.php?json&max=1&version=8.3' -o version.json
  51. echo version="$(jq -r 'keys[0]' version.json)" >> "$GITHUB_OUTPUT"
  52. echo archive="$(jq -r '.[] .source[] | select(.filename |endswith(".xz")) | "https://www.php.net/distributions/" + .filename' version.json)" >> "$GITHUB_OUTPUT"
  53. -
  54. name: Cache PHP
  55. id: cache-php
  56. uses: actions/cache@v4
  57. with:
  58. path: php/target
  59. key: php-sanitizers-${{ matrix.sanitizer }}-${{ runner.arch }}-${{ steps.determine-php-version.outputs.version }}
  60. -
  61. if: steps.cache-php.outputs.cache-hit != 'true'
  62. name: Compile PHP
  63. run: |
  64. mkdir php/
  65. curl -fsSL "${{ steps.determine-php-version.outputs.archive }}" | tar -Jx -C php --strip-components=1
  66. cd php/
  67. ./configure \
  68. CFLAGS="$CFLAGS" \
  69. LDFLAGS="$LDFLAGS" \
  70. --enable-debug \
  71. --enable-embed \
  72. --enable-zts \
  73. --enable-option-checking=fatal \
  74. --disable-zend-signals \
  75. --without-sqlite3 \
  76. --without-pdo-sqlite \
  77. --without-libxml \
  78. --disable-dom \
  79. --disable-simplexml \
  80. --disable-xml \
  81. --disable-xmlreader \
  82. --disable-xmlwriter \
  83. --without-pcre-jit \
  84. --disable-opcache-jit \
  85. --disable-cli \
  86. --disable-cgi \
  87. --disable-phpdbg \
  88. --without-pear \
  89. --disable-mbregex \
  90. --enable-werror \
  91. ${{ matrix.sanitizer == 'msan' && '--enable-memory-sanitizer' || '' }} \
  92. --prefix="$(pwd)/target/"
  93. make -j"$(getconf _NPROCESSORS_ONLN)"
  94. make install
  95. -
  96. name: Add PHP to the PATH
  97. run: echo "$(pwd)/php/target/bin" >> "$GITHUB_PATH"
  98. -
  99. name: Set Set CGO flags
  100. run: |
  101. {
  102. echo "CGO_CFLAGS=$CFLAGS $(php-config --includes)"
  103. echo "CGO_LDFLAGS=$LDFLAGS $(php-config --ldflags) $(php-config --libs)"
  104. } >> "$GITHUB_ENV"
  105. -
  106. name: Compile tests
  107. run: go test -${{ matrix.sanitizer }} -v -x -c
  108. -
  109. name: Run tests
  110. run: ./frankenphp.test -test.v