Add libaom, libde265, libheif support, for imagick AVIF format support (#575)

* Add libaom, libde265, libheif support, for imagick AVIF format support

* Fix aom optimization

* Fix aom build command

* Fix libheif build command

* Fix libheif build

* cs fix
This commit is contained in:
Jerry Ma 2024-12-19 12:23:39 +08:00 committed by GitHub
parent d4ec366c5f
commit 192c8cde87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 303 additions and 31 deletions

View File

@ -560,6 +560,19 @@
"source": "rar",
"cpp-extension": true
},
"rdkafka": {
"support": {
"BSD": "wip",
"Windows": "wip"
},
"type": "external",
"source": "ext-rdkafka",
"arg-type": "custom",
"cpp-extension": true,
"lib-depends": [
"librdkafka"
]
},
"readline": {
"support": {
"Windows": "wip",
@ -708,19 +721,6 @@
"zlib"
]
},
"rdkafka": {
"support": {
"BSD": "wip",
"Windows": "wip"
},
"type": "external",
"source": "ext-rdkafka",
"arg-type": "custom",
"cpp-extension": true,
"lib-depends": [
"librdkafka"
]
},
"swoole": {
"support": {
"Windows": "no",

View File

@ -176,7 +176,8 @@
"libjpeg",
"libwebp",
"freetype",
"libtiff"
"libtiff",
"libheif"
],
"lib-suggests": [
"zstd",
@ -208,6 +209,13 @@
"libsodium"
]
},
"libaom": {
"source": "libaom",
"static-libs-unix": [
"libaom.a"
],
"cpp-library": true
},
"libargon2": {
"source": "libargon2",
"static-libs-unix": [
@ -235,6 +243,13 @@
"ares_rules.h"
]
},
"libde265": {
"source": "libde265",
"static-libs-unix": [
"libde265.a"
],
"cpp-library": true
},
"libevent": {
"source": "libevent",
"static-libs-unix": [
@ -276,6 +291,19 @@
"fficonfig.h"
]
},
"libheif": {
"source": "libheif",
"static-libs-unix": [
"libheif.a"
],
"lib-depends": [
"libde265",
"libwebp",
"libaom",
"zlib",
"brotli"
]
},
"libiconv": {
"source": "libiconv",
"static-libs-unix": [
@ -355,6 +383,18 @@
"openssl"
]
},
"librdkafka": {
"source": "librdkafka",
"static-libs-unix": [
"librdkafka.a",
"librdkafka++.a",
"librdkafka-static.a"
],
"cpp-library": true,
"lib-suggests": [
"zstd"
]
},
"libsodium": {
"source": "libsodium",
"static-libs-unix": [
@ -558,18 +598,6 @@
"pkg-config": {
"source": "pkg-config"
},
"librdkafka": {
"source": "librdkafka",
"static-libs-unix": [
"librdkafka.a",
"librdkafka++.a",
"librdkafka-static.a"
],
"cpp-library": true,
"lib-suggests": [
"zstd"
]
},
"postgresql": {
"source": "postgresql",
"static-libs-unix": [

View File

@ -303,6 +303,16 @@
"path": "LICENSE"
}
},
"libaom": {
"type": "git",
"rev": "main",
"url": "https://aomedia.googlesource.com/aom",
"provide-pre-built": true,
"license": {
"type": "file",
"path": "LICENSE"
}
},
"libargon2": {
"type": "git",
"rev": "master",
@ -338,6 +348,17 @@
"path": "LICENSE.md"
}
},
"libde265": {
"type": "ghrel",
"repo": "strukturag/libde265",
"match": "libde265-.+\\.tar\\.gz",
"prefer-stable": true,
"provide-pre-built": true,
"license": {
"type": "file",
"path": "COPYING"
}
},
"libevent": {
"type": "ghrel",
"repo": "libevent/libevent",
@ -368,6 +389,17 @@
"path": "LICENSE"
}
},
"libheif": {
"type": "ghrel",
"repo": "strukturag/libheif",
"match": "libheif-.+\\.tar\\.gz",
"prefer-stable": true,
"provide-pre-built": true,
"license": {
"type": "file",
"path": "COPYING"
}
},
"libiconv": {
"type": "filelist",
"url": "https://ftp.gnu.org/gnu/libiconv/",

View File

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace SPC\builder\linux\library;
class libaom extends LinuxLibraryBase
{
use \SPC\builder\unix\library\libaom;
public const NAME = 'libaom';
}

View File

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace SPC\builder\linux\library;
class libde265 extends LinuxLibraryBase
{
use \SPC\builder\unix\library\libde265;
public const NAME = 'libde265';
}

View File

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace SPC\builder\linux\library;
class libheif extends LinuxLibraryBase
{
use \SPC\builder\unix\library\libheif;
public const NAME = 'libheif';
}

View File

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace SPC\builder\macos\library;
class libaom extends MacOSLibraryBase
{
use \SPC\builder\unix\library\libaom;
public const NAME = 'libaom';
}

View File

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace SPC\builder\macos\library;
class libde265 extends MacOSLibraryBase
{
use \SPC\builder\unix\library\libde265;
public const NAME = 'libde265';
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace SPC\builder\macos\library;
use SPC\store\FileSystem;
class libheif extends MacOSLibraryBase
{
use \SPC\builder\unix\library\libheif;
public const NAME = 'libheif';
public function patchBeforeBuild(): bool
{
if (!str_contains(file_get_contents($this->source_dir . '/CMakeLists.txt'), 'libbrotlienc')) {
FileSystem::replaceFileStr(
$this->source_dir . '/CMakeLists.txt',
'list(APPEND REQUIRES_PRIVATE "libbrotlidec")',
'list(APPEND REQUIRES_PRIVATE "libbrotlidec")' . "\n" . ' list(APPEND REQUIRES_PRIVATE "libbrotlienc")'
);
return true;
}
return false;
}
}

View File

@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace SPC\builder\unix\library;
use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
use SPC\store\FileSystem;
trait libaom
{
/**
* @throws RuntimeException
* @throws FileSystemException
*/
protected function build(): void
{
// CMake needs a clean build directory
FileSystem::resetDir($this->source_dir . '/builddir');
// Start build
shell()->cd($this->source_dir . '/builddir')
->exec(
'cmake ' .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
'-DCMAKE_BUILD_TYPE=Release ' .
'-DBUILD_SHARED_LIBS=OFF ' .
'-DAOM_TARGET_CPU=generic ' .
'..'
)
->exec("cmake --build . -j {$this->builder->concurrency}")
->exec('make install');
$this->patchPkgconfPrefix(['aom.pc']);
}
}

View File

@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace SPC\builder\unix\library;
use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
use SPC\store\FileSystem;
trait libde265
{
/**
* @throws RuntimeException
* @throws FileSystemException
*/
protected function build(): void
{
// CMake needs a clean build directory
FileSystem::resetDir($this->source_dir . '/build');
// Start build
shell()->cd($this->source_dir . '/build')
->exec(
'cmake ' .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
'-DCMAKE_BUILD_TYPE=Release ' .
'-DBUILD_SHARED_LIBS=OFF ' .
'-DENABLE_SDL=OFF ' . // Disable SDL, currently not supported
'..'
)
->exec("cmake --build . -j {$this->builder->concurrency}")
->exec('make install');
$this->patchPkgconfPrefix(['libde265.pc']);
}
}

View File

@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace SPC\builder\unix\library;
use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
use SPC\store\FileSystem;
trait libheif
{
/**
* @throws RuntimeException
* @throws FileSystemException
*/
protected function build(): void
{
// CMake needs a clean build directory
FileSystem::resetDir($this->source_dir . '/build');
// Start build
shell()->cd($this->source_dir . '/build')
->exec(
'cmake ' .
'--preset=release ' .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
'-DCMAKE_BUILD_TYPE=Release ' .
'-DBUILD_SHARED_LIBS=OFF ' .
'-DWITH_EXAMPLES=OFF ' .
'-DWITH_GDK_PIXBUF=OFF ' .
'-DBUILD_TESTING=OFF ' .
'-DWITH_LIBSHARPYUV=ON ' . // optional: libwebp
'-DENABLE_PLUGIN_LOADING=OFF ' .
'..'
)
->exec("cmake --build . -j {$this->builder->concurrency}")
->exec('make install');
$this->patchPkgconfPrefix(['libheif.pc']);
}
}

View File

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
assert(class_exists('Imagick'));
assert(Imagick::queryFormats('AVIF') !== []);
assert(Imagick::queryFormats('HEIF') !== []);
assert(Imagick::queryFormats('HEIC') !== []);
assert(Imagick::queryFormats('WEBP') !== []);
assert(Imagick::queryFormats('JPEG') !== []);
assert(Imagick::queryFormats('PNG') !== []);
assert(Imagick::queryFormats('TIFF') !== []);

View File

@ -21,9 +21,9 @@ $test_php_version = [
// test os (macos-13, macos-14, ubuntu-latest, windows-latest are available)
$test_os = [
// 'macos-14',
'macos-13',
// 'ubuntu-latest',
'macos-14',
// 'macos-13',
'ubuntu-latest',
];
// whether enable thread safe
@ -39,7 +39,7 @@ $prefer_pre_built = true;
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
$extensions = match (PHP_OS_FAMILY) {
'Linux', 'Darwin' => 'rdkafka',
'Linux', 'Darwin' => 'imagick',
'Windows' => 'zlib',
};
@ -53,7 +53,7 @@ $with_libs = match (PHP_OS_FAMILY) {
// You can use `common`, `bulk`, `minimal` or `none`.
// note: combination is only available for *nix platform. Windows must use `none` combination
$base_combination = match (PHP_OS_FAMILY) {
'Linux', 'Darwin' => 'bulk',
'Linux', 'Darwin' => 'minimal',
'Windows' => 'none',
};