mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-02 22:35:43 +08:00
artifact: add path/binary/isInstalled static helpers
Give zig, rust, go_win and go_xcaddy a small consistent surface for locating the install directory and a binary inside it: - path(): install/extract root for the artifact - binary($name = '<default>'): full path to a binary under that root, picking the artifact's natural layout (top-level for zig, bin/ for rust and the go toolchains) - isInstalled(): is the default binary present on disk Callers that previously concatenated PKG_ROOT_PATH . '/zig/zig' (and the equivalents for the other artifacts) by hand can call the helpers instead, and any later code that needs to ask "is this toolchain available" can use isInstalled() without rebuilding the path.
This commit is contained in:
@@ -15,6 +15,23 @@ use StaticPHP\Util\GlobalEnvManager;
|
||||
|
||||
class go_win
|
||||
{
|
||||
/** GOROOT for the Windows Go toolchain. */
|
||||
public static function path(): string
|
||||
{
|
||||
return PKG_ROOT_PATH . '/go-win';
|
||||
}
|
||||
|
||||
/** Path to a binary inside go-win's bin/ (go.exe, gofmt.exe, …). */
|
||||
public static function binary(string $name = 'go.exe'): string
|
||||
{
|
||||
return self::path() . '/bin/' . $name;
|
||||
}
|
||||
|
||||
public static function isInstalled(): bool
|
||||
{
|
||||
return is_file(self::binary());
|
||||
}
|
||||
|
||||
#[CustomBinary('go-win', [
|
||||
'windows-x86_64',
|
||||
])]
|
||||
|
||||
@@ -17,6 +17,23 @@ use StaticPHP\Util\System\LinuxUtil;
|
||||
|
||||
class go_xcaddy
|
||||
{
|
||||
/** GOROOT for the bundled Go toolchain used to build xcaddy. */
|
||||
public static function path(): string
|
||||
{
|
||||
return PKG_ROOT_PATH . '/go-xcaddy';
|
||||
}
|
||||
|
||||
/** Path to a binary inside go-xcaddy's bin/ (xcaddy, go, …). */
|
||||
public static function binary(string $name = 'xcaddy'): string
|
||||
{
|
||||
return self::path() . '/bin/' . $name;
|
||||
}
|
||||
|
||||
public static function isInstalled(): bool
|
||||
{
|
||||
return is_file(self::binary());
|
||||
}
|
||||
|
||||
#[CustomBinary('go-xcaddy', [
|
||||
'linux-x86_64',
|
||||
'linux-aarch64',
|
||||
|
||||
@@ -16,6 +16,23 @@ use StaticPHP\Util\System\LinuxUtil;
|
||||
|
||||
class rust
|
||||
{
|
||||
/** Install prefix the rust tarball's install.sh writes into. */
|
||||
public static function path(): string
|
||||
{
|
||||
return PKG_ROOT_PATH . '/rust';
|
||||
}
|
||||
|
||||
/** Path to a binary inside the rust install dir (cargo, rustc, rustup, …). */
|
||||
public static function binary(string $name = 'cargo'): string
|
||||
{
|
||||
return self::path() . '/bin/' . $name;
|
||||
}
|
||||
|
||||
public static function isInstalled(): bool
|
||||
{
|
||||
return is_file(self::binary());
|
||||
}
|
||||
|
||||
#[CustomBinary('rust', [
|
||||
'linux-x86_64',
|
||||
'linux-aarch64',
|
||||
|
||||
@@ -15,6 +15,23 @@ use StaticPHP\Runtime\SystemTarget;
|
||||
|
||||
class zig
|
||||
{
|
||||
/** Directory zig extracts into. */
|
||||
public static function path(): string
|
||||
{
|
||||
return PKG_ROOT_PATH . '/zig';
|
||||
}
|
||||
|
||||
/** Path to a binary inside the zig install dir (zig, zig-cc, zig-c++, zig-ar, …). */
|
||||
public static function binary(string $name = 'zig'): string
|
||||
{
|
||||
return self::path() . '/' . $name;
|
||||
}
|
||||
|
||||
public static function isInstalled(): bool
|
||||
{
|
||||
return is_file(self::binary());
|
||||
}
|
||||
|
||||
#[CustomBinary('zig', [
|
||||
'linux-x86_64',
|
||||
'linux-aarch64',
|
||||
|
||||
Reference in New Issue
Block a user