Skip to content

Commit af31876

Browse files
realFlowControlshivammathur
authored andcommitted
Add ASAN/UBSan PHP versions
1 parent 5a9ba12 commit af31876

14 files changed

Lines changed: 230 additions & 44 deletions

File tree

.github/workflows/build.yml

Lines changed: 65 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,36 @@ on:
2020
description: 'OS versions to build on'
2121
default: 'ubuntu:22.04 ubuntu:24.04 arm64v8/ubuntu:22.04 arm64v8/ubuntu:24.04 debian:11 debian:12 debian:trixie'
2222
required: false
23+
workflow_call:
24+
inputs:
25+
build-mode:
26+
description: 'Build mode: --build-all or --build-new'
27+
default: '--build-new'
28+
required: false
29+
type: string
30+
php-source:
31+
description: 'PHP source: --web-php or --php-src'
32+
default: ''
33+
required: false
34+
type: string
35+
php-version:
36+
description: 'PHP version to build'
37+
default: '8.4'
38+
required: false
39+
type: string
40+
container-os-versions:
41+
description: 'OS versions to build on'
42+
default: 'ubuntu:22.04 ubuntu:24.04 arm64v8/ubuntu:22.04 arm64v8/ubuntu:24.04 debian:11 debian:12 debian:trixie'
43+
required: false
44+
type: string
2345

2446
env:
2547
CONTAINER_OS_LIST: ubuntu:22.04 ubuntu:24.04 arm64v8/ubuntu:22.04 arm64v8/ubuntu:24.04 debian:11 debian:12 debian:trixie
2648
RUNNER_OS_LIST: ubuntu-22.04 ubuntu-24.04 ubuntu-22.04-arm ubuntu-24.04-arm
27-
PHP_LIST: ${{ inputs.php-version }}
49+
PHP_LIST: ${{ inputs.php-version || '8.4' }}
2850
SAPI_LIST: apache2 cgi cli embed fpm phpdbg
2951
BUILD_LIST: nts zts
30-
PHP_SOURCE: ${{ inputs.php-source }}
52+
PHP_SOURCE: ${{ inputs.php-source || '--web-php' }}
3153
CONTAINER_BASE: ubuntu-24.04
3254
CONTAINER_BASE_ARM: ubuntu-24.04-arm
3355

@@ -55,8 +77,8 @@ jobs:
5577
CONTAINER_BASE_ARM: ${{ env.CONTAINER_BASE_ARM }}
5678
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5779
RUNNER_OS_LIST: ${{ env.RUNNER_OS_LIST }}
58-
PHP_LIST: ${{ inputs.php-version }}
59-
PHP_SOURCE: ${{ inputs.php-source || '--web-php' }}
80+
PHP_LIST: ${{ env.PHP_LIST }}
81+
PHP_SOURCE: ${{ env.PHP_SOURCE }}
6082
SAPI_LIST: ${{ env.SAPI_LIST }}
6183
BUILD_LIST: ${{ env.BUILD_LIST }}
6284
run: bash scripts/get-matrix.sh
@@ -82,18 +104,19 @@ jobs:
82104
- name: Build and package SAPI
83105
run: bash scripts/build.sh build_sapi "${SAPI}"
84106
env:
107+
ASAN: ${{ matrix.asan }}
85108
BUILD: ${{ matrix.build }}
86109
GITHUB_MESSAGE: ${{ github.event.head_commit.message || inputs.build-mode }}
87110
GITHUB_REPOSITORY: ${{ github.repository }}
88111
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89112
PHP_VERSION: ${{ matrix.php-version }}
90-
PHP_SOURCE: ${{ github.event.inputs.php-source }}
113+
PHP_SOURCE: ${{ env.PHP_SOURCE }}
91114
SAPI: ${{ matrix.sapi }}
92115

93116
- name: Upload Artifact
94117
uses: actions/upload-artifact@v7
95118
with:
96-
name: php-sapi-${{ matrix.sapi }}-${{ matrix.php-version }}-${{ matrix.build }}+${{ matrix.dist }}-${{ matrix.dist-version }}
119+
name: php-sapi-${{ matrix.sapi }}-${{ matrix.php-version }}-${{ matrix.build }}${{ matrix.asan && '-asan' || '' }}+${{ matrix.dist }}-${{ matrix.dist-version }}
97120
path: /tmp/debian/*.zst
98121

99122
package:
@@ -109,6 +132,12 @@ jobs:
109132
- name: Checkout
110133
uses: actions/checkout@v6
111134

135+
- name: Configure ASAN runtime
136+
if: matrix.asan == 'asan'
137+
run: |
138+
echo "ASAN_OPTIONS=detect_leaks=0" >> "$GITHUB_ENV"
139+
echo "ZEND_DONT_UNLOAD_MODULES=1" >> "$GITHUB_ENV"
140+
112141
- name: Install required packages
113142
run: bash scripts/install-requirements.sh
114143
env:
@@ -117,7 +146,7 @@ jobs:
117146

118147
- uses: actions/download-artifact@v8
119148
with:
120-
pattern: php-sapi-*-${{ matrix.php-version }}-${{ matrix.build }}+${{ matrix.dist }}-${{ matrix.dist-version }}
149+
pattern: php-sapi-*-${{ matrix.php-version }}-${{ matrix.build }}${{ matrix.asan && '-asan' || '' }}+${{ matrix.dist }}-${{ matrix.dist-version }}
121150
path: /tmp
122151
merge-multiple: true
123152

@@ -133,6 +162,7 @@ jobs:
133162
- name: Merge SAPI builds
134163
run: bash scripts/build.sh merge
135164
env:
165+
ASAN: ${{ matrix.asan }}
136166
BUILD: ${{ matrix.build }}
137167
SAPI_LIST: ${{ env.SAPI_LIST }}
138168
GITHUB_USER: ${{ github.repository_owner }}
@@ -143,20 +173,22 @@ jobs:
143173
GITHUB_REPOSITORY: ${{ github.repository }}
144174
GITHUB_WORKSPACE: ${{ github.workspace }}
145175
PHP_VERSION: ${{ matrix.php-version }}
146-
PHP_SOURCE: ${{ github.event.inputs.php-source }}
176+
PHP_SOURCE: ${{ env.PHP_SOURCE }}
147177

148178
- name: Build extensions
149179
run: bash scripts/build.sh build_extensions
150180
env:
181+
ASAN: ${{ matrix.asan }}
151182
BUILD: ${{ matrix.build }}
152183
SAPI_LIST: ${{ env.SAPI_LIST }}
153184
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
154185
PHP_VERSION: ${{ matrix.php-version }}
155-
PHP_SOURCE: ${{ github.event.inputs.php-source }}
186+
PHP_SOURCE: ${{ env.PHP_SOURCE }}
156187

157188
- name: Package build
158189
run: bash scripts/build.sh package
159190
env:
191+
ASAN: ${{ matrix.asan }}
160192
BUILD: ${{ matrix.build }}
161193
SAPI_LIST: ${{ env.SAPI_LIST }}
162194
GITHUB_USER: ${{ github.repository_owner }}
@@ -167,12 +199,12 @@ jobs:
167199
GITHUB_REPOSITORY: ${{ github.repository }}
168200
GITHUB_WORKSPACE: ${{ github.workspace }}
169201
PHP_VERSION: ${{ matrix.php-version }}
170-
PHP_SOURCE: ${{ github.event.inputs.php-source }}
202+
PHP_SOURCE: ${{ env.PHP_SOURCE }}
171203

172204
- name: Upload Artifact
173205
uses: actions/upload-artifact@v7
174206
with:
175-
name: php${{ matrix.php-version }}-${{ matrix.build }}+${{ matrix.dist }}-${{ matrix.dist-version }}
207+
name: php${{ matrix.php-version }}-${{ matrix.build }}${{ matrix.asan && '-asan' || '' }}+${{ matrix.dist }}-${{ matrix.dist-version }}
176208
path: |
177209
/tmp/*.xz
178210
/tmp/*.zst
@@ -219,15 +251,21 @@ jobs:
219251
- name: Checkout
220252
uses: actions/checkout@v6
221253

254+
- name: Configure ASAN runtime
255+
if: matrix.asan == 'asan'
256+
run: |
257+
echo "ASAN_OPTIONS=detect_leaks=0" >> "$GITHUB_ENV"
258+
echo "ZEND_DONT_UNLOAD_MODULES=1" >> "$GITHUB_ENV"
259+
222260
- uses: actions/download-artifact@v8
223261
with:
224-
name: php${{ matrix.php-version }}-${{ matrix.build }}+${{ matrix.dist }}-${{ matrix.dist-version }}
262+
name: php${{ matrix.php-version }}-${{ matrix.build }}${{ matrix.asan && '-asan' || '' }}+${{ matrix.dist }}-${{ matrix.dist-version }}
225263
path: /tmp
226264

227265
- name: Install PHP
228266
run: |
229267
sed -i '/download/d' scripts/install.sh
230-
bash scripts/install.sh ${{ matrix.php-version }} local ${{ matrix.debug }} ${{ matrix.build }}
268+
bash scripts/install.sh ${{ matrix.php-version }} local ${{ matrix.debug }} ${{ matrix.build }} ${{ matrix.asan }}
231269
232270
- name: Test
233271
run: |
@@ -260,15 +298,21 @@ jobs:
260298
- name: Checkout
261299
uses: actions/checkout@v6
262300

301+
- name: Configure ASAN runtime
302+
if: matrix.asan == 'asan'
303+
run: |
304+
echo "ASAN_OPTIONS=detect_leaks=0" >> "$GITHUB_ENV"
305+
echo "ZEND_DONT_UNLOAD_MODULES=1" >> "$GITHUB_ENV"
306+
263307
- uses: actions/download-artifact@v8
264308
with:
265-
name: php${{ matrix.php-version }}-${{ matrix.build }}+${{ matrix.os }}
309+
name: php${{ matrix.php-version }}-${{ matrix.build }}${{ matrix.asan && '-asan' || '' }}+${{ matrix.os }}
266310
path: /tmp
267311

268312
- name: Install PHP
269313
run: |
270314
sed -i '/download/d' scripts/install.sh
271-
bash scripts/install.sh ${{ matrix.php-version }} github ${{ matrix.debug }} ${{ matrix.build }}
315+
bash scripts/install.sh ${{ matrix.php-version }} github ${{ matrix.debug }} ${{ matrix.build }} ${{ matrix.asan }}
272316
273317
- name: Test
274318
run: |
@@ -289,7 +333,7 @@ jobs:
289333
release-container-only:
290334
needs: [get-matrix, local-test]
291335
runs-on: ubuntu-latest
292-
if: "!contains(github.event.head_commit.message, 'skip-release') && contains(needs.get-matrix.outputs.container_only, 'true')"
336+
if: github.event_name != 'pull_request' && !contains(github.event.head_commit.message || inputs.build-mode, 'skip-release') && contains(needs.get-matrix.outputs.container_only, 'true')
293337

294338
steps:
295339
- name: Checkout
@@ -307,13 +351,13 @@ jobs:
307351
env:
308352
GITHUB_MESSAGE: ${{ github.event.head_commit.message || inputs.build-mode }}
309353
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
310-
PHP_LIST: ${{ inputs.php-version }}
311-
PHP_SOURCE: ${{ github.event.inputs.php-source }}
354+
PHP_LIST: ${{ env.PHP_LIST }}
355+
PHP_SOURCE: ${{ env.PHP_SOURCE }}
312356

313357
release:
314358
needs: [get-matrix, local-test, github-test]
315359
runs-on: ubuntu-latest
316-
if: "!contains(github.event.head_commit.message, 'skip-release') && contains(needs.get-matrix.outputs.container_only, 'false')"
360+
if: github.event_name != 'pull_request' && !contains(github.event.head_commit.message || inputs.build-mode, 'skip-release') && contains(needs.get-matrix.outputs.container_only, 'false')
317361

318362
steps:
319363
- name: Checkout
@@ -331,5 +375,5 @@ jobs:
331375
env:
332376
GITHUB_MESSAGE: ${{ github.event.head_commit.message || inputs.build-mode }}
333377
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
334-
PHP_LIST: ${{ inputs.php-version }}
335-
PHP_SOURCE: ${{ github.event.inputs.php-source }}
378+
PHP_LIST: ${{ env.PHP_LIST }}
379+
PHP_SOURCE: ${{ env.PHP_SOURCE }}

.github/workflows/ci.yml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
name: CI
22

33
on:
4+
pull_request:
5+
branches:
6+
- main
7+
types:
8+
- opened
9+
- reopened
10+
- synchronize
11+
- ready_for_review
412
workflow_dispatch:
513
inputs:
614
build-mode:
@@ -45,15 +53,30 @@ jobs:
4553
- name: Get PHP versions
4654
id: set-php-versions
4755
env:
48-
COMMIT: ${{ github.event.head_commit.message || inputs.build-mode }}
56+
COMMIT: ${{ github.event.head_commit.message || inputs.build-mode || (github.event_name == 'pull_request' && '--build-all skip-release') || '--build-new' }}
4957
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5058
PHP_LIST: ${{ inputs.php-versions || env.PHP_LIST }}
5159
PHP_SOURCE: ${{ inputs.php-source || env.PHP_SOURCE }}
5260
run: bash scripts/get-php-versions.sh
5361

62+
pull-request-builds:
63+
needs: get-php-versions
64+
if: github.event_name == 'pull_request' && needs.get-php-versions.outputs.has_versions == 'true'
65+
strategy:
66+
fail-fast: false
67+
matrix:
68+
php-version: ${{ fromJson(needs.get-php-versions.outputs.php_versions) }}
69+
uses: ./.github/workflows/build.yml
70+
with:
71+
build-mode: --build-all skip-release
72+
container-os-versions: ubuntu:22.04 ubuntu:24.04 arm64v8/ubuntu:22.04 arm64v8/ubuntu:24.04 debian:11 debian:12 debian:trixie
73+
php-source: --web-php
74+
php-version: ${{ matrix.php-version }}
75+
secrets: inherit
76+
5477
dispatch-builds:
5578
needs: get-php-versions
56-
if: needs.get-php-versions.outputs.has_versions == 'true'
79+
if: github.event_name != 'pull_request' && needs.get-php-versions.outputs.has_versions == 'true'
5780
runs-on: ubuntu-latest
5881
env:
5982
BUILD_MODE: ${{ inputs.build-mode || '--build-new' }}

README.md

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- [Install](#install)
1515
- [Extensions](#extensions)
1616
- [JIT](#jit)
17+
- [ASAN](#asan-addresssanitizer)
1718
- [SAPI Support](#sapi-support)
1819
- [Builds](#builds)
1920
- [Uninstall](#uninstall)
@@ -42,15 +43,16 @@ chmod a+x ./install.sh
4243

4344
The installer takes the following options:
4445
```bash
45-
./install.sh <php-version> <release|debug> <nts|zts>
46+
./install.sh <php-version> [release|debug] [nts|zts] [asan]
4647
```
4748

48-
The `php-version` is required, and `release` and `nts` are the defaults.
49+
The `php-version` is required, and `release` and `nts` are the defaults.
4950

5051
- release: No debugging symbols
5152
- debug: With debugging symbols
5253
- nts: Non Thread Safe
5354
- zts: Thread Safe
55+
- asan: AddressSanitizer build (PHP 8.0+ only)
5456

5557
### Examples
5658

@@ -66,6 +68,12 @@ The `php-version` is required, and `release` and `nts` are the defaults.
6668
./install.sh 8.4 debug zts
6769
```
6870

71+
- or, to install `PHP 8.4` with AddressSanitizer (for memory error detection):
72+
73+
```bash
74+
./install.sh 8.4 asan
75+
```
76+
6977
- Finally, test your PHP version:
7078

7179
```bash
@@ -134,6 +142,35 @@ To disable JIT:
134142
switch_jit -v <php-version> -s <ALL|sapi-name> disable
135143
```
136144

145+
## ASAN (AddressSanitizer)
146+
147+
PHP 8.0 and above versions have builds with AddressSanitizer (ASAN) and UndefinedBehaviorSanitizer (UBSan) enabled. These builds are useful for detecting memory issues.
148+
149+
To install an ASAN build:
150+
151+
```bash
152+
./install.sh 8.4 asan
153+
```
154+
155+
You can combine ASAN with other options:
156+
157+
```bash
158+
# ASAN + Thread Safe
159+
./install.sh 8.4 zts asan
160+
161+
# ASAN + Debug symbols
162+
./install.sh 8.4 debug asan
163+
```
164+
165+
**Notes:**
166+
167+
- ASAN builds are only available for PHP 8.0 and above.
168+
- Running PHP with ASAN will be slower than regular builds due to the instrumentation overhead.
169+
- You can configure ASAN behavior using the `ASAN_OPTIONS` environment variable:
170+
```bash
171+
ASAN_OPTIONS=detect_leaks=1 php your_script.php
172+
```
173+
137174
## SAPI support
138175

139176
These SAPIs are installed by default:
@@ -160,7 +197,7 @@ switch_sapi -v <php-version> -s <sapi|sapi:server>
160197

161198
## Builds
162199

163-
The following releases have `nts` and `zts` builds for the following PHP versions along with builds with and without debugging symbols.
200+
The following releases have `nts` and `zts` builds for the following PHP versions along with builds with and without debugging symbols. PHP 8.0+ versions also include AddressSanitizer (ASAN) builds for memory error detection.
164201

165202
- [PHP 8.6.0-dev](https://github.com/shivammathur/php-builder/releases/tag/8.6)
166203
- [PHP 8.5.x](https://github.com/shivammathur/php-builder/releases/tag/8.5)

config/definitions/8.0

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
# Placeholder for thread-safe build.
130130
ZTS
131131

132+
# Placeholder for ASAN build.
133+
ASAN
134+
132135
# Placeholder for patch commands.
133136
PATCHES
134137

config/definitions/8.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
# Placeholder for thread-safe build.
130130
ZTS
131131

132+
# Placeholder for ASAN build.
133+
ASAN
134+
132135
# Placeholder for patch commands.
133136
PATCHES
134137

config/definitions/8.2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
# Placeholder for thread-safe build.
130130
ZTS
131131

132+
# Placeholder for ASAN build.
133+
ASAN
134+
132135
# Placeholder for patch commands.
133136
PATCHES
134137

config/definitions/8.3

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
# Placeholder for thread-safe build.
130130
ZTS
131131

132+
# Placeholder for ASAN build.
133+
ASAN
134+
132135
# Placeholder for patch commands.
133136
PATCHES
134137

0 commit comments

Comments
 (0)