Forward-port #1006 changes

This commit is contained in:
crazywhalecc 2026-02-05 19:21:13 +08:00
parent 8fc2da9acf
commit 97634b009f
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680
7 changed files with 49 additions and 22 deletions

View File

@ -25,8 +25,10 @@ class zig
$index_json = json_decode($index_json ?: '', true);
$latest_version = null;
foreach ($index_json as $version => $data) {
$latest_version = $version;
break;
if ($version !== 'master') {
$latest_version = $version;
break;
}
}
if (!$latest_version) {

View File

@ -21,10 +21,11 @@ class GitHubRelease implements DownloadTypeInterface, ValidatorInterface
private ?string $version = null;
public function getGitHubReleases(string $name, string $repo, bool $prefer_stable = true): array
public function getGitHubReleases(string $name, string $repo, bool $prefer_stable = true, ?string $query = null): array
{
logger()->debug("Fetching {$name} GitHub releases from {$repo}");
$url = str_replace('{repo}', $repo, self::API_URL);
$url .= ($query ?? '');
$headers = $this->getGitHubTokenHeaders();
$data2 = default_shell()->executeCurl($url, headers: $headers);
$data = json_decode($data2 ?: '', true);
@ -45,9 +46,10 @@ class GitHubRelease implements DownloadTypeInterface, ValidatorInterface
* Get the latest GitHub release assets for a given repository.
* match_asset is provided, only return the asset that matches the regex.
*/
public function getLatestGitHubRelease(string $name, string $repo, bool $prefer_stable, string $match_asset): array
public function getLatestGitHubRelease(string $name, string $repo, bool $prefer_stable, string $match_asset, ?string $query = null): array
{
$url = str_replace('{repo}', $repo, self::API_URL);
$url .= ($query ?? '');
$headers = $this->getGitHubTokenHeaders();
$data2 = default_shell()->executeCurl($url, headers: $headers);
$data = json_decode($data2 ?: '', true);
@ -81,7 +83,7 @@ class GitHubRelease implements DownloadTypeInterface, ValidatorInterface
if (!isset($config['match'])) {
throw new DownloaderException("GitHubRelease downloader requires 'match' config for {$name}");
}
$rel = $this->getLatestGitHubRelease($name, $config['repo'], $config['prefer-stable'] ?? true, $config['match']);
$rel = $this->getLatestGitHubRelease($name, $config['repo'], $config['prefer-stable'] ?? true, $config['match'], $config['query'] ?? null);
// download file using curl
$asset_url = str_replace(['{repo}', '{id}'], [$config['repo'], $rel['id']], self::ASSET_URL);

View File

@ -23,9 +23,10 @@ class GitHubTarball implements DownloadTypeInterface
* If match_url is provided, only return the tarball that matches the regex.
* Otherwise, return the first tarball found.
*/
public function getGitHubTarballInfo(string $name, string $repo, string $rel_type, bool $prefer_stable = true, ?string $match_url = null, ?string $basename = null): array
public function getGitHubTarballInfo(string $name, string $repo, string $rel_type, bool $prefer_stable = true, ?string $match_url = null, ?string $basename = null, ?string $query = null): array
{
$url = str_replace(['{repo}', '{rel_type}'], [$repo, $rel_type], self::API_URL);
$url .= ($query ?? '');
$data = default_shell()->executeCurl($url, headers: $this->getGitHubTokenHeaders());
$data = json_decode($data ?: '', true);
if (!is_array($data)) {
@ -33,7 +34,10 @@ class GitHubTarball implements DownloadTypeInterface
}
$url = null;
foreach ($data as $rel) {
if (($rel['prerelease'] ?? false) === true && $prefer_stable) {
$prerelease = $rel['prerelease'] ?? false;
$draft = $rel['draft'] ?? false;
$tarball_url = $rel['tarball_url'] ?? null;
if ($prerelease && $prefer_stable || $draft && $prefer_stable || !$tarball_url) {
continue;
}
if ($match_url === null) {
@ -70,7 +74,7 @@ class GitHubTarball implements DownloadTypeInterface
'ghtagtar' => 'tags',
default => throw new DownloaderException("Invalid GitHubTarball type for {$name}"),
};
[$url, $filename] = $this->getGitHubTarballInfo($name, $config['repo'], $rel_type, $config['prefer-stable'] ?? true, $config['match'] ?? null, $name);
[$url, $filename] = $this->getGitHubTarballInfo($name, $config['repo'], $rel_type, $config['prefer-stable'] ?? true, $config['match'] ?? null, $name, $config['query'] ?? null);
$path = DOWNLOAD_PATH . "/{$filename}";
default_shell()->executeCurlDownload($url, $path, headers: $this->getGitHubTokenHeaders());
return DownloadResult::archive($filename, $config, $config['extract'] ?? null, version: $this->version);

View File

@ -82,9 +82,9 @@ class ConfigValidator
public const array ARTIFACT_TYPE_FIELDS = [ // [required_fields, optional_fields]
'filelist' => [['url', 'regex'], ['extract']],
'git' => [['url'], ['extract', 'submodules', 'rev', 'regex']],
'ghtagtar' => [['repo'], ['extract', 'prefer-stable', 'match']],
'ghtar' => [['repo'], ['extract', 'prefer-stable', 'match']],
'ghrel' => [['repo', 'match'], ['extract', 'prefer-stable']],
'ghtagtar' => [['repo'], ['extract', 'prefer-stable', 'match', 'query']],
'ghtar' => [['repo'], ['extract', 'prefer-stable', 'match', 'query']],
'ghrel' => [['repo', 'match'], ['extract', 'prefer-stable', 'query']],
'url' => [['url'], ['filename', 'extract', 'version']],
'bitbuckettag' => [['repo'], ['extract']],
'local' => [['dirname'], ['extract']],

View File

@ -64,7 +64,8 @@ class ZigToolchain implements UnixToolchainInterface
$cflags = getenv('SPC_DEFAULT_C_FLAGS') ?: getenv('CFLAGS') ?: '';
$has_avx512 = str_contains($cflags, '-mavx512') || str_contains($cflags, '-march=x86-64-v4');
if (!$has_avx512) {
GlobalEnvManager::putenv('SPC_EXTRA_PHP_VARS=php_cv_have_avx512=no php_cv_have_avx512vbmi=no');
$extra_vars = getenv('SPC_EXTRA_PHP_VARS') ?: '';
GlobalEnvManager::putenv("SPC_EXTRA_PHP_VARS=php_cv_have_avx512=no php_cv_have_avx512vbmi=no {$extra_vars}");
}
}

View File

@ -314,12 +314,7 @@ class FileSystem
continue;
}
$sub_file = self::convertPath($dir . '/' . $v);
if (is_dir($sub_file)) {
# 如果是 目录 且 递推 , 则递推添加下级文件
if (!self::removeDir($sub_file)) {
return false;
}
} elseif (is_link($sub_file) || is_file($sub_file)) {
if (is_link($sub_file) || is_file($sub_file)) {
if (!unlink($sub_file)) {
$cmd = PHP_OS_FAMILY === 'Windows' ? 'del /f /q' : 'rm -f';
f_exec("{$cmd} " . escapeshellarg($sub_file), $out, $ret);
@ -328,6 +323,11 @@ class FileSystem
return false;
}
}
} elseif (is_dir($sub_file)) {
# 如果是 目录 且 递推 , 则递推添加下级文件
if (!self::removeDir($sub_file)) {
return false;
}
}
}
if (is_link($dir)) {

View File

@ -291,9 +291,18 @@ class SPCConfigUtil
// parse pkg-configs
foreach ($packages as $package) {
$pc = PackageConfig::get($package, 'pkg-configs', []);
$pkg_config_path = getenv('PKG_CONFIG_PATH') ?: '';
$search_paths = array_filter(explode(SystemTarget::isUnix() ? ':' : ';', $pkg_config_path));
foreach ($pc as $file) {
if (!file_exists(BUILD_LIB_PATH . "/pkgconfig/{$file}.pc")) {
throw new WrongUsageException("pkg-config file '{$file}.pc' for lib [{$package}] does not exist in '" . BUILD_LIB_PATH . "/pkgconfig'. Please build it first.");
$found = false;
foreach ($search_paths as $path) {
if (file_exists($path . "/{$file}.pc")) {
$found = true;
break;
}
}
if (!$found) {
throw new WrongUsageException("pkg-config file '{$file}.pc' for lib [{$package}] does not exist. Please build it first.");
}
}
$pc_cflags = implode(' ', $pc);
@ -324,9 +333,18 @@ class SPCConfigUtil
if (SystemTarget::isUnix()) {
// add pkg-configs libs
$pkg_configs = PackageConfig::get($package, 'pkg-configs', []);
$pkg_config_path = getenv('PKG_CONFIG_PATH') ?: '';
$search_paths = array_filter(explode(':', $pkg_config_path));
foreach ($pkg_configs as $pkg_config) {
if (!file_exists(BUILD_LIB_PATH . "/pkgconfig/{$pkg_config}.pc")) {
throw new WrongUsageException("pkg-config file '{$pkg_config}.pc' for lib [{$package}] does not exist in '" . BUILD_LIB_PATH . "/pkgconfig'. Please build it first.");
$found = false;
foreach ($search_paths as $path) {
if (file_exists($path . "/{$pkg_config}.pc")) {
$found = true;
break;
}
}
if (!$found) {
throw new WrongUsageException("pkg-config file '{$pkg_config}.pc' for lib [{$package}] does not exist. Please build it first.");
}
}
$pkg_configs = implode(' ', $pkg_configs);