Implement fastlz, zlib (unix)

This commit is contained in:
crazywhalecc 2026-01-22 16:50:31 +08:00
parent 22fc7030f6
commit c27ed8b0b4
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680
5 changed files with 116 additions and 0 deletions

View File

@ -31,3 +31,22 @@ bzip2:
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

View File

@ -19,3 +19,20 @@ bzip2:
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

View File

@ -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');
}
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1,20 @@
(C) 1995-2022 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. 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.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jean-loup Gailly Mark Adler
jloup@gzip.org madler@alumni.caltech.edu