This commit is contained in:
crazywhalecc
2025-11-30 15:35:04 +08:00
parent f6c818d3c0
commit 14bfb4198a
179 changed files with 19502 additions and 655 deletions

View File

@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Artifact;
/**
* Attribute to register a hook that runs after binary extraction completes.
*
* This is useful for post-extraction tasks like:
* - Setting executable permissions
* - Creating symlinks
* - Platform-specific binary setup
* - Verifying binary integrity
*
* The callback method signature should be:
* ```php
* function(string $target_path, string $platform): void
* ```
*
* - `$target_path`: The directory where binary was extracted
* - `$platform`: The current platform string (e.g., 'linux-x86_64')
*
* Multiple hooks can be registered for the same artifact using IS_REPEATABLE.
* Use the `$platforms` parameter to filter which platforms the hook should run on.
*
* @example
* ```php
* #[AfterBinaryExtract('zig')]
* public function setupZig(string $target_path, string $platform): void
* {
* // Setup zig after extraction (runs on all platforms)
* chmod("{$target_path}/zig", 0755);
* }
*
* #[AfterBinaryExtract('pkg-config', ['linux-x86_64', 'linux-aarch64'])]
* public function setupPkgConfigLinux(string $target_path): void
* {
* // Linux-specific setup for pkg-config
* symlink("{$target_path}/bin/pkg-config", "/usr/local/bin/pkg-config");
* }
*
* #[AfterBinaryExtract('openssl', ['darwin-aarch64'])]
* public function patchOpensslMacM1(string $target_path): void
* {
* // macOS ARM64 specific patches
* }
* ```
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
readonly class AfterBinaryExtract
{
/**
* @param string $artifact_name The name of the artifact this hook applies to
* @param string[] $platforms Platform filters (empty array means all platforms).
* Valid values: 'linux-x86_64', 'linux-aarch64', 'darwin-x86_64',
* 'darwin-aarch64', 'windows-x86_64', etc.
*/
public function __construct(
public string $artifact_name,
public array $platforms = []
) {}
}

View File

@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Artifact;
/**
* Attribute to register a hook that runs after source extraction completes.
*
* This is useful for post-extraction tasks like:
* - Patching source files
* - Removing unnecessary directories (tests, docs, etc.)
* - Applying platform-specific fixes
* - Renaming or reorganizing files
*
* The callback method signature should be:
* ```php
* function(string $target_path): void
* ```
*
* - `$target_path`: The directory where source was extracted
*
* Multiple hooks can be registered for the same artifact using IS_REPEATABLE.
*
* @example
* ```php
* #[AfterSourceExtract('php-src')]
* public function patchPhpSrc(string $target_path): void
* {
* // Apply patches after php-src is extracted
* FileSystem::replaceFileStr("{$target_path}/configure", 'old', 'new');
* }
*
* #[AfterSourceExtract('openssl')]
* public function cleanupOpenssl(string $target_path): void
* {
* // Remove unnecessary directories
* FileSystem::removeDir("{$target_path}/test");
* FileSystem::removeDir("{$target_path}/fuzz");
* }
* ```
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
readonly class AfterSourceExtract
{
/**
* @param string $artifact_name The name of the artifact this hook applies to
*/
public function __construct(public string $artifact_name) {}
}

View File

@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Artifact;
/**
* Attribute to completely take over the binary extraction process for an artifact.
*
* When this attribute is applied to a method, the standard extraction logic is bypassed,
* and the annotated method is responsible for extracting the binary files.
*
* The callback method signature should be:
* ```php
* function(Artifact $artifact, string $source_file, string $target_path, string $platform): void
* ```
*
* - `$artifact`: The artifact instance being extracted
* - `$source_file`: Path to the downloaded archive or directory
* - `$target_path`: The resolved target extraction path from config
* - `$platform`: The current platform string (e.g., 'linux-x86_64', 'darwin-aarch64')
*
* @example
* ```php
* #[BinaryExtract('special-tool', ['linux-x86_64', 'linux-aarch64'])]
* public function extractSpecialTool(Artifact $artifact, string $source_file, string $target_path): void
* {
* // Custom binary extraction logic
* }
* ```
*/
#[\Attribute(\Attribute::TARGET_METHOD)]
readonly class BinaryExtract
{
/**
* @param string $artifact_name The name of the artifact this extraction handler applies to
* @param string[] $platforms Platform filters (empty array means all platforms).
* Valid values: 'linux-x86_64', 'linux-aarch64', 'darwin-x86_64',
* 'darwin-aarch64', 'windows-x86_64', etc.
*/
public function __construct(
public string $artifact_name,
public array $platforms = []
) {}
}

View File

@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Artifact;
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class CustomBinary
{
public function __construct(public string $artifact_name, public array $support_os) {}
}

View File

@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Artifact;
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class CustomSource
{
public function __construct(public string $artifact_name) {}
}

View File

@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Artifact;
/**
* Attribute to completely take over the source extraction process for an artifact.
*
* When this attribute is applied to a method, the standard extraction logic is bypassed,
* and the annotated method is responsible for extracting the source files.
*
* The callback method signature should be:
* ```php
* function(Artifact $artifact, string $source_file, string $target_path): void
* ```
*
* - `$artifact`: The artifact instance being extracted
* - `$source_file`: Path to the downloaded archive or directory
* - `$target_path`: The resolved target extraction path from config
*
* @example
* ```php
* #[SourceExtract('weird-package')]
* public function extractWeirdPackage(Artifact $artifact, string $source_file, string $target_path): void
* {
* // Custom extraction logic
* shell_exec("tar -xf {$source_file} -C {$target_path} --strip-components=2");
* }
* ```
*/
#[\Attribute(\Attribute::TARGET_METHOD)]
readonly class SourceExtract
{
/**
* @param string $artifact_name The name of the artifact this extraction handler applies to
*/
public function __construct(public string $artifact_name) {}
}

View File

@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Doctor;
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class CheckItem
{
public mixed $callback = null;
public function __construct(
public string $item_name,
public ?string $limit_os = null,
public int $level = 100,
public bool $manual = false,
) {}
}

View File

@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Doctor;
/**
* Indicate a method is a fix item for doctor check.
*/
#[\Attribute(\Attribute::TARGET_METHOD)]
class FixItem
{
public function __construct(public string $name) {}
}

View File

@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Doctor;
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
class OptionalCheck
{
public function __construct(public array $check) {}
}

View File

@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Package;
/**
* Indicates that the annotated method should be executed after a specific stage of the build process for a given package.
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
readonly class AfterStage
{
public function __construct(public string $package_name, public string $stage, public ?string $only_when_package_resolved = null) {}
}

View File

@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Package;
/**
* Indicates that the annotated method should be executed before a specific stage of the build process for a given package.
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
readonly class BeforeStage
{
public function __construct(public string $package_name, public string $stage, public ?string $only_when_package_resolved = null) {}
}

View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Package;
/**
* Mark a method as building for a specific OS.
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
readonly class BuildFor
{
/**
* @param 'Darwin'|'Linux'|'Windows' $os The operating system to build for PHP_OS_FAMILY
*/
public function __construct(public string $os) {}
}

View File

@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Package;
/**
* Indicates a custom configure argument for PHP build process.
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
readonly class CustomPhpConfigureArg
{
public function __construct(public string $os = '') {}
}

View File

@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Package;
/**
* Indicates that the annotated class defines a PHP extension.
*/
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
readonly class Extension
{
public function __construct(public string $name) {}
}

View File

@@ -0,0 +1,8 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Package;
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class Info {}

View File

@@ -0,0 +1,8 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Package;
#[\Attribute(\Attribute::TARGET_METHOD)]
class InitPackage {}

View File

@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Package;
/**
* Indicates that the annotated class defines a library package.
*/
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
readonly class Library
{
public function __construct(public string $name) {}
}

View File

@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Package;
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
readonly class PatchBeforeBuild
{
public function __construct() {}
}

View File

@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Package;
/**
* Indicates that the annotated method is responsible for initializing the build process for a target package.
*/
#[\Attribute(\Attribute::TARGET_METHOD)]
class ResolveBuild {}

View File

@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Package;
/**
* Indicates that the annotated method defines a specific stage in a package.
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
readonly class Stage
{
public function __construct(public string $name) {}
}

View File

@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Package;
/**
* Indicates that the annotated class defines a target.
*/
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
readonly class Target
{
public function __construct(public string $name) {}
}

View File

@@ -0,0 +1,8 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute\Package;
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class Validate {}

View File

@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace StaticPHP\Attribute;
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
readonly class PatchDescription
{
public function __construct(public string $description) {}
}