Add asan usage

This commit is contained in:
Florian Engelhardt 2026-01-08 15:44:54 +01:00
parent 5efa2a774e
commit 4c9c2be10e
No known key found for this signature in database
6 changed files with 62 additions and 3 deletions

View File

@ -41,6 +41,7 @@ Setup PHP with required extensions, php.ini configuration, code-coverage support
- [Nightly Build Setup](#nightly-build-setup)
- [Debug Build Setup](#debug-build-setup)
- [Thread Safe Setup](#thread-safe-setup)
- [ASAN Build Setup](#asan-build-setup)
- [Force Update Setup](#force-update-setup)
- [Verbose Setup](#verbose-setup)
- [Multi-Arch Setup](#multi-arch-setup)
@ -463,6 +464,13 @@ Disable coverage for these reasons:
- Accepts a `string` in csv-format. For example: `phpunit, phpcs`
- See [tools support](#wrench-tools-support) for tools supported.
#### `asan` (optional)
- Specify to set up PHP with AddressSanitizer (ASAN) for memory error detection.
- Accepts `true` or `false`.
- Only available for PHP 8.0 and above on Linux runners.
- See [ASAN build setup](#asan-build-setup) for more info.
#### `github-token` (optional)
- Specify the GitHub token to use for authentication.
@ -621,6 +629,43 @@ jobs:
phpts: ts # specify ts or nts
```
### ASAN Build Setup
> Set up PHP with AddressSanitizer (ASAN) for memory error detection.
- ASAN builds include both AddressSanitizer and UndefinedBehaviorSanitizer (UBSan).
- Only available for PHP 8.0 and above on Linux runners.
- Useful for detecting memory errors such as buffer overflows, use-after-free, and memory leaks.
```yaml
jobs:
run:
runs-on: ubuntu-latest
name: Setup PHP with ASAN
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
asan: true
```
You can combine ASAN with other options:
```yaml
- name: Setup PHP with ASAN and thread safety
uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
asan: true
env:
phpts: ts
```
> [!NOTE]
> - ASAN builds have a performance overhead due to the instrumentation, so they are recommended for testing and debugging only.
> - You can configure ASAN behavior using the `ASAN_OPTIONS` environment variable in your test steps.
### Force Update Setup
> Update to the latest patch of PHP versions.

View File

@ -27,6 +27,9 @@ inputs:
tools:
description: 'Setup popular tools globally.'
required: false
asan:
description: 'Setup PHP with Address Sanitizer (ASAN). PHP 8.0+ on Linux only.'
required: false
github-token:
description: 'GitHub token to use for authentication.'
default: ${{ github.token }}

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -53,6 +53,7 @@ export async function getScript(os: string): Promise<string> {
export async function setEnv(): Promise<void> {
process.env['fail_fast'] = await utils.getInput('fail-fast', false);
process.env['GITHUB_TOKEN'] ??= await utils.getInput('github-token', false);
process.env['ASAN'] = await utils.getInput('asan', false);
}
/**

View File

@ -114,7 +114,7 @@ add_devtools() {
# Function to setup PHP from the shivammathur/php-builder builds.
setup_php_builder() {
run_script "php-builder" "${runner:?}" "$version" "${debug:?}" "${ts:?}"
run_script "php-builder" "${runner:?}" "$version" "${debug:?}" "${ts:?}" "${asan:-}"
}
# Function to setup PHP 5.3, PHP 5.4 and PHP 5.5.
@ -186,7 +186,15 @@ update_php() {
# Function to install PHP.
add_php() {
if [ "${runner:?}" = "self-hosted" ] || [ "${use_package_cache:-true}" = "false" ]; then
# ASAN is only supported for PHP 8.0+
if [[ -n "${asan:-}" && ! "$version" =~ ^8\. ]]; then
add_log "${cross:?}" "PHP" "ASAN is only supported for PHP 8.0+"
exit 1
fi
# ASAN builds are only available from php-builder
if [[ -n "${asan:-}" ]]; then
setup_php_builder
elif [ "${runner:?}" = "self-hosted" ] || [ "${use_package_cache:-true}" = "false" ]; then
if [[ "$version" =~ ${php_builder_versions:?} || "$ts" = "zts" ]]; then
setup_php_builder
else

View File

@ -52,6 +52,7 @@ read_env() {
update="${update:-${UPDATE:-false}}"
[ "${debug:-${DEBUG:-false}}" = "true" ] && debug=debug && update=true || debug=release
[[ "${phpts:-${PHPTS:-nts}}" = "ts" || "${phpts:-${PHPTS:-nts}}" = "zts" ]] && ts=zts && update=true || ts=nts
[[ "${asan:-${ASAN:-false}}" = "true" ]] && asan=asan && update=true || asan=
fail_fast="${fail_fast:-${FAIL_FAST:-false}}"
[[ ( -z "$ImageOS" && -z "$ImageVersion" ) ||
( -n "$RUNNER_ENVIRONMENT" && "$RUNNER_ENVIRONMENT" = "self-hosted" ) ||
@ -78,6 +79,7 @@ read_env() {
export runner
export update
export ts
export asan
export tool_path_dir
}