Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,15 @@ jobs:
if: "!(contains(matrix.os, 'macos') && matrix.rust == 'nightly')"
run: cargo test --release --workspace --features closure,anyhow,runtime,observer --no-fail-fast
test-embed:
name: Test with embed (NTS)
name: Test with embed (${{ matrix.label }})
runs-on: ubuntu-latest
strategy:
matrix:
include:
- phpts: nts
label: NTS
- phpts: ts
label: TS
env:
clang: "17"
php_version: "8.5"
Expand All @@ -179,19 +186,39 @@ jobs:
uses: actions/checkout@v6

- name: Setup PHP
if: matrix.phpts == 'nts'
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.php_version }}
env:
debug: true

- name: Setup PHP ZTS repository
if: matrix.phpts == 'ts'
# setup-php does not provide a ZTS embed package on Ubuntu.
run: |
PHP_VERSION="${{ env.php_version }}"
PHP_VERSION="${PHP_VERSION//./}"
KEY_FILE="/etc/apt/keyrings/henderkes${PHP_VERSION}.asc"
REPO_LINE="deb [signed-by=${KEY_FILE}] https://pkg.henderkes.com/api/packages/${PHP_VERSION}/debian php-zts main"

sudo mkdir -p /etc/apt/keyrings
sudo curl -fsSL "https://pkg.henderkes.com/api/packages/${PHP_VERSION}/debian/repository.key" -o "${KEY_FILE}"
echo "${REPO_LINE}" | sudo tee "/etc/apt/sources.list.d/static-php${PHP_VERSION}.list" > /dev/null
sudo apt update -y

- name: Install PHP ZTS packages
if: matrix.phpts == 'ts'
run: sudo apt install -y php-zts-cli php-zts-devel php-zts-embed

- name: Setup Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: rustfmt, clippy

- name: Install libphp-embed
if: matrix.phpts == 'nts'
run: sudo apt update -y && sudo apt install -y libphp${{ env.php_version }}-embed-dbgsym

- name: Install cargo-expand
Expand Down Expand Up @@ -223,6 +250,22 @@ jobs:
echo "LLVM_VERSION=${{ steps.clang.outputs.version }}" >> $GITHUB_ENV
echo "LLVM_CONFIG_PATH=${{ runner.temp }}/llvm-${{ env.clang }}/bin/llvm-config" >> $GITHUB_ENV

- name: Configure PHP ZTS environment
if: matrix.phpts == 'ts'
# ext-php-rs links embed builds with `-lphp`, so provide a generic soname.
run: |
PHP_VERSION="${{ env.php_version }}"
PHP_VERSION="${PHP_VERSION//./}"
PHP_ZTS_LIB_DIR="${RUNNER_TEMP}/php-zts-lib"

mkdir -p "${PHP_ZTS_LIB_DIR}"
ln -sf "/usr/lib/libphp-zts-${PHP_VERSION}.so" "${PHP_ZTS_LIB_DIR}/libphp.so"
{
echo "PHP=/usr/bin/php-zts"
echo "PHP_CONFIG=/usr/bin/php-config-zts"
echo "RUSTFLAGS=${RUSTFLAGS:+${RUSTFLAGS} }-L native=${PHP_ZTS_LIB_DIR}"
} >> "${GITHUB_ENV}"

- name: Test with embed feature
run: cargo test --workspace --release --features closure,embed,anyhow,smartstring,observer,indexmap --no-fail-fast

Expand Down Expand Up @@ -266,4 +309,4 @@ jobs:
-v $(pwd):/workspace \
-w /workspace \
extphprs/ext-php-rs:musl-${{ matrix.php }}-${{ matrix.phpts[1] }} \
test --workspace --release --features closure,anyhow,runtime,observer --no-fail-fast
test --workspace --release --features closure,anyhow,runtime,observer --no-fail-fast
32 changes: 23 additions & 9 deletions tests/src/integration/observer/observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
observer_test_reset();

// Define a user function to observe
function my_test_function(): string
function my_test_function(string $suffix = ""): string
{
return "hello";
return "hello{$suffix}";
}

// Define another user function
Expand All @@ -22,10 +22,22 @@ function another_function(int $x): int
// Note: The observer functions themselves are internal (Rust) functions,
// so they should NOT be counted by our observer which filters to user functions only.

// Call user functions
my_test_function();
another_function(5);
my_test_function();
// Resolve callables at runtime so opcache cannot fold these calls away.
$user_calls = [
[getenv('EXT_PHP_RS_OBSERVER_FN1') ?: 'my_test_function', ['']],
[getenv('EXT_PHP_RS_OBSERVER_FN2') ?: 'another_function', [5]],
[getenv('EXT_PHP_RS_OBSERVER_FN3') ?: 'my_test_function', [' again']],
];

$results = [];
foreach ($user_calls as [$function, $args]) {
$results[] = $function(...$args);
}

assert(
$results === ['hello', 10, 'hello again'],
'Unexpected results from observed user function calls',
);

// Get counts after calling user functions
$call_count = observer_test_get_call_count();
Expand All @@ -39,9 +51,9 @@ function another_function(int $x): int
assert($call_count === $end_count, "Call count and end count should match");

// Test nested function calls
function outer(): int
function outer(callable $callback): int
{
return inner();
return $callback();
}

function inner(): int
Expand All @@ -50,7 +62,9 @@ function inner(): int
}

observer_test_reset();
$result = outer();
$outer = getenv('EXT_PHP_RS_OUTER_FN') ?: 'outer';
$inner = getenv('EXT_PHP_RS_INNER_FN') ?: 'inner';
$result = $outer($inner);
assert($result === 42, "Nested call should return 42");

$nested_call_count = observer_test_get_call_count();
Expand Down
Loading