Skip to content
Draft
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
52 changes: 52 additions & 0 deletions config/artifact.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
attr:
source:
type: url
url: 'https://download.savannah.nongnu.org/releases/attr/attr-2.5.2.tar.gz'
source-mirror:
type: url
url: 'https://mirror.souseiseki.middlendian.com/nongnu/attr/attr-2.5.2.tar.gz'
metadata:
license-files: ['doc/COPYING.LGPL']
license: LGPL-2.1-or-later

brotli:
source:
type: ghtagtar
repo: google/brotli
match: 'v1\.\d.*'
binary: hosted # 等价于v2的provide-pre-built: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think "binary" is the best description here. Binary could also refer to the binaries the artifact produces, not necessarily the prebuilt library.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-built library also belongs to a kind of binary I think. And hosted is just an alias like this:

"binary": {
            "linux-x86_64": {
                "type": "ghrel",
                "repo": "static-php/static-php-cli-hosted",
                "match": "pkg-config-aarch64-linux-musl-1.2.5.txz",
                "extract": {
                    "bin/pkg-config": "{pkg_root_path}/bin/pkg-config"
                }
            },
            "linux-aarch64": {
                "type": "ghrel",
                "repo": "static-php/static-php-cli-hosted",
                "match": "pkg-config-x86_64-linux-musl-1.2.5.txz",
                "extract": {
                    "bin/pkg-config": "{pkg_root_path}/bin/pkg-config"
                }
            },
            "macos-x86_64": {
                "type": "ghrel",
                "repo": "static-php/static-php-cli-hosted",
                "match": "pkg-config-x86_64-darwin.txz",
                "extract": {
                    "bin/pkg-config": "{pkg_root_path}/bin/pkg-config"
                }
            },
            "macos-aarch64": {
                "type": "ghrel",
                "repo": "static-php/static-php-cli-hosted",
                "match": "pkg-config-aarch64-darwin.txz",
                "extract": "{pkg_root_path}"
            }
        }

My expected goal is:

That means that binary is a pre-built product that only needs to be installed, including the pre-built itself. If the hosted alias is expanded, it might look similar to the binary in pkg-config above.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get it, but going by conventions it's confusing. pre-built is better for this.

Copy link
Owner Author

@crazywhalecc crazywhalecc Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's true that pre-built is more appropriate than hosted. My main point before was to show that the pre-built version is built by our hosting actions. I will try to change this name later.

Copy link
Collaborator

@henderkes henderkes Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think hosted is fine, it's "binary" that's confusing here.

"pre-built": {
    "linux-x86_64": {
        "type": "ghrel",
        "repo": "static-php/static-php-cli-hosted",
        "match": "pkg-config-aarch64-linux-musl-1.2.5.txz",
        "extract": {
            "bin/pkg-config": "{pkg_root_path}/bin/pkg-config"
        }
    },
    "linux-aarch64": {
        "type": "ghrel",
        "repo": "static-php/static-php-cli-hosted",
        "match": "pkg-config-x86_64-linux-musl-1.2.5.txz",
        "extract": {
            "bin/pkg-config": "{pkg_root_path}/bin/pkg-config"
        }
    },
    "macos-x86_64": {
        "type": "ghrel",
        "repo": "static-php/static-php-cli-hosted",
        "match": "pkg-config-x86_64-darwin.txz",
        "extract": {
            "bin/pkg-config": "{pkg_root_path}/bin/pkg-config"
        }
    },
    "macos-aarch64": {
        "type": "ghrel",
        "repo": "static-php/static-php-cli-hosted",
        "match": "pkg-config-aarch64-darwin.txz",
                "extract": "{pkg_root_path}"
    }
}

This would be fine.

Copy link
Owner Author

@crazywhalecc crazywhalecc Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My perspective is that since we've merged pre-built and pkg in v2 to artifact.binary in v3, or rather, the concept of v3 has been almost completely redefined, some of the original binary packages here are not part of the pre-built, or were not built by us. For example, nasm, go-xcaddy, etc.

I can't think of any other names besides binary that can represent "pre-built", "closed source software", and "other non-source artifacts" at the same time. Their functions and behaviors are the same.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or were not built by us. For example, nasm, go-xcaddy, etc.

But they are nevertheless pre-built.

Copy link
Owner Author

@crazywhalecc crazywhalecc Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But they are nevertheless pre-built.

I agree that closed-source software and third-party binaries are also "pre-built". But I prefer using the "what is it" instead of "how is it built" here.

metadata:
license-files: ['LICENSE']
license: MIT

bzip2:
source:
type: url
url: 'https://dl.static-php.dev/static-php-cli/deps/bzip2/bzip2-1.0.8.tar.gz'
source-mirror:
type: filelist
url: 'https://sourceware.org/pub/bzip2/'
regex: '/href="(?<file>bzip2-(?<version>[^"]+)\.tar\.gz)"/'
binary: hosted
metadata:
license-files: ['{registry_root}/src/globals/licenses/bzip2.txt']
license: bzip2-1.0.6

fastlz:
source:
type: git
url: 'https://github.com/ariya/FastLZ.git'
rev: master
metadata:
license-files: ['LICENSE.MIT']
license: MIT

zlib:
source:
type: ghrel
repo: madler/zlib
match: 'zlib.+\.tar\.gz'
binary: hosted
metadata:
license-files: ['{registry_root}/src/globals/licenses/zlib.txt']
license: Zlib-Custom
38 changes: 38 additions & 0 deletions config/pkg.lib.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
attr:
type: library
static-libs@unix:
- libattr.a
artifact: attr
brotli:
type: library
pkg-configs:
- libbrotlicommon
- libbrotlidec
- libbrotlienc
headers:
- brotli
artifact: brotli
bzip2:
type: library
static-libs@unix:
- libbz2.a
headers:
- bzlib.h
artifact: bzip2

fastlz:
type: library
static-libs@unix:
- libfastlz.a
headers:
- fastlz.h
artifact: fastlz

zlib:
type: library
static-libs@unix:
- libz.a
headers:
- zlib.h
- zconf.h
artifact: zlib
4 changes: 2 additions & 2 deletions spc.registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
},
"config": [
"config/pkg.ext.json",
"config/pkg.lib.json",
"config/pkg.lib.yaml",
"config/pkg.target.json"
]
},
"artifact": {
"config": [
"config/artifact.json"
"config/artifact.yaml"
],
"psr-4": {
"Package\\Artifact": "src/Package/Artifact"
Expand Down
23 changes: 23 additions & 0 deletions src/Package/Artifact/attr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Package\Artifact;

use StaticPHP\Artifact\Artifact;
use StaticPHP\Attribute\Artifact\AfterSourceExtract;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Util\SourcePatcher;
use StaticPHP\Util\System\LinuxUtil;

class attr
{
#[AfterSourceExtract('attr')]
#[PatchDescription('Patch attr for Alpine Linux (musl) and macOS - gethostname declaration')]
public function patchAttrForAlpine(Artifact $artifact): void
{
if (PHP_OS_FAMILY === 'Darwin' || PHP_OS_FAMILY === 'Linux' && LinuxUtil::isMuslDist()) {
SourcePatcher::patchFile('attr_alpine_gethostname.patch', $artifact->getSourceDir());
}
}
}
24 changes: 24 additions & 0 deletions src/Package/Artifact/bzip2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Package\Artifact;

use StaticPHP\Artifact\Artifact;
use StaticPHP\Attribute\Artifact\AfterSourceExtract;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Util\FileSystem;

class bzip2
{
#[AfterSourceExtract('bzip2')]
#[PatchDescription('Patch bzip2 Makefile to add -fPIC flag for position-independent code')]
public function patchBzip2Makefile(Artifact $artifact): void
{
FileSystem::replaceFileStr(
$artifact->getSourceDir() . '/Makefile',
'CFLAGS=-Wall',
'CFLAGS=-fPIC -Wall'
);
}
}
29 changes: 29 additions & 0 deletions src/Package/Library/attr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Package\Library;

use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;

#[Library('attr')]
class attr
{
#[BuildFor('Linux')]
#[BuildFor('Darwin')]
public function build(LibraryPackage $lib): void
{
UnixAutoconfExecutor::create($lib)
->appendEnv([
'CFLAGS' => '-Wno-int-conversion -Wno-implicit-function-declaration',
])
->exec('libtoolize --force --copy')
->exec('./autogen.sh || autoreconf -if')
->configure('--disable-nls')
->make('install-attributes_h install-data install-libattr_h install-libLTLIBRARIES install-pkgincludeHEADERS install-pkgconfDATA', with_install: false);
$lib->patchPkgconfPrefix(['libattr.pc'], PKGCONF_PATCH_PREFIX);
}
}
55 changes: 55 additions & 0 deletions src/Package/Library/brotli.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace Package\Library;

use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
use StaticPHP\Util\FileSystem;

#[Library('brotli')]
class brotli
{
#[BuildFor('Linux')]
#[BuildFor('Darwin')]
public function build(LibraryPackage $lib): void
{
UnixCMakeExecutor::create($lib)
->setBuildDir($lib->getSourceDir() . '/build-dir')
->addConfigureArgs("-DSHARE_INSTALL_PREFIX={$lib->getBuildRootPath()}")
->build();

// Patch pkg-config files
$lib->patchPkgconfPrefix(['libbrotlicommon.pc', 'libbrotlidec.pc', 'libbrotlienc.pc'], PKGCONF_PATCH_PREFIX);

// Add -lbrotlicommon to libbrotlidec.pc and libbrotlienc.pc
FileSystem::replaceFileLineContainsString(
$lib->getLibDir() . '/pkgconfig/libbrotlidec.pc',
'Libs: -L${libdir} -lbrotlidec',
'Libs: -L${libdir} -lbrotlidec -lbrotlicommon'
);
FileSystem::replaceFileLineContainsString(
$lib->getLibDir() . '/pkgconfig/libbrotlienc.pc',
'Libs: -L${libdir} -lbrotlienc',
'Libs: -L${libdir} -lbrotlienc -lbrotlicommon'
);

// Create symlink: libbrotli.a -> libbrotlicommon.a
shell()->cd($lib->getLibDir())->exec('ln -sf libbrotlicommon.a libbrotli.a');

// Remove dynamic libraries
foreach (FileSystem::scanDirFiles($lib->getLibDir(), false, true) as $filename) {
if (str_starts_with($filename, 'libbrotli') && (str_contains($filename, '.so') || str_ends_with($filename, '.dylib'))) {
unlink($lib->getLibDir() . '/' . $filename);
}
}

// Remove brotli binary if exists
if (file_exists($lib->getBinDir() . '/brotli')) {
unlink($lib->getBinDir() . '/brotli');
}
}
}
25 changes: 25 additions & 0 deletions src/Package/Library/bzip2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Package\Library;

use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Package\PackageBuilder;

#[Library('bzip2')]
class bzip2
{
#[BuildFor('Linux')]
#[BuildFor('Darwin')]
public function build(LibraryPackage $lib, PackageBuilder $builder): void
{
shell()->cd($lib->getSourceDir())->initializeEnv($lib)
->exec("make PREFIX='{$lib->getBuildRootPath()}' clean")
->exec("make -j{$builder->concurrency} PREFIX='{$lib->getBuildRootPath()}' libbz2.a")
->exec('cp libbz2.a ' . $lib->getLibDir())
->exec('cp bzlib.h ' . $lib->getIncludeDir());
}
}
36 changes: 36 additions & 0 deletions src/Package/Library/fastlz.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Package\Library;

use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Exception\BuildFailureException;
use StaticPHP\Package\LibraryPackage;

#[Library('fastlz')]
class fastlz
{
#[BuildFor('Linux')]
#[BuildFor('Darwin')]
public function build(LibraryPackage $lib): void
{
$cc = getenv('CC') ?: 'cc';
$ar = getenv('AR') ?: 'ar';

shell()->cd($lib->getSourceDir())->initializeEnv($lib)
->exec("{$cc} -c -O3 -fPIC fastlz.c -o fastlz.o")
->exec("{$ar} rcs libfastlz.a fastlz.o");

// Copy header file
if (!copy($lib->getSourceDir() . '/fastlz.h', $lib->getIncludeDir() . '/fastlz.h')) {
throw new BuildFailureException('Failed to copy fastlz.h');
}

// Copy static library
if (!copy($lib->getSourceDir() . '/libfastlz.a', $lib->getLibDir() . '/libfastlz.a')) {
throw new BuildFailureException('Failed to copy libfastlz.a');
}
}
}
24 changes: 24 additions & 0 deletions src/Package/Library/zlib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Package\Library;

use StaticPHP\Attribute\Package\BuildFor;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Package\LibraryPackage;
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;

#[Library('zlib')]
class zlib
{
#[BuildFor('Linux')]
#[BuildFor('Darwin')]
public function build(LibraryPackage $lib): void
{
UnixAutoconfExecutor::create($lib)->exec("./configure --static --prefix={$lib->getBuildRootPath()}")->make();

// Patch pkg-config file
$lib->patchPkgconfPrefix(['zlib.pc'], PKGCONF_PATCH_PREFIX);
}
}
Loading