Use zig toolchain by default, lint files

This commit is contained in:
crazywhalecc
2026-02-03 14:01:41 +08:00
parent 6fdbf629dc
commit 38f742156d
20 changed files with 373 additions and 365 deletions

View File

@@ -83,7 +83,7 @@ SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime
; - gnu-native: used for general linux distros, can build gnu target for the installed glibc version only. ; - gnu-native: used for general linux distros, can build gnu target for the installed glibc version only.
; option to specify the target, superceded by SPC_TARGET if set ; option to specify the target, superceded by SPC_TARGET if set
SPC_LIBC=musl ; SPC_LIBC=musl
; uncomment to link libc dynamically on musl ; uncomment to link libc dynamically on musl
; SPC_MUSL_DYNAMIC=true ; SPC_MUSL_DYNAMIC=true
@@ -94,13 +94,13 @@ SPC_LIBC=musl
; `native-native` - links against system libc dynamically ; `native-native` - links against system libc dynamically
; `native-native-musl` - links against musl libc statically ; `native-native-musl` - links against musl libc statically
; `native-native-musl -dynamic` - links against musl libc dynamically ; `native-native-musl -dynamic` - links against musl libc dynamically
; SPC_TARGET= SPC_TARGET=native-native-musl
; compiler environments ; compiler environments (default value is defined by selected toolchain)
CC=${SPC_LINUX_DEFAULT_CC} CC=${SPC_DEFAULT_CC}
CXX=${SPC_LINUX_DEFAULT_CXX} CXX=${SPC_DEFAULT_CXX}
AR=${SPC_LINUX_DEFAULT_AR} AR=${SPC_DEFAULT_AR}
LD=${SPC_LINUX_DEFAULT_LD} LD=${SPC_DEFAULT_LD}
; default compiler flags, used in CMake toolchain file, openssl and pkg-config build ; default compiler flags, used in CMake toolchain file, openssl and pkg-config build
SPC_DEFAULT_C_FLAGS="-fPIC -Os" SPC_DEFAULT_C_FLAGS="-fPIC -Os"
SPC_DEFAULT_CXX_FLAGS="-fPIC -Os" SPC_DEFAULT_CXX_FLAGS="-fPIC -Os"
@@ -132,11 +132,11 @@ OPENSSLDIR=""
; build target: macho or macho (possibly we could support macho-universal in the future) ; build target: macho or macho (possibly we could support macho-universal in the future)
; Currently we do not support universal and cross-compilation for macOS. ; Currently we do not support universal and cross-compilation for macOS.
SPC_TARGET=native-macos SPC_TARGET=native-macos
; compiler environments ; compiler environments (default value is defined by selected toolchain)
CC=clang CC=${SPC_DEFAULT_CC}
CXX=clang++ CXX=${SPC_DEFAULT_CXX}
AR=ar AR=${SPC_DEFAULT_AR}
LD=ld LD=${SPC_DEFAULT_LD}
; default compiler flags, used in CMake toolchain file, openssl and pkg-config build ; default compiler flags, used in CMake toolchain file, openssl and pkg-config build
SPC_DEFAULT_C_FLAGS="--target=${MAC_ARCH}-apple-darwin -Os" SPC_DEFAULT_C_FLAGS="--target=${MAC_ARCH}-apple-darwin -Os"
SPC_DEFAULT_CXX_FLAGS="--target=${MAC_ARCH}-apple-darwin -Os" SPC_DEFAULT_CXX_FLAGS="--target=${MAC_ARCH}-apple-darwin -Os"

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,6 @@
{ {
"frankenphp": { "frankenphp": {
"type": "virtual-target",
"artifact": "frankenphp", "artifact": "frankenphp",
"depends": [ "depends": [
"php-embed", "php-embed",
@@ -9,90 +10,78 @@
"php-embed", "php-embed",
"go-xcaddy", "go-xcaddy",
"libxml2" "libxml2"
], ]
"type": "virtual-target"
}, },
"go-xcaddy": { "go-xcaddy": {
"type": "target",
"artifact": "go-xcaddy", "artifact": "go-xcaddy",
"static-bins": [ "static-bins": [
"xcaddy" "xcaddy"
], ]
"type": "target"
}, },
"musl-toolchain": { "musl-toolchain": {
"artifact": "musl-toolchain", "type": "target",
"type": "target" "artifact": "musl-toolchain"
}, },
"nasm": { "nasm": {
"artifact": "nasm", "type": "target",
"type": "target" "artifact": "nasm"
}, },
"php": { "php": {
"type": "target",
"artifact": "php-src", "artifact": "php-src",
"depends@macos": [ "depends@macos": [
"libxml2" "libxml2"
], ]
"type": "target"
}, },
"php-cgi": { "php-cgi": {
"type": "virtual-target",
"depends": [ "depends": [
"php" "php"
], ]
"type": "virtual-target"
}, },
"php-cli": { "php-cli": {
"type": "virtual-target",
"depends": [ "depends": [
"php" "php"
], ]
"type": "virtual-target"
}, },
"php-embed": { "php-embed": {
"type": "virtual-target",
"depends": [ "depends": [
"php" "php"
], ]
"type": "virtual-target"
}, },
"php-fpm": { "php-fpm": {
"type": "virtual-target",
"depends": [ "depends": [
"php" "php"
], ]
"type": "virtual-target"
}, },
"php-micro": { "php-micro": {
"type": "virtual-target",
"artifact": "micro", "artifact": "micro",
"depends": [ "depends": [
"php" "php"
], ]
"type": "virtual-target"
}, },
"php-sdk-binary-tools": { "php-sdk-binary-tools": {
"artifact": "php-sdk-binary-tools", "type": "target",
"type": "target" "artifact": "php-sdk-binary-tools"
},
"pkg-config": {
"artifact": "pkg-config",
"static-bins": [
"pkg-config"
],
"type": "target"
}, },
"strawberry-perl": { "strawberry-perl": {
"artifact": "strawberry-perl", "type": "target",
"type": "target" "artifact": "strawberry-perl"
}, },
"upx": { "upx": {
"artifact": "upx", "type": "target",
"type": "target" "artifact": "upx"
}, },
"vswhere": { "vswhere": {
"type": "target",
"artifact": "vswhere", "artifact": "vswhere",
"static-bins@windows": [ "static-bins@windows": [
"vswhere.exe" "vswhere.exe"
], ]
"type": "target"
},
"zig": {
"artifact": "zig",
"type": "target"
} }
} }

View File

@@ -4,15 +4,11 @@ curl:
source: source:
type: ghrel type: ghrel
repo: curl/curl repo: curl/curl
match: 'curl.+\.tar\.xz' match: curl.+\.tar\.xz
prefer-stable: true prefer-stable: true
metadata: metadata:
license-files: [COPYING] license-files: [COPYING]
license: curl license: curl
static-libs@unix:
- libcurl.a
headers:
- curl
depends@unix: depends@unix:
- openssl - openssl
- zlib - zlib
@@ -31,3 +27,7 @@ curl:
- CoreFoundation - CoreFoundation
- CoreServices - CoreServices
- SystemConfiguration - SystemConfiguration
headers:
- curl
static-libs@unix:
- libcurl.a

View File

@@ -10,10 +10,10 @@ gettext:
license: LGPL-2.1-or-later license: LGPL-2.1-or-later
depends: depends:
- libiconv - libiconv
suggests:
- ncurses
- libxml2
frameworks: frameworks:
- CoreFoundation - CoreFoundation
static-libs@unix: static-libs@unix:
- libintl.a - libintl.a
suggests:
- ncurses
- libxml2

View File

@@ -11,11 +11,11 @@ idn2:
depends@macos: depends@macos:
- libiconv - libiconv
- gettext - gettext
headers:
- idn2.h
pkg-configs:
- libidn2
suggests@unix: suggests@unix:
- libiconv - libiconv
- gettext - gettext
- libunistring - libunistring
headers:
- idn2.h
pkg-configs:
- libidn2

View File

@@ -11,6 +11,9 @@ krb5:
source-root: src source-root: src
depends: depends:
- openssl - openssl
suggests:
- ldap
- libedit
frameworks: frameworks:
- Kerberos - Kerberos
headers: headers:
@@ -18,6 +21,3 @@ krb5:
- gssapi/gssapi.h - gssapi/gssapi.h
pkg-configs: pkg-configs:
- krb5-gssapi - krb5-gssapi
suggests:
- ldap
- libedit

View File

@@ -10,10 +10,10 @@ libxml2:
license: MIT license: MIT
depends@unix: depends@unix:
- libiconv - libiconv
suggests@unix:
- xz
- zlib
headers: headers:
- libxml2 - libxml2
pkg-configs: pkg-configs:
- libxml-2.0 - libxml-2.0
suggests@unix:
- xz
- zlib

View File

@@ -11,14 +11,14 @@ nghttp2:
depends: depends:
- zlib - zlib
- openssl - openssl
suggests:
- libxml2
- nghttp3
- ngtcp2
- brotli
headers: headers:
- nghttp2 - nghttp2
pkg-configs: pkg-configs:
- libnghttp2 - libnghttp2
static-libs@unix: static-libs@unix:
- libnghttp2.a - libnghttp2.a
suggests:
- libxml2
- nghttp3
- ngtcp2
- brotli

View File

@@ -11,6 +11,9 @@ ngtcp2:
license: MIT license: MIT
depends: depends:
- openssl - openssl
suggests:
- nghttp3
- brotli
headers: headers:
- ngtcp2 - ngtcp2
pkg-configs: pkg-configs:
@@ -19,6 +22,3 @@ ngtcp2:
static-libs@unix: static-libs@unix:
- libngtcp2.a - libngtcp2.a
- libngtcp2_crypto_ossl.a - libngtcp2_crypto_ossl.a
suggests:
- nghttp3
- brotli

View File

@@ -0,0 +1,9 @@
pkg-config:
type: target
artifact:
source: 'https://dl.static-php.dev/static-php-cli/deps/pkg-config/pkg-config-0.29.2.tar.gz'
binary:
linux-x86_64: { type: ghrel, repo: static-php/static-php-cli-hosted, match: pkg-config-x86_64-linux-musl-1.2.5.txz, extract: { bin/pkg-config: '{pkg_root_path}/bin/pkg-config' } }
linux-aarch64: { type: ghrel, repo: static-php/static-php-cli-hosted, match: pkg-config-aarch64-linux-musl-1.2.5.txz, extract: { bin/pkg-config: '{pkg_root_path}/bin/pkg-config' } }
macos-x86_64: { type: ghrel, repo: static-php/static-php-cli-hosted, match: pkg-config-x86_64-darwin.txz, extract: { bin/pkg-config: '{pkg_root_path}/bin/pkg-config' } }
macos-aarch64: { type: ghrel, repo: static-php/static-php-cli-hosted, match: pkg-config-aarch64-darwin.txz, extract: { bin/pkg-config: '{pkg_root_path}/bin/pkg-config' } }

View File

@@ -0,0 +1,4 @@
zig:
type: target
artifact:
binary: custom

View File

@@ -13,6 +13,7 @@
"config": [ "config": [
"config/pkg.ext.json", "config/pkg.ext.json",
"config/pkg/lib", "config/pkg/lib",
"config/pkg/target",
"config/pkg.target.json" "config/pkg.target.json"
] ]
}, },

View File

@@ -56,7 +56,7 @@ class LintConfigCommand extends BaseCommand
public function packageSortKey(string $a, string $b): int public function packageSortKey(string $a, string $b): int
{ {
// sort by predefined order, other not matching keys go to the end alphabetically // sort by predefined order, other not matching keys go to the end alphabetically
$order = ['type', 'artifact']; $order = ['type', 'artifact', 'depends', 'suggests', 'frameworks'];
// Handle suffix patterns (e.g., 'depends@unix', 'static-libs@windows') // Handle suffix patterns (e.g., 'depends@unix', 'static-libs@windows')
$base_a = preg_replace('/@(unix|windows|macos|linux|freebsd|bsd)$/', '', $a); $base_a = preg_replace('/@(unix|windows|macos|linux|freebsd|bsd)$/', '', $a);

View File

@@ -27,25 +27,25 @@ class LinuxMuslCheck
public static function optionalCheck(): bool public static function optionalCheck(): bool
{ {
$toolchain = ApplicationContext::get(ToolchainInterface::class); $toolchain = ApplicationContext::get(ToolchainInterface::class);
return $toolchain instanceof MuslToolchain || $toolchain instanceof ZigToolchain && !LinuxUtil::isMuslDist(); return $toolchain instanceof MuslToolchain || $toolchain instanceof ZigToolchain && !LinuxUtil::isMuslDist() && !str_contains(getenv('SPC_TARGET') ?: '', 'gnu');
} }
/** @noinspection PhpUnused */ /** @noinspection PhpUnused */
#[CheckItem('if musl-wrapper is installed', limit_os: 'Linux', level: 800)] #[CheckItem('if musl-wrapper is installed', limit_os: 'Linux', level: 800)]
public function checkMusl(): CheckResult public function checkMusl(): ?CheckResult
{ {
$musl_wrapper_lib = sprintf('/lib/ld-musl-%s.so.1', php_uname('m')); $musl_wrapper_lib = sprintf('/lib/ld-musl-%s.so.1', php_uname('m'));
if (file_exists($musl_wrapper_lib) && (file_exists('/usr/local/musl/lib/libc.a') || getenv('SPC_TOOLCHAIN') === ZigToolchain::class)) { if (file_exists($musl_wrapper_lib) && (file_exists('/usr/local/musl/lib/libc.a') || getenv('SPC_TOOLCHAIN') === ZigToolchain::class)) {
return CheckResult::ok(); return null;
} }
return CheckResult::fail('musl-wrapper is not installed on your system', 'fix-musl-wrapper'); return CheckResult::fail('musl-wrapper is not installed on your system', 'fix-musl-wrapper');
} }
#[CheckItem('if musl-cross-make is installed', limit_os: 'Linux', level: 799)] #[CheckItem('if musl-cross-make is installed', limit_os: 'Linux', level: 799)]
public function checkMuslCrossMake(): CheckResult public function checkMuslCrossMake(): ?CheckResult
{ {
if (getenv('SPC_TOOLCHAIN') === ZigToolchain::class && !LinuxUtil::isMuslDist()) { if (getenv('SPC_TOOLCHAIN') === ZigToolchain::class && !LinuxUtil::isMuslDist()) {
return CheckResult::ok(); return null;
} }
$arch = arch2gnu(php_uname('m')); $arch = arch2gnu(php_uname('m'));
$cross_compile_lib = "/usr/local/musl/{$arch}-linux-musl/lib/libc.a"; $cross_compile_lib = "/usr/local/musl/{$arch}-linux-musl/lib/libc.a";

View File

@@ -259,7 +259,7 @@ class PackageInstaller
if ($this->isBuildPackage($package)) { if ($this->isBuildPackage($package)) {
return $package->isInstalled(); return $package->isInstalled();
} }
if ($package instanceof LibraryPackage && $package->getArtifact()->shouldUseBinary()) { if ($package->getArtifact() !== null && $package->getArtifact()->shouldUseBinary()) {
$artifact = $package->getArtifact(); $artifact = $package->getArtifact();
return $artifact->isBinaryExtracted(); return $artifact->isBinaryExtracted();
} }

View File

@@ -18,10 +18,10 @@ class ClangNativeToolchain implements UnixToolchainInterface
{ {
public function initEnv(): void public function initEnv(): void
{ {
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CC=clang'); GlobalEnvManager::putenv('SPC_DEFAULT_CC=clang');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CXX=clang++'); GlobalEnvManager::putenv('SPC_DEFAULT_CXX=clang++');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=ar'); GlobalEnvManager::putenv('SPC_DEFAULT_AR=ar');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=ld'); GlobalEnvManager::putenv('SPC_DEFAULT_LD=ld');
} }
public function afterInit(): void public function afterInit(): void

View File

@@ -15,10 +15,10 @@ class GccNativeToolchain implements UnixToolchainInterface
{ {
public function initEnv(): void public function initEnv(): void
{ {
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CC=gcc'); GlobalEnvManager::putenv('SPC_DEFAULT_CC=gcc');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CXX=g++'); GlobalEnvManager::putenv('SPC_DEFAULT_CXX=g++');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=ar'); GlobalEnvManager::putenv('SPC_DEFAULT_AR=ar');
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=ld'); GlobalEnvManager::putenv('SPC_DEFAULT_LD=ld');
} }
public function afterInit(): void public function afterInit(): void

View File

@@ -14,10 +14,10 @@ class MuslToolchain implements UnixToolchainInterface
{ {
$arch = getenv('GNU_ARCH'); $arch = getenv('GNU_ARCH');
// Set environment variables for musl toolchain // Set environment variables for musl toolchain
GlobalEnvManager::putenv("SPC_LINUX_DEFAULT_CC={$arch}-linux-musl-gcc"); GlobalEnvManager::putenv("SPC_DEFAULT_CC={$arch}-linux-musl-gcc");
GlobalEnvManager::putenv("SPC_LINUX_DEFAULT_CXX={$arch}-linux-musl-g++"); GlobalEnvManager::putenv("SPC_DEFAULT_CXX={$arch}-linux-musl-g++");
GlobalEnvManager::putenv("SPC_LINUX_DEFAULT_AR={$arch}-linux-musl-ar"); GlobalEnvManager::putenv("SPC_DEFAULT_AR={$arch}-linux-musl-ar");
GlobalEnvManager::putenv("SPC_LINUX_DEFAULT_LD={$arch}-linux-musl-ld"); GlobalEnvManager::putenv("SPC_DEFAULT_LD={$arch}-linux-musl-ld");
GlobalEnvManager::addPathIfNotExists('/usr/local/musl/bin'); GlobalEnvManager::addPathIfNotExists('/usr/local/musl/bin');
GlobalEnvManager::addPathIfNotExists("/usr/local/musl/{$arch}-linux-musl/bin"); GlobalEnvManager::addPathIfNotExists("/usr/local/musl/{$arch}-linux-musl/bin");
@@ -40,7 +40,7 @@ class MuslToolchain implements UnixToolchainInterface
public function getCompilerInfo(): ?string public function getCompilerInfo(): ?string
{ {
$compiler = getenv('CC') ?: getenv('SPC_LINUX_DEFAULT_CC'); $compiler = getenv('CC') ?: getenv('SPC_DEFAULT_CC');
$version = shell(false)->execWithResult("{$compiler} --version", false); $version = shell(false)->execWithResult("{$compiler} --version", false);
$head = pathinfo($compiler, PATHINFO_BASENAME); $head = pathinfo($compiler, PATHINFO_BASENAME);
if ($version[0] === 0 && preg_match('/linux-musl-cc.*(\d+.\d+.\d+)/', $version[1][0], $match)) { if ($version[0] === 0 && preg_match('/linux-musl-cc.*(\d+.\d+.\d+)/', $version[1][0], $match)) {

View File

@@ -28,7 +28,12 @@ class PkgConfigUtil
]; ];
$found = null; $found = null;
foreach ($find_list as $file) { foreach ($find_list as $file) {
if (file_exists($file) && is_executable($file)) { $exists = file_exists($file);
$executable = is_executable($file);
if (!$exists) {
continue;
}
if (!$executable && chmod($file, 0755) || $executable) {
$found = $file; $found = $file;
break; break;
} }