mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-19 13:24:51 +08:00
Implement attr, brotli, bzip2 build for unix
This commit is contained in:
parent
7b725bb4da
commit
22fc7030f6
33
config/artifact.yaml
Normal file
33
config/artifact.yaml
Normal file
@ -0,0 +1,33 @@
|
||||
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
|
||||
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
|
||||
21
config/pkg.lib.yaml
Normal file
21
config/pkg.lib.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
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
|
||||
@ -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"
|
||||
|
||||
23
src/Package/Artifact/attr.php
Normal file
23
src/Package/Artifact/attr.php
Normal file
@ -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
src/Package/Artifact/bzip2.php
Normal file
24
src/Package/Artifact/bzip2.php
Normal file
@ -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
src/Package/Library/attr.php
Normal file
29
src/Package/Library/attr.php
Normal file
@ -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
src/Package/Library/brotli.php
Normal file
55
src/Package/Library/brotli.php
Normal file
@ -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
src/Package/Library/bzip2.php
Normal file
25
src/Package/Library/bzip2.php
Normal file
@ -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());
|
||||
}
|
||||
}
|
||||
14
src/globals/licenses/bzip2.txt
Normal file
14
src/globals/licenses/bzip2.txt
Normal file
@ -0,0 +1,14 @@
|
||||
This program, "bzip2", the associated library "libbzip2", and all documentation, are copyright (C) 1996-2010 Julian R Seward. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
2. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
3. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
4. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Julian Seward, jseward@bzip.org bzip2/libbzip2 version 1.0.6 of 6 September 2010
|
||||
|
||||
PATENTS: To the best of my knowledge, bzip2 and libbzip2 do not use any patented algorithms. However, I do not have the resources to carry out a patent search. Therefore I cannot give any guarantee of the above statement.
|
||||
Loading…
x
Reference in New Issue
Block a user