From 192c8cde87890771e9fc1c81aef66c03f4bcb39f Mon Sep 17 00:00:00 2001 From: Jerry Ma Date: Thu, 19 Dec 2024 12:23:39 +0800 Subject: [PATCH] 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 --- config/ext.json | 26 +++++------ config/lib.json | 54 ++++++++++++++++------ config/source.json | 32 +++++++++++++ src/SPC/builder/linux/library/libaom.php | 12 +++++ src/SPC/builder/linux/library/libde265.php | 12 +++++ src/SPC/builder/linux/library/libheif.php | 12 +++++ src/SPC/builder/macos/library/libaom.php | 12 +++++ src/SPC/builder/macos/library/libde265.php | 12 +++++ src/SPC/builder/macos/library/libheif.php | 27 +++++++++++ src/SPC/builder/unix/library/libaom.php | 36 +++++++++++++++ src/SPC/builder/unix/library/libde265.php | 36 +++++++++++++++ src/SPC/builder/unix/library/libheif.php | 41 ++++++++++++++++ src/globals/ext-tests/imagick.php | 12 +++++ src/globals/test-extensions.php | 10 ++-- 14 files changed, 303 insertions(+), 31 deletions(-) create mode 100644 src/SPC/builder/linux/library/libaom.php create mode 100644 src/SPC/builder/linux/library/libde265.php create mode 100644 src/SPC/builder/linux/library/libheif.php create mode 100644 src/SPC/builder/macos/library/libaom.php create mode 100644 src/SPC/builder/macos/library/libde265.php create mode 100644 src/SPC/builder/macos/library/libheif.php create mode 100644 src/SPC/builder/unix/library/libaom.php create mode 100644 src/SPC/builder/unix/library/libde265.php create mode 100644 src/SPC/builder/unix/library/libheif.php create mode 100644 src/globals/ext-tests/imagick.php diff --git a/config/ext.json b/config/ext.json index 64ff42ec..ed55386e 100644 --- a/config/ext.json +++ b/config/ext.json @@ -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", diff --git a/config/lib.json b/config/lib.json index 8879763f..69f92737 100644 --- a/config/lib.json +++ b/config/lib.json @@ -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": [ diff --git a/config/source.json b/config/source.json index 7b77dab9..283561ca 100644 --- a/config/source.json +++ b/config/source.json @@ -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/", diff --git a/src/SPC/builder/linux/library/libaom.php b/src/SPC/builder/linux/library/libaom.php new file mode 100644 index 00000000..4a58a870 --- /dev/null +++ b/src/SPC/builder/linux/library/libaom.php @@ -0,0 +1,12 @@ +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; + } +} diff --git a/src/SPC/builder/unix/library/libaom.php b/src/SPC/builder/unix/library/libaom.php new file mode 100644 index 00000000..5ecf6704 --- /dev/null +++ b/src/SPC/builder/unix/library/libaom.php @@ -0,0 +1,36 @@ +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']); + } +} diff --git a/src/SPC/builder/unix/library/libde265.php b/src/SPC/builder/unix/library/libde265.php new file mode 100644 index 00000000..df02bbb3 --- /dev/null +++ b/src/SPC/builder/unix/library/libde265.php @@ -0,0 +1,36 @@ +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']); + } +} diff --git a/src/SPC/builder/unix/library/libheif.php b/src/SPC/builder/unix/library/libheif.php new file mode 100644 index 00000000..e2d2a486 --- /dev/null +++ b/src/SPC/builder/unix/library/libheif.php @@ -0,0 +1,41 @@ +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']); + } +} diff --git a/src/globals/ext-tests/imagick.php b/src/globals/ext-tests/imagick.php new file mode 100644 index 00000000..5fac8dcc --- /dev/null +++ b/src/globals/ext-tests/imagick.php @@ -0,0 +1,12 @@ + 'rdkafka', + 'Linux', 'Darwin' => 'imagick', 'Windows' => 'zlib', }; @@ -53,7 +53,7 @@ // 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', };