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
3 changes: 2 additions & 1 deletion src/Package/Extension/rdkafka.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public function patchBeforeMake(): bool
#[CustomPhpConfigureArg('Linux')]
public function getUnixConfigureArg(bool $shared, PackageBuilder $builder): string
{
$pkgconf_libs = new SPCConfigUtil(['no_php' => true, 'libs_only_deps' => true])->getExtensionConfig($this);
$pkgconf_libs = new SPCConfigUtil(['no_php' => true, 'libs_only_deps' => true])
->configForResolvedBuild([$this->getName()], $this->getInstaller());
return '--with-rdkafka=' . ($shared ? 'shared,' : '') . $builder->getBuildRootPath() . " RDKAFKA_LIBS=\"{$pkgconf_libs['libs']}\"";
}
}
3 changes: 2 additions & 1 deletion src/Package/Extension/swoole.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public function getUnixConfigureArg(bool $shared, PackageBuilder $builder, Packa
$arg .= $installer->getPhpExtensionPackage('swoole-hook-mysql') ? ' --enable-mysqlnd' : ' --disable-mysqlnd';
$arg .= $installer->getPhpExtensionPackage('swoole-hook-sqlite') ? ' --enable-swoole-sqlite' : ' --disable-swoole-sqlite';
if ($installer->getPhpExtensionPackage('swoole-hook-odbc')) {
$config = new SPCConfigUtil()->getLibraryConfig($installer->getLibraryPackage('unixodbc'));
$config = new SPCConfigUtil(['no_php' => true, 'libs_only_deps' => true])
->configForResolvedBuild(['unixodbc'], $installer);
$arg .= " --with-swoole-odbc=unixODBC,{$builder->getBuildRootPath()} SWOOLE_ODBC_LIBS=\"{$config['libs']}\"";
}

Expand Down
2 changes: 1 addition & 1 deletion src/Package/Library/krb5.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function build(LibraryPackage $lib, PackageInstaller $installer, Toolchai

$resolved = array_keys($installer->getResolvedPackages());
$spc = new SPCConfigUtil(['no_php' => true, 'libs_only_deps' => true]);
$config = $spc->getPackageDepsConfig($lib->getName(), $resolved, include_suggests: true);
$config = $spc->getPackageDepsConfig($lib->getName(), $resolved);
$extraEnv = [
'CFLAGS' => '-fcommon',
'LIBS' => $config['libs'],
Expand Down
2 changes: 1 addition & 1 deletion src/Package/Library/postgresql.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function buildWin(LibraryPackage $lib): void
public function buildUnix(PackageInstaller $installer, PackageBuilder $builder): void
{
$spc_config = new SPCConfigUtil(['no_php' => true, 'libs_only_deps' => true]);
$config = $spc_config->getPackageDepsConfig('postgresql', array_keys($installer->getResolvedPackages()), include_suggests: $builder->getOption('with-suggests', false));
$config = $spc_config->getPackageDepsConfig('postgresql', array_keys($installer->getResolvedPackages()));

$env_vars = [
'CFLAGS' => $config['cflags'] . ' -std=c17',
Expand Down
5 changes: 1 addition & 4 deletions src/Package/Target/php/frankenphp.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ public function buildFrankenphpForUnix(TargetPackage $package, PackageInstaller
$staticFlags = '';
}

$resolved = array_keys($installer->getResolvedPackages());
// remove self from deps
$resolved = array_filter($resolved, fn ($pkg_name) => $pkg_name !== $package->getName());
$config = new SPCConfigUtil()->config($resolved);
$config = new SPCConfigUtil()->configForResolvedBuild([$package->getName()], $installer);
$cflags = "{$package->getLibExtraCFlags()} {$config['cflags']} " . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') . " -DFRANKENPHP_VERSION={$frankenphp_version}";
$libs = $config['libs'];

Expand Down
4 changes: 2 additions & 2 deletions src/Package/Target/php/unix.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ public function smokeTestEmbedForUnix(PackageInstaller $installer, ToolchainInte
copy(ROOT_DIR . '/src/globals/common-tests/embed.c', $sample_file_path . '/embed.c');
copy(ROOT_DIR . '/src/globals/common-tests/embed.php', $sample_file_path . '/embed.php');

$config = new SPCConfigUtil()->config($installer->getAvailableResolvedPackageNames());
$config = new SPCConfigUtil()->configForResolvedBuild(['php'], $installer);
$lens = "{$config['cflags']} {$config['ldflags']} {$config['libs']}";
if ($toolchain->isStatic()) {
$lens .= ' -static';
Expand Down Expand Up @@ -785,7 +785,7 @@ private function processLibphpSoFile(string $libphpSo, PackageInstaller $install
*/
private function makeVars(PackageInstaller $installer): array
{
$config = new SPCConfigUtil(['libs_only_deps' => true])->config($installer->getAvailableResolvedPackageNames());
$config = new SPCConfigUtil(['libs_only_deps' => true])->configForResolvedBuild(['php'], $installer);
$static = ApplicationContext::get(ToolchainInterface::class)->isStatic() ? '-all-static' : '';
$pie = SystemTarget::getTargetOS() === 'Linux' ? '-pie' : '';

Expand Down
2 changes: 1 addition & 1 deletion src/Package/Target/php/windows.php
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ public function smokeTestEmbedForWindows(PackageInstaller $installer, TargetPack

// Get build configuration using spc-config
$util = new \StaticPHP\Util\SPCConfigUtil();
$config = $util->config(array_map(fn ($x) => $x->getName(), $installer->getResolvedPackages()));
$config = $util->configForResolvedBuild(['php'], $installer);

// Build the embed test executable using cl.exe
// Note: MSVCToolchain already initialized the VC environment, no need for vcvarsall
Expand Down
4 changes: 2 additions & 2 deletions src/StaticPHP/Package/LibraryPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ public function packPrebuilt(): void
*/
public function getStaticLibFiles(): string
{
$config = new SPCConfigUtil(['libs_only_deps' => true, 'absolute_libs' => true]);
$res = $config->config([$this->getName()]);
$config = new SPCConfigUtil(['no_php' => true, 'libs_only_deps' => true, 'absolute_libs' => true]);
$res = $config->configForResolvedBuild([$this->getName()], $this->getInstaller());
return $res['libs'];
}

Expand Down
4 changes: 2 additions & 2 deletions src/StaticPHP/Package/PhpExtensionPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,13 @@ public function getSharedExtensionEnv(): array
$compiler_extra = trim($compiler_extra . ' -lcompiler_rt');
GlobalEnvManager::putenv("SPC_COMPILER_EXTRA={$compiler_extra}");
}
$config = (new SPCConfigUtil())->getExtensionConfig($this);
$config = (new SPCConfigUtil())->configForResolvedBuild([$this->getName()], $this->getInstaller());
[$staticLibs, $sharedLibs] = $this->splitLibsIntoStaticAndShared($config['libs']);
$preStatic = PHP_OS_FAMILY === 'Darwin' ? '' : '-Wl,--start-group ';
$postStatic = PHP_OS_FAMILY === 'Darwin' ? '' : ' -Wl,--end-group ';
return [
'CFLAGS' => $config['cflags'],
'CXXFLAGS' => $config['cflags'],
'CXXFLAGS' => $config['cxxflags'],
'LDFLAGS' => $config['ldflags'],
'LIBS' => clean_spaces("{$preStatic} {$staticLibs} {$postStatic} {$sharedLibs}"),
'LD_LIBRARY_PATH' => BUILD_LIB_PATH,
Expand Down
46 changes: 46 additions & 0 deletions src/StaticPHP/Util/DependencyResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,52 @@ public static function getSubDependencies(string $package_name, array $resolved_
return $sorted;
}

/**
* Get the link closure for one or more roots within an already-resolved package set.
*
* Both depends and suggests may be traversed, but only packages present in the
* resolved set are returned. Dependency overrides add build-specific graph edges,
* such as PHP's resolved static extensions and virtual SAPI targets.
*
* @param array<Package|string> $packages
* @param string[] $resolved_packages
* @param array<string, string[]> $dependency_overrides
* @return string[] Packages in dependency order, including the roots
*/
public static function getResolvedPackageClosure(
array $packages,
array $resolved_packages,
array $dependency_overrides = [],
bool $include_suggests = true,
): array {
$resolved_set = array_flip($resolved_packages);
$dep_map = [];
foreach ($resolved_packages as $package) {
$dep_map[$package] = [
'depends' => array_merge(
PackageConfig::get($package, 'depends', []),
$dependency_overrides[$package] ?? [],
),
'suggests' => PackageConfig::get($package, 'suggests', []),
];
}

$visited = [];
$sorted = [];
foreach ($packages as $package) {
$name = is_string($package) ? $package : $package->getName();
if (!PackageConfig::isPackageExists($name)) {
throw new WrongUsageException("Package '{$name}' does not exist in config, please check your package name !");
}
if (!isset($resolved_set[$name])) {
throw new WrongUsageException("Package '{$name}' is not part of the resolved package set.");
}
self::visitSubDeps($name, $dep_map, $resolved_set, $include_suggests, $visited, $sorted);
}

return $sorted;
}

/**
* Build a reverse dependency map for the resolved packages.
* For each package that is depended upon, list which packages depend on it.
Expand Down
Loading