-
-
Notifications
You must be signed in to change notification settings - Fork 351
v3-refactor: Implement v2 libs #1021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
crazywhalecc
wants to merge
5
commits into
v3-dev
Choose a base branch
from
v3-refactor/libs
base: v3-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1865762
Fix config yaml support
crazywhalecc ae74875
Fix config yaml support
crazywhalecc 7b725bb
Add LicenseDumper component
crazywhalecc 22fc703
Implement attr, brotli, bzip2 build for unix
crazywhalecc c27ed8b
Implement fastlz, zlib (unix)
crazywhalecc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
binaryI think. Andhostedis just an alias like this:My expected goal is:
That means that
binaryis a pre-built product that only needs to be installed, including the pre-built itself. If thehostedalias is expanded, it might look similar to the binary in pkg-config above.There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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-builtis more appropriate thanhosted. 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.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
This would be fine.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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
binarythat can represent "pre-built", "closed source software", and "other non-source artifacts" at the same time. Their functions and behaviors are the same.There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.