Skip to content

Commit f8d24e2

Browse files
committed
Refactor package resolution to filter only available build artifacts
1 parent 991da26 commit f8d24e2

File tree

7 files changed

+1410
-1385
lines changed

7 files changed

+1410
-1385
lines changed

src/Package/Extension/curl.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
<?php
2-
3-
declare(strict_types=1);
4-
5-
namespace Package\Extension;
6-
7-
use Package\Target\php;
8-
use StaticPHP\Attribute\Package\BeforeStage;
9-
use StaticPHP\Attribute\Package\Extension;
10-
use StaticPHP\Attribute\PatchDescription;
11-
12-
#[Extension('curl')]
13-
class curl
14-
{
15-
#[BeforeStage('php', [php::class, 'makeForWindows'], 'ext-curl')]
16-
#[PatchDescription('Inject secur32.lib into SPC_EXTRA_LIBS for Schannel SSL support')]
17-
public function addSecur32LibForWindows(): void
18-
{
19-
// curl on Windows uses Schannel (USE_WINDOWS_SSPI=ON, CURL_USE_SCHANNEL=ON),
20-
// which requires secur32.lib for SSL/TLS functions (SslEncryptPackage, etc.).
21-
$extra_libs = getenv('SPC_EXTRA_LIBS') ?: '';
22-
if (!str_contains($extra_libs, 'secur32.lib')) {
23-
putenv('SPC_EXTRA_LIBS=' . trim($extra_libs . ' secur32.lib'));
24-
}
25-
}
26-
}
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Package\Extension;
6+
7+
use Package\Target\php;
8+
use StaticPHP\Attribute\Package\BeforeStage;
9+
use StaticPHP\Attribute\Package\Extension;
10+
use StaticPHP\Attribute\PatchDescription;
11+
12+
#[Extension('curl')]
13+
class curl
14+
{
15+
#[BeforeStage('php', [php::class, 'makeForWindows'], 'ext-curl')]
16+
#[PatchDescription('Inject secur32.lib into SPC_EXTRA_LIBS for Schannel SSL support')]
17+
public function addSecur32LibForWindows(): void
18+
{
19+
// curl on Windows uses Schannel (USE_WINDOWS_SSPI=ON, CURL_USE_SCHANNEL=ON),
20+
// which requires secur32.lib for SSL/TLS functions (SslEncryptPackage, etc.).
21+
$extra_libs = getenv('SPC_EXTRA_LIBS') ?: '';
22+
if (!str_contains($extra_libs, 'secur32.lib')) {
23+
putenv('SPC_EXTRA_LIBS=' . trim($extra_libs . ' secur32.lib'));
24+
}
25+
}
26+
}

src/Package/Library/nghttp2.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public function buildWin(LibraryPackage $lib): void
2929
->build();
3030

3131
FileSystem::replaceFileStr($lib->getIncludeDir() . '\nghttp2\nghttp2.h', '#ifdef NGHTTP2_STATICLIB', '#if 1');
32-
3332
}
3433

3534
#[BuildFor('Linux')]

src/Package/Target/php/unix.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ public function smokeTestEmbedForUnix(PackageInstaller $installer, ToolchainInte
577577
copy(ROOT_DIR . '/src/globals/common-tests/embed.c', $sample_file_path . '/embed.c');
578578
copy(ROOT_DIR . '/src/globals/common-tests/embed.php', $sample_file_path . '/embed.php');
579579

580-
$config = new SPCConfigUtil()->config(array_map(fn ($x) => $x->getName(), $installer->getResolvedPackages()));
580+
$config = new SPCConfigUtil()->config($installer->getAvailableResolvedPackageNames());
581581
$lens = "{$config['cflags']} {$config['ldflags']} {$config['libs']}";
582582
if ($toolchain->isStatic()) {
583583
$lens .= ' -static';
@@ -735,7 +735,7 @@ private function processLibphpSoFile(string $libphpSo, PackageInstaller $install
735735
*/
736736
private function makeVars(PackageInstaller $installer): array
737737
{
738-
$config = new SPCConfigUtil(['libs_only_deps' => true])->config(array_map(fn ($x) => $x->getName(), $installer->getResolvedPackages()));
738+
$config = new SPCConfigUtil(['libs_only_deps' => true])->config($installer->getAvailableResolvedPackageNames());
739739
$static = ApplicationContext::get(ToolchainInterface::class)->isStatic() ? '-all-static' : '';
740740
$pie = SystemTarget::getTargetOS() === 'Linux' ? '-pie' : '';
741741

src/Package/Target/php/windows.php

Lines changed: 783 additions & 783 deletions
Large diffs are not rendered by default.

src/StaticPHP/Package/PackageInstaller.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,32 @@ public function isPackageResolved(string $package_name): bool
301301
return isset($this->packages[$package_name]);
302302
}
303303

304+
/**
305+
* Get resolved package names filtered to only packages whose build artifacts are available.
306+
* This excludes library packages that haven't been built/installed yet, which naturally
307+
* prevents SPCConfigUtil from checking static-lib files of libraries that come after
308+
* the current target in the build order (e.g. 'watcher' for frankenphp isn't built
309+
* when 'php' is being compiled).
310+
*
311+
* @return string[] Available resolved package names
312+
*/
313+
public function getAvailableResolvedPackageNames(): array
314+
{
315+
return array_values(array_filter(
316+
array_keys($this->packages),
317+
function (string $name): bool {
318+
$pkg = $this->packages[$name] ?? null;
319+
// Exclude library packages whose build artifacts don't exist yet.
320+
// Extensions and targets are not filtered — extensions are compiled into PHP
321+
// and don't have standalone build artifacts.
322+
if ($pkg instanceof LibraryPackage && $pkg->getType() === 'library' && !$pkg->isInstalled()) {
323+
return false;
324+
}
325+
return true;
326+
}
327+
));
328+
}
329+
304330
public function isPackageInstalled(Package|string $package_name): bool
305331
{
306332
if (empty($this->packages)) {
Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,64 @@
1-
<?php
2-
3-
declare(strict_types=1);
4-
5-
namespace StaticPHP\Runtime\Shell;
6-
7-
use StaticPHP\Exception\SPCInternalException;
8-
use ZM\Logger\ConsoleColor;
9-
10-
class WindowsCmd extends Shell
11-
{
12-
public function __construct(?bool $debug = null)
13-
{
14-
if (PHP_OS_FAMILY !== 'Windows') {
15-
throw new SPCInternalException('Only windows can use WindowsCmd');
16-
}
17-
parent::__construct($debug);
18-
}
19-
20-
public function exec(string $cmd): static
21-
{
22-
/* @phpstan-ignore-next-line */
23-
logger()->info(ConsoleColor::yellow('[EXEC] ') . ConsoleColor::green($cmd));
24-
25-
$original_command = $cmd;
26-
$this->logCommandInfo($original_command);
27-
$this->last_cmd = $cmd = $this->getExecString($cmd);
28-
// echo $cmd . PHP_EOL;
29-
30-
$this->passthru($cmd, $this->console_putput, $original_command, cwd: $this->cd);
31-
return $this;
32-
}
33-
34-
public function execWithWrapper(string $wrapper, string $args): WindowsCmd
35-
{
36-
return $this->exec($wrapper . ' "' . str_replace('"', '^"', $args) . '"');
37-
}
38-
39-
public function execWithResult(string $cmd, bool $with_log = true): array
40-
{
41-
if ($with_log) {
42-
/* @phpstan-ignore-next-line */
43-
logger()->info(ConsoleColor::blue('[EXEC] ') . ConsoleColor::green($cmd));
44-
} else {
45-
logger()->debug('Running command with result: ' . $cmd);
46-
}
47-
$original_command = $cmd;
48-
$this->logCommandInfo($original_command);
49-
$cmd = $this->getExecString($cmd);
50-
$result = $this->passthru($cmd, $this->console_putput, $original_command, capture_output: true, throw_on_error: false, cwd: $this->cd, env: $this->env);
51-
$out = explode("\n", $result['output']);
52-
return [$result['code'], $out];
53-
}
54-
55-
public function getLastCommand(): string
56-
{
57-
return $this->last_cmd;
58-
}
59-
60-
private function getExecString(string $cmd): string
61-
{
62-
return $cmd;
63-
}
64-
}
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace StaticPHP\Runtime\Shell;
6+
7+
use StaticPHP\Exception\SPCInternalException;
8+
use ZM\Logger\ConsoleColor;
9+
10+
class WindowsCmd extends Shell
11+
{
12+
public function __construct(?bool $debug = null)
13+
{
14+
if (PHP_OS_FAMILY !== 'Windows') {
15+
throw new SPCInternalException('Only windows can use WindowsCmd');
16+
}
17+
parent::__construct($debug);
18+
}
19+
20+
public function exec(string $cmd): static
21+
{
22+
/* @phpstan-ignore-next-line */
23+
logger()->info(ConsoleColor::yellow('[EXEC] ') . ConsoleColor::green($cmd));
24+
25+
$original_command = $cmd;
26+
$this->logCommandInfo($original_command);
27+
$this->last_cmd = $cmd = $this->getExecString($cmd);
28+
// echo $cmd . PHP_EOL;
29+
30+
$this->passthru($cmd, $this->console_putput, $original_command, cwd: $this->cd);
31+
return $this;
32+
}
33+
34+
public function execWithWrapper(string $wrapper, string $args): WindowsCmd
35+
{
36+
return $this->exec($wrapper . ' "' . str_replace('"', '^"', $args) . '"');
37+
}
38+
39+
public function execWithResult(string $cmd, bool $with_log = true): array
40+
{
41+
if ($with_log) {
42+
/* @phpstan-ignore-next-line */
43+
logger()->info(ConsoleColor::blue('[EXEC] ') . ConsoleColor::green($cmd));
44+
} else {
45+
logger()->debug('Running command with result: ' . $cmd);
46+
}
47+
$original_command = $cmd;
48+
$this->logCommandInfo($original_command);
49+
$cmd = $this->getExecString($cmd);
50+
$result = $this->passthru($cmd, $this->console_putput, $original_command, capture_output: true, throw_on_error: false, cwd: $this->cd, env: $this->env);
51+
$out = explode("\n", $result['output']);
52+
return [$result['code'], $out];
53+
}
54+
55+
public function getLastCommand(): string
56+
{
57+
return $this->last_cmd;
58+
}
59+
60+
private function getExecString(string $cmd): string
61+
{
62+
return $cmd;
63+
}
64+
}

0 commit comments

Comments
 (0)