Skip to content

Commit 7837563

Browse files
V3 feat/re2c (#992)
Co-authored-by: Copilot <[email protected]>
2 parents 127c935 + f68adc3 commit 7837563

39 files changed

+953
-198
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"ext-mbstring": "*",
1414
"ext-zlib": "*",
1515
"laravel/prompts": "~0.1",
16+
"nette/php-generator": "^4.2",
1617
"php-di/php-di": "^7.1",
1718
"symfony/console": "^5.4 || ^6 || ^7",
1819
"symfony/process": "^7.2",

composer.lock

Lines changed: 162 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/pkg.lib.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,9 @@
711711
"ncurses": {
712712
"type": "library",
713713
"artifact": "ncurses",
714+
"static-libs@unix": [
715+
"libncurses.a"
716+
],
714717
"license": {
715718
"type": "file",
716719
"path": "COPYING"

src/Package/Command/SwitchPhpVersionCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use StaticPHP\Artifact\DownloaderOptions;
1010
use StaticPHP\Command\BaseCommand;
1111
use StaticPHP\DI\ApplicationContext;
12-
use StaticPHP\Package\PackageLoader;
12+
use StaticPHP\Registry\PackageLoader;
1313
use StaticPHP\Util\FileSystem;
1414
use StaticPHP\Util\InteractiveTerm;
1515
use Symfony\Component\Console\Attribute\AsCommand;

src/Package/Extension/readline.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44

55
namespace Package\Extension;
66

7+
use Package\Target\php;
78
use StaticPHP\Attribute\Package\AfterStage;
89
use StaticPHP\Attribute\Package\BeforeStage;
910
use StaticPHP\Attribute\Package\Extension;
11+
use StaticPHP\Attribute\PatchDescription;
1012
use StaticPHP\Package\PackageInstaller;
1113
use StaticPHP\Toolchain\Interface\ToolchainInterface;
1214
use StaticPHP\Util\SourcePatcher;
1315

1416
#[Extension('readline')]
1517
class readline
1618
{
17-
#[BeforeStage('php', 'unix-make-cli')]
19+
#[BeforeStage('php', [php::class, 'makeCliForUnix'], 'ext-readline')]
20+
#[PatchDescription('Fix readline static build with musl')]
1821
public function beforeMakeLinuxCli(PackageInstaller $installer, ToolchainInterface $toolchain): void
1922
{
2023
if ($toolchain->isStatic()) {
@@ -23,7 +26,7 @@ public function beforeMakeLinuxCli(PackageInstaller $installer, ToolchainInterfa
2326
}
2427
}
2528

26-
#[AfterStage('php', 'unix-make-cli')]
29+
#[AfterStage('php', [php::class, 'makeCliForUnix'], 'ext-readline')]
2730
public function afterMakeLinuxCli(PackageInstaller $installer, ToolchainInterface $toolchain): void
2831
{
2932
if ($toolchain->isStatic()) {

src/Package/Library/imap.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Package\Library;
66

7+
use Package\Target\php;
78
use StaticPHP\Attribute\Package\AfterStage;
89
use StaticPHP\Attribute\Package\Library;
910
use StaticPHP\Attribute\PatchDescription;
@@ -13,7 +14,7 @@
1314
#[Library('imap')]
1415
class imap
1516
{
16-
#[AfterStage('php', 'patch-embed-scripts')]
17+
#[AfterStage('php', [php::class, 'patchEmbedScripts'], 'imap')]
1718
#[PatchDescription('Fix missing -lcrypt in php-config libs on glibc systems')]
1819
public function afterPatchScripts(): void
1920
{

src/Package/Library/libedit.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Package\Library;
6+
7+
use StaticPHP\Attribute\Package\BeforeStage;
8+
use StaticPHP\Attribute\Package\BuildFor;
9+
use StaticPHP\Attribute\Package\Library;
10+
use StaticPHP\Package\LibraryPackage;
11+
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
12+
use StaticPHP\Util\FileSystem;
13+
14+
#[Library('libedit')]
15+
class libedit extends LibraryPackage
16+
{
17+
#[BeforeStage(stage: 'build')]
18+
public function patchBeforeBuild(): void
19+
{
20+
FileSystem::replaceFileRegex(
21+
"{$this->getSourceDir()}/src/sys.h",
22+
'|//#define\s+strl|',
23+
'#define strl'
24+
);
25+
}
26+
27+
#[BuildFor('Darwin')]
28+
#[BuildFor('Linux')]
29+
public function build(): void
30+
{
31+
UnixAutoconfExecutor::create($this)
32+
->appendEnv(['CFLAGS' => '-D__STDC_ISO_10646__=201103L'])
33+
->configure()
34+
->make();
35+
$this->patchPkgconfPrefix(['libedit.pc']);
36+
}
37+
}

src/Package/Library/ncurses.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Package\Library;
6+
7+
use StaticPHP\Attribute\Package\BuildFor;
8+
use StaticPHP\Attribute\Package\Library;
9+
use StaticPHP\Package\LibraryPackage;
10+
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
11+
use StaticPHP\Toolchain\Interface\ToolchainInterface;
12+
use StaticPHP\Util\DirDiff;
13+
use StaticPHP\Util\FileSystem;
14+
15+
#[Library('ncurses')]
16+
class ncurses
17+
{
18+
#[BuildFor('Darwin')]
19+
#[BuildFor('Linux')]
20+
public function build(LibraryPackage $package, ToolchainInterface $toolchain): void
21+
{
22+
$dirdiff = new DirDiff(BUILD_BIN_PATH);
23+
24+
UnixAutoconfExecutor::create($package)
25+
->appendEnv([
26+
'LDFLAGS' => $toolchain->isStatic() ? '-static' : '',
27+
])
28+
->configure(
29+
'--enable-overwrite',
30+
'--with-curses-h',
31+
'--enable-pc-files',
32+
'--enable-echo',
33+
'--disable-widec',
34+
'--with-normal',
35+
'--with-ticlib',
36+
'--without-tests',
37+
'--without-dlsym',
38+
'--without-debug',
39+
'--enable-symlinks',
40+
"--bindir={$package->getBinDir()}",
41+
"--includedir={$package->getIncludeDir()}",
42+
"--libdir={$package->getLibDir()}",
43+
"--prefix={$package->getBuildRootPath()}",
44+
)
45+
->make();
46+
$new_files = $dirdiff->getIncrementFiles(true);
47+
foreach ($new_files as $file) {
48+
@unlink(BUILD_BIN_PATH . '/' . $file);
49+
}
50+
51+
shell()->cd(BUILD_ROOT_PATH)->exec('rm -rf share/terminfo');
52+
shell()->cd(BUILD_ROOT_PATH)->exec('rm -rf lib/terminfo');
53+
54+
$pkgconf_list = ['form.pc', 'menu.pc', 'ncurses++.pc', 'ncurses.pc', 'panel.pc', 'tic.pc'];
55+
$package->patchPkgconfPrefix($pkgconf_list);
56+
57+
foreach ($pkgconf_list as $pkgconf) {
58+
FileSystem::replaceFileStr("{$package->getLibDir()}/pkgconfig/{$pkgconf}", "-L{$package->getLibDir()}", '-L${libdir}');
59+
}
60+
}
61+
}

src/Package/Library/postgresql.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Package\Library;
66

7+
use Package\Target\php;
78
use StaticPHP\Attribute\Package\BeforeStage;
89
use StaticPHP\Attribute\Package\Library;
910
use StaticPHP\Attribute\PatchDescription;
@@ -12,7 +13,7 @@
1213
#[Library('postgresql')]
1314
class postgresql
1415
{
15-
#[BeforeStage('php', 'unix-configure', 'postgresql')]
16+
#[BeforeStage('php', [php::class, 'configureForUnix'], 'postgresql')]
1617
#[PatchDescription('Patch to avoid explicit_bzero detection issues on some systems')]
1718
public function patchBeforePHPConfigure(TargetPackage $package): void
1819
{

src/Package/Target/micro.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Package\Target;
6+
7+
use StaticPHP\Attribute\Package\BeforeStage;
8+
use StaticPHP\Attribute\Package\Target;
9+
use StaticPHP\Attribute\PatchDescription;
10+
use StaticPHP\Package\TargetPackage;
11+
use StaticPHP\Util\FileSystem;
12+
13+
#[Target('php-micro')]
14+
class micro
15+
{
16+
#[BeforeStage('php', [php::class, 'makeEmbedForUnix'], 'php-micro')]
17+
#[PatchDescription('Patch Makefile to build only libphp.la for embedding')]
18+
public function patchBeforeEmbed(TargetPackage $package): void
19+
{
20+
FileSystem::replaceFileStr("{$package->getSourceDir()}/Makefile", 'OVERALL_TARGET =', 'OVERALL_TARGET = libphp.la');
21+
}
22+
}

0 commit comments

Comments
 (0)