Skip to content
Open
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
1 change: 1 addition & 0 deletions src/Package/Extension/simdjson.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function getSharedExtensionEnv(): array
if (!str_contains((string) $extra, '-lstdc++')) {
f_putenv('SPC_COMPILER_EXTRA=' . clean_spaces($extra . ' -lstdc++'));
}

$env['CFLAGS'] .= ' -Xclang -target-feature -Xclang +evex512';
$env['CXXFLAGS'] .= ' -Xclang -target-feature -Xclang +evex512';
}
Expand Down
1 change: 1 addition & 0 deletions src/Package/Library/libde265.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function buildUnix(): void
->addConfigureArgs(
'-DENABLE_SDL=OFF',
'-DENABLE_DECODER=OFF',
'-DENABLE_SIMD=OFF',
'-DHAVE_NEON=OFF',
)
->build();
Expand Down
70 changes: 54 additions & 16 deletions src/StaticPHP/Command/Dev/GenExtTestMatrixCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ public function handle(): int
// Separate into regular and virtual extensions (build-static:false excluded globally)
$all_regular = [];
$all_virtual = [];
$all_libraries = [];
foreach ($all as $pkg_name => $config) {
if (($config['type'] ?? '') === 'library') {
$all_libraries[$pkg_name] = $config;
continue;
}
if (($config['type'] ?? '') !== 'php-extension') {
continue;
}
Expand Down Expand Up @@ -154,10 +159,7 @@ public function handle(): int
$raw,
fn ($d) => isset($pool_set[$d]) && $d !== $pkg_name
));
$os_lib_deps[$this->displayName($pkg_name)] = array_values(array_filter(
$raw,
fn ($d) => !str_starts_with($d, 'ext-')
));
$os_lib_deps[$this->displayName($pkg_name)] = $this->collectLibraryDeps($raw, $all_libraries, $os);
}
$all_ext_lib_deps[$os] = $os_lib_deps;

Expand Down Expand Up @@ -246,22 +248,23 @@ public function handle(): int
}
}

if (!empty($filter_extensions)) {
$entries = array_values(array_filter($entries, function (array $entry) use ($filter_extensions): bool {
if (!empty($filter_extensions) || !empty($filter_libs)) {
$entries = array_values(array_filter($entries, function (array $entry) use ($filter_extensions, $filter_libs, $all_ext_lib_deps): bool {
$names = explode(',', $entry['extension']);
return count(array_intersect($names, $filter_extensions)) > 0;
}));
}

if (!empty($filter_libs)) {
$entries = array_values(array_filter($entries, function (array $entry) use ($filter_libs, $all_ext_lib_deps): bool {
$names = explode(',', $entry['extension']);
$lib_deps = $all_ext_lib_deps[$entry['os']] ?? [];
foreach ($names as $name) {
if (count(array_intersect($lib_deps[$name] ?? [], $filter_libs)) > 0) {
return true;
if (!empty($filter_extensions) && count(array_intersect($names, $filter_extensions)) > 0) {
return true;
}

if (!empty($filter_libs)) {
$lib_deps = $all_ext_lib_deps[$entry['os']] ?? [];
foreach ($names as $name) {
if (count(array_intersect($lib_deps[$name] ?? [], $filter_libs)) > 0) {
return true;
}
}
}

return false;
}));
}
Expand Down Expand Up @@ -300,6 +303,41 @@ private function displayName(string $pkg_name): string
return str_starts_with($pkg_name, 'ext-') ? substr($pkg_name, 4) : $pkg_name;
}

/**
* Collect direct and transitive library dependencies from a package dependency list.
*
* @param string[] $deps
* @param array<string, mixed[]> $library_configs
* @param array<string, true> $seen
*
* @return string[]
*/
private function collectLibraryDeps(array $deps, array $library_configs, string $platform, array $seen = []): array
{
$collected = [];
foreach ($deps as $dep) {
if (str_starts_with($dep, 'ext-') || isset($seen[$dep])) {
continue;
}

$seen[$dep] = true;
$collected[$dep] = $dep;

if (!isset($library_configs[$dep])) {
continue;
}

$child_deps = array_merge(
$this->resolvePlatformList($library_configs[$dep], 'depends', $platform),
$this->resolvePlatformList($library_configs[$dep], 'suggests', $platform),
);
foreach ($this->collectLibraryDeps($child_deps, $library_configs, $platform, $seen) as $child_dep) {
$collected[$child_dep] = $child_dep;
}
}
return array_values($collected);
}

/**
* Split orphans into batches such that no two conflicting extensions share a batch.
* Uses a greedy graph-coloring approach.
Expand Down
35 changes: 35 additions & 0 deletions tests/StaticPHP/Command/Dev/GenExtTestMatrixCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,31 @@ public function testForLibsFilter(): void
}
}

/**
* --for-libs must include extensions that depend on the library through other libraries.
*/
public function testForLibsFilterIncludesTransitiveLibraryDeps(): void
{
$matrix = $this->runMatrix(['--os' => 'Linux', '--for-libs' => 'libde265']);

$this->assertNotEmpty($matrix, '--for-libs=libde265 must yield at least one entry');
foreach ($matrix as $entry) {
$parts = explode(',', $entry['extension']);
$this->assertContains('imagick', $parts, "Entry {$entry['extension']} should not appear in --for-libs=libde265 results");
}
}

/**
* Multiple filters should include entries matching any changed package.
*/
public function testExtensionAndLibraryFiltersAreCombinedAsUnion(): void
{
$matrix = $this->runMatrix(['--os' => 'Linux', '--for-extensions' => 'simdjson', '--for-libs' => 'libde265']);

$this->assertNotEmpty($this->findEntriesContaining($matrix, 'simdjson'), 'simdjson entry must be included');
$this->assertNotEmpty($this->findEntriesContaining($matrix, 'imagick'), 'imagick entry must be included through libde265');
}

/**
* --tier2 must produce only Tier2 runners and no Windows entries.
*/
Expand Down Expand Up @@ -258,14 +283,17 @@ private function findEntriesContaining(array $matrix, string ...$names): array
* - ext-swoole-hook-* virtual (arg-type: none) — must be bundled with swoole
* - ext-curl simple orphan, depended on by swoole but must NOT be pulled into swoole entry
* - ext-redis simple orphan
* - ext-simdjson simple orphan used for combined filter tests
* - ext-xml depends on lib 'libxml2'
* - ext-dom depends on ext-xml (DFS chain)
* - ext-imagick depends on imagemagick -> libheif -> libde265
* - ext-linux-only restricted to Linux via os: [Linux]
*/
private static function buildFixture(): array
{
// php-extension must be a non-empty assoc array ([] fails is_assoc_array() check).
$ext = static fn (array $phpExt = ['arg-type' => 'standard'], array $topLevel = []): array => array_merge(['type' => 'php-extension', 'php-extension' => $phpExt], $topLevel);
$lib = static fn (array $topLevel = []): array => array_merge(['type' => 'library', 'artifact' => ['source' => 'custom']], $topLevel);

return [
// Isolated standalones
Expand All @@ -279,11 +307,18 @@ private static function buildFixture(): array
// Simple orphans
'ext-curl' => $ext(),
'ext-redis' => $ext(),
'ext-simdjson' => $ext(),

// DFS chain: dom depends on xml; xml depends on lib 'libxml2'
'ext-xml' => $ext(['arg-type' => 'standard'], ['depends' => ['libxml2']]),
'ext-dom' => $ext(['arg-type' => 'standard'], ['depends' => ['ext-xml']]),

// Transitive library chain: imagick -> imagemagick -> libheif -> libde265
'ext-imagick' => $ext(['arg-type' => 'standard'], ['depends' => ['imagemagick']]),
'imagemagick' => $lib(['depends' => ['libheif']]),
'libheif' => $lib(['depends' => ['libde265']]),
'libde265' => $lib(),

// OS-restricted to Linux only
'ext-linux-only' => $ext(['os' => ['Linux']]),
];
Expand Down
Loading