Compare commits

...

4 Commits

Author SHA1 Message Date
crazywhalecc
9e2a5ce188 Add target htop 2026-03-18 15:01:06 +08:00
crazywhalecc
0b0ecd17c3 Allow curl building static executable 2026-03-18 15:00:58 +08:00
crazywhalecc
c81146bf18 Add ncursesw 2026-03-18 15:00:44 +08:00
crazywhalecc
c1f2fd49a6 Add ext-imap 2026-03-18 13:30:29 +08:00
11 changed files with 206 additions and 65 deletions

View File

@@ -0,0 +1,9 @@
ncurses:
binary: hosted
metadata:
license-files:
- COPYING
source:
type: filelist
url: 'https://ftp.gnu.org/pub/gnu/ncurses/'
regex: '/href="(?<file>ncurses-(?<version>[^"]+)\.tar\.gz)"/'

View File

@@ -0,0 +1,15 @@
ext-imap:
type: php-extension
artifact:
source:
type: pecl
name: imap
metadata:
license-files: [LICENSE]
license: PHP-3.01
depends:
- imap
suggests:
- ext-openssl
php-extension:
arg-type: custom

View File

@@ -1,12 +1,10 @@
ncurses:
type: library
artifact:
source:
type: filelist
url: 'https://ftp.gnu.org/pub/gnu/ncurses/'
regex: '/href="(?<file>ncurses-(?<version>[^"]+)\.tar\.gz)"/'
binary: hosted
metadata:
license-files: [COPYING]
artifact: ncurses
static-libs@unix:
- libncurses.a
ncursesw:
type: library
artifact: ncurses
static-libs@unix:
- libncursesw.a

View File

@@ -1,5 +1,5 @@
curl:
type: library
type: target
artifact:
source:
type: ghrel
@@ -29,5 +29,7 @@ curl:
- SystemConfiguration
headers:
- curl
static-bins@unix:
- curl
static-libs@unix:
- libcurl.a

View File

@@ -0,0 +1,10 @@
htop:
type: target
artifact:
source:
type: ghrel
repo: htop-dev/htop
match: htop.+\.tar\.xz
prefer-stable: true
depends:
- ncursesw

View File

@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace Package\Extension;
use Package\Target\php;
use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\CustomPhpConfigureArg;
use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Attribute\Package\Validate;
use StaticPHP\Exception\WrongUsageException;
use StaticPHP\Package\PackageBuilder;
use StaticPHP\Package\PackageInstaller;
use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Util\FileSystem;
#[Extension('imap')]
class imap extends PhpExtensionPackage
{
#[Validate]
public function validate(PackageBuilder $builder): void
{
if ($builder->getOption('enable-zts')) {
throw new WrongUsageException('ext-imap is not thread safe, do not build it with ZTS builds');
}
}
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-imap')]
public function patchBeforeBuildconf(PackageInstaller $installer): void
{
if ($installer->getLibraryPackage('openssl')) {
// sometimes imap with openssl does not contain zlib (required by openssl)
// we need to add it manually
FileSystem::replaceFileStr("{$this->getSourceDir()}/config.m4", 'TST_LIBS="$DLIBS $IMAP_SHARED_LIBADD"', 'TST_LIBS="$DLIBS $IMAP_SHARED_LIBADD -lz"');
}
// c-client is built with PASSWDTYPE=nul so libcrypt is not referenced.
FileSystem::replaceFileStr(
"{$this->getSourceDir()}/config.m4",
" PHP_CHECK_LIBRARY(crypt, crypt,\n [\n PHP_ADD_LIBRARY(crypt,, IMAP_SHARED_LIBADD)\n AC_DEFINE(HAVE_LIBCRYPT,1,[ ])\n ])",
' dnl Skipped: crypt check not needed (c-client built with PASSWDTYPE=nul)'
);
}
#[CustomPhpConfigureArg('Darwin')]
#[CustomPhpConfigureArg('Linux')]
public function getUnixConfigureArg(PackageInstaller $installer, PackageBuilder $builder): string
{
$arg = "--with-imap={$builder->getBuildRootPath()}";
if (($ssl = $installer->getLibraryPackage('openssl')) !== null) {
$arg .= " --with-imap-ssl={$ssl->getBuildRootPath()}";
}
return $arg;
}
}

View File

@@ -4,8 +4,6 @@ declare(strict_types=1);
namespace Package\Library;
use Package\Target\php;
use StaticPHP\Attribute\Package\AfterStage;
use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Attribute\Package\PatchBeforeBuild;
@@ -19,15 +17,6 @@ use StaticPHP\Util\SourcePatcher;
#[Library('imap')]
class imap
{
#[AfterStage('php', [php::class, 'patchUnixEmbedScripts'], 'imap')]
#[PatchDescription('Fix missing -lcrypt in php-config libs on glibc systems')]
public function afterPatchScripts(): void
{
if (SystemTarget::getLibc() === 'glibc') {
FileSystem::replaceFileRegex(BUILD_BIN_PATH . '/php-config', '/^libs="(.*)"$/m', 'libs="$1 -lcrypt"');
}
}
#[PatchBeforeBuild]
#[PatchDescription('Patch imap build system for Linux and macOS compatibility')]
public function patchBeforeBuild(LibraryPackage $lib): void
@@ -66,14 +55,24 @@ class imap
}
$libcVer = SystemTarget::getLibcVersion();
$extraLibs = $libcVer && version_compare($libcVer, '2.17', '<=') ? 'EXTRALDFLAGS="-ldl -lrt -lpthread"' : '';
shell()->cd($lib->getSourceDir())
->exec('make clean')
->exec('touch ip6')
->exec('chmod +x tools/an')
->exec('chmod +x tools/ua')
->exec('chmod +x src/osdep/unix/drivers')
->exec('chmod +x src/osdep/unix/mkauths')
->exec("yes | make slx {$ssl_options} EXTRACFLAGS='-fPIC -Wno-implicit-function-declaration -Wno-incompatible-function-pointer-types' {$extraLibs}");
try {
shell()->cd($lib->getSourceDir())
->exec('make clean')
->exec('touch ip6')
->exec('chmod +x tools/an')
->exec('chmod +x tools/ua')
->exec('chmod +x src/osdep/unix/drivers')
->exec('chmod +x src/osdep/unix/mkauths')
// PASSWDTYPE=nul avoids any crypt() symbol reference in c-client.a;
// zig-cc 0.15+ uses paths_first strategy and cannot find libcrypt outside of buildroot.
->exec("yes | make slx {$ssl_options} PASSWDTYPE=nul EXTRACFLAGS='-fPIC -Wno-implicit-function-declaration -Wno-incompatible-function-pointer-types' {$extraLibs}");
} catch (\Throwable $e) {
// slx target also builds bundled tools (mtest, etc.) which may fail to link -lcrypt dynamically
// (e.g. with zig-cc). We only need c-client.a, so tolerate the failure if it was built.
if (!file_exists("{$lib->getSourceDir()}/c-client/c-client.a")) {
throw $e;
}
}
try {
shell()
->exec("cp -rf {$lib->getSourceDir()}/c-client/c-client.a {$lib->getLibDir()}/libc-client.a")
@@ -94,16 +93,24 @@ class imap
$ssl_options = 'SSLTYPE=none';
}
$out = shell()->execWithResult('echo "-include $(xcrun --show-sdk-path)/usr/include/poll.h -include $(xcrun --show-sdk-path)/usr/include/time.h -include $(xcrun --show-sdk-path)/usr/include/utime.h"')[1][0];
shell()->cd($lib->getSourceDir())
->exec('make clean')
->exec('touch ip6')
->exec('chmod +x tools/an')
->exec('chmod +x tools/ua')
->exec('chmod +x src/osdep/unix/drivers')
->exec('chmod +x src/osdep/unix/mkauths')
->exec(
"echo y | make osx {$ssl_options} EXTRACFLAGS='-Wno-implicit-function-declaration -Wno-incompatible-function-pointer-types {$out}'"
);
try {
shell()->cd($lib->getSourceDir())
->exec('make clean')
->exec('touch ip6')
->exec('chmod +x tools/an')
->exec('chmod +x tools/ua')
->exec('chmod +x src/osdep/unix/drivers')
->exec('chmod +x src/osdep/unix/mkauths')
->exec(
"echo y | make osx {$ssl_options} EXTRACFLAGS='-Wno-implicit-function-declaration -Wno-incompatible-function-pointer-types {$out}'"
);
} catch (\Throwable $e) {
// osx target also builds bundled tools (mtest, etc.) which may fail to link.
// We only need c-client.a, so tolerate the failure if it was built.
if (!file_exists("{$lib->getSourceDir()}/c-client/c-client.a")) {
throw $e;
}
}
try {
shell()
->exec("cp -rf {$lib->getSourceDir()}/c-client/c-client.a {$lib->getLibDir()}/libc-client.a")

View File

@@ -13,6 +13,7 @@ use StaticPHP\Util\DirDiff;
use StaticPHP\Util\FileSystem;
#[Library('ncurses')]
#[Library('ncursesw')]
class ncurses
{
#[BuildFor('Darwin')]
@@ -21,37 +22,48 @@ class ncurses
{
$dirdiff = new DirDiff(BUILD_BIN_PATH);
UnixAutoconfExecutor::create($package)
$ac = UnixAutoconfExecutor::create($package)
->appendEnv([
'LDFLAGS' => $toolchain->isStatic() ? '-static' : '',
])
->configure(
'--enable-overwrite',
'--with-curses-h',
'--enable-pc-files',
'--enable-echo',
'--disable-widec',
'--with-normal',
'--with-ticlib',
'--without-tests',
'--without-dlsym',
'--without-debug',
'--enable-symlinks',
"--bindir={$package->getBinDir()}",
"--includedir={$package->getIncludeDir()}",
"--libdir={$package->getLibDir()}",
"--prefix={$package->getBuildRootPath()}",
)
]);
$wide = $package->getName() === 'ncurses' ? ['--disable-widec'] : [];
// Include standard system terminfo paths as fallback so binaries linking this ncurses
// (e.g. htop) can find terminfo on any target system without needing TERMINFO_DIRS set.
$terminfo_dirs = implode(':', [
"{$package->getBuildRootPath()}/share/terminfo",
'/etc/terminfo',
'/lib/terminfo',
'/usr/share/terminfo',
]);
$ac->configure(
'--enable-overwrite',
'--with-curses-h',
'--enable-pc-files',
'--enable-echo',
'--with-normal',
'--with-ticlib',
'--without-tests',
'--without-dlsym',
'--without-debug',
'--enable-symlinks',
"--with-terminfo-dirs={$terminfo_dirs}",
"--bindir={$package->getBinDir()}",
"--includedir={$package->getIncludeDir()}",
"--libdir={$package->getLibDir()}",
"--prefix={$package->getBuildRootPath()}",
...$wide,
)
->make();
$new_files = $dirdiff->getIncrementFiles(true);
foreach ($new_files as $file) {
@unlink(BUILD_BIN_PATH . '/' . $file);
}
shell()->cd(BUILD_ROOT_PATH)->exec('rm -rf share/terminfo');
shell()->cd(BUILD_ROOT_PATH)->exec('rm -rf lib/terminfo');
// shell()->cd(BUILD_ROOT_PATH)->exec('rm -rf share/terminfo');
// shell()->cd(BUILD_ROOT_PATH)->exec('rm -rf lib/terminfo');
$pkgconf_list = ['form.pc', 'menu.pc', 'ncurses++.pc', 'ncurses.pc', 'panel.pc', 'tic.pc'];
$suffix = $package->getName() === 'ncursesw' ? 'w' : '';
$pkgconf_list = ["form{$suffix}.pc", "menu{$suffix}.pc", "ncurses++{$suffix}.pc", "ncurses{$suffix}.pc", "panel{$suffix}.pc", "tic{$suffix}.pc"];
$package->patchPkgconfPrefix($pkgconf_list);
foreach ($pkgconf_list as $pkgconf) {

View File

@@ -2,18 +2,18 @@
declare(strict_types=1);
namespace Package\Library;
namespace Package\Target;
use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Attribute\Package\PatchBeforeBuild;
use StaticPHP\Attribute\Package\Target;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Util\FileSystem;
#[Library('curl')]
#[Target('curl')]
class curl
{
#[PatchBeforeBuild]
@@ -48,7 +48,7 @@ class curl
->optionalPackage('idn2', ...cmake_boolean_args('CURL_USE_IDN2'))
->optionalPackage('libcares', '-DENABLE_ARES=ON')
->addConfigureArgs(
'-DBUILD_CURL_EXE=OFF',
'-DBUILD_CURL_EXE=ON',
'-DBUILD_LIBCURL_DOCS=OFF',
)
->build();
@@ -63,5 +63,7 @@ class curl
}
shell()->cd("{$lib->getLibDir()}/cmake/CURL/")
->exec("sed -ie 's|\"/lib/libcurl.a\"|\"{$lib->getLibDir()}/libcurl.a\"|g' CURLTargets-release.cmake");
$lib->setOutput('Static curl executable path', BUILD_BIN_PATH . '/curl');
}
}

View File

@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace Package\Target;
use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Target;
use StaticPHP\Package\TargetPackage;
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
use StaticPHP\Toolchain\Interface\ToolchainInterface;
#[Target('htop')]
class htop extends TargetPackage
{
#[BuildFor('Darwin')]
#[BuildFor('Linux')]
public function build(ToolchainInterface $toolchain): void
{
// htop's --enable-static adds -static to CFLAGS/LDFLAGS globally (not just for .a libraries),
// which causes zig-cc to fail on glibc targets. Only enable it for truly static (musl) builds.
UnixAutoconfExecutor::create($this)
->removeConfigureArgs('--disable-shared', '--enable-static')
->exec('./autogen.sh')
->addConfigureArgs($toolchain->isStatic() ? '--enable-static' : '--disable-static')
->configure()
->make(with_clean: false);
}
}

View File

@@ -389,7 +389,9 @@ class SPCConfigUtil
}
if (in_array('imap', $packages) && SystemTarget::getTargetOS() === 'Linux' && SystemTarget::getLibc() === 'glibc') {
$lib_names[] = '-lcrypt';
if (file_exists(BUILD_LIB_PATH . '/libcrypt.a')) {
$lib_names[] = '-lcrypt';
}
}
if (!$use_short_libs) {
$lib_names = array_map(fn ($l) => $this->getFullLibName($l), $lib_names);