diff --git a/config/pkg/target/pkg-config.yml b/config/pkg/target/pkg-config.yml deleted file mode 100644 index 9b6d1603..00000000 --- a/config/pkg/target/pkg-config.yml +++ /dev/null @@ -1,9 +0,0 @@ -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' } } diff --git a/config/pkg/target/zig.yml b/config/pkg/target/zig.yml deleted file mode 100644 index dda72b55..00000000 --- a/config/pkg/target/zig.yml +++ /dev/null @@ -1,4 +0,0 @@ -zig: - type: target - artifact: - binary: custom diff --git a/config/pkg/target/7za-win.yml b/config/pkg/tool/7za-win.yml similarity index 69% rename from config/pkg/target/7za-win.yml rename to config/pkg/tool/7za-win.yml index 351fad8c..c8d35bfe 100644 --- a/config/pkg/target/7za-win.yml +++ b/config/pkg/tool/7za-win.yml @@ -1,5 +1,9 @@ 7za-win: - type: target + type: tool artifact: binary: windows-x86_64: { type: url, url: 'https://dl.static-php.dev/v3/tools/7zip/7za.exe', extract: '{pkg_root_path}/bin/7za.exe' } + tool: + provides: + - 7za.exe + binary-subdir: bin diff --git a/config/pkg/target/go-win.yml b/config/pkg/tool/go-win.yml similarity index 68% rename from config/pkg/target/go-win.yml rename to config/pkg/tool/go-win.yml index 46c13f5f..a65b6f5a 100644 --- a/config/pkg/target/go-win.yml +++ b/config/pkg/tool/go-win.yml @@ -1,5 +1,5 @@ go-win: - type: target + type: tool artifact: binary: custom env: @@ -8,3 +8,8 @@ go-win: GOPATH: '{pkg_root_path}/go-win/go' path@windows: - '{pkg_root_path}/go-win/bin' + tool: + provides: + - go.exe + - gofmt.exe + binary-subdir: go-win/bin diff --git a/config/pkg/target/go-xcaddy.yml b/config/pkg/tool/go-xcaddy.yml similarity index 70% rename from config/pkg/target/go-xcaddy.yml rename to config/pkg/tool/go-xcaddy.yml index deafb37d..19c723a9 100644 --- a/config/pkg/target/go-xcaddy.yml +++ b/config/pkg/tool/go-xcaddy.yml @@ -1,5 +1,5 @@ go-xcaddy: - type: target + type: tool artifact: binary: custom env: @@ -8,5 +8,8 @@ go-xcaddy: GOPATH: '{pkg_root_path}/go-xcaddy/go' path@unix: - '{pkg_root_path}/go-xcaddy/bin' - static-bins: - - xcaddy + tool: + provides: + - go + - gofmt + binary-subdir: go-xcaddy/bin diff --git a/config/pkg/target/jom.yml b/config/pkg/tool/jom.yml similarity index 73% rename from config/pkg/target/jom.yml rename to config/pkg/tool/jom.yml index 70916bfd..fa98fcca 100644 --- a/config/pkg/target/jom.yml +++ b/config/pkg/tool/jom.yml @@ -1,7 +1,11 @@ jom: - type: target + type: tool artifact: binary: windows-x86_64: { type: url, url: 'https://download.qt.io/official_releases/jom/jom.zip', extract: '{pkg_root_path}/jom' } path@windows: - '{pkg_root_path}\jom' + tool: + provides: + - jom.exe + binary-subdir: jom diff --git a/config/pkg/target/nasm.yml b/config/pkg/tool/nasm.yml similarity index 72% rename from config/pkg/target/nasm.yml rename to config/pkg/tool/nasm.yml index 3e6d9e43..928adc2b 100644 --- a/config/pkg/target/nasm.yml +++ b/config/pkg/tool/nasm.yml @@ -1,5 +1,10 @@ nasm: - type: target + type: tool artifact: binary: windows-x86_64: { type: url, url: 'https://dl.static-php.dev/static-php-cli/deps/nasm/nasm-2.16.01-win64.zip', extract: { nasm.exe: '{pkg_root_path}/bin/nasm.exe', ndisasm.exe: '{pkg_root_path}/bin/ndisasm.exe' } } + tool: + provides: + - nasm.exe + - ndisasm.exe + binary-subdir: bin diff --git a/config/pkg/target/protoc.yml b/config/pkg/tool/protoc.yml similarity index 82% rename from config/pkg/target/protoc.yml rename to config/pkg/tool/protoc.yml index b45fb335..596dad19 100644 --- a/config/pkg/target/protoc.yml +++ b/config/pkg/tool/protoc.yml @@ -1,8 +1,12 @@ protoc: - type: target + type: tool artifact: binary: linux-x86_64: { type: ghrel, repo: protocolbuffers/protobuf, match: 'protoc-([0-9.]+)-linux-x86_64\.zip', extract: '{pkg_root_path}/protoc' } linux-aarch64: { type: ghrel, repo: protocolbuffers/protobuf, match: 'protoc-([0-9.]+)-linux-aarch_64\.zip', extract: '{pkg_root_path}/protoc' } path: - '{pkg_root_path}/protoc/bin' + tool: + provides: + - protoc + binary-subdir: protoc/bin diff --git a/config/pkg/target/strawberry-perl.yml b/config/pkg/tool/strawberry-perl.yml similarity index 72% rename from config/pkg/target/strawberry-perl.yml rename to config/pkg/tool/strawberry-perl.yml index 9e2e3187..d3587b4e 100644 --- a/config/pkg/target/strawberry-perl.yml +++ b/config/pkg/tool/strawberry-perl.yml @@ -1,5 +1,9 @@ strawberry-perl: - type: target + type: tool artifact: binary: windows-x86_64: { type: url, url: 'https://github.com/StrawberryPerl/Perl-Dist-Strawberry/releases/download/SP_5380_5361/strawberry-perl-5.38.0.1-64bit-portable.zip', extract: '{pkg_root_path}/strawberry-perl' } + tool: + provides: + - perl.exe + binary-subdir: strawberry-perl/perl/bin diff --git a/config/pkg/target/upx.yml b/config/pkg/tool/upx.yml similarity index 79% rename from config/pkg/target/upx.yml rename to config/pkg/tool/upx.yml index 29506c39..9530b1eb 100644 --- a/config/pkg/target/upx.yml +++ b/config/pkg/tool/upx.yml @@ -1,7 +1,13 @@ upx: - type: target + type: tool artifact: binary: linux-x86_64: { type: ghrel, repo: upx/upx, match: upx.+-amd64_linux\.tar\.xz, extract: { upx: '{pkg_root_path}/bin/upx' } } linux-aarch64: { type: ghrel, repo: upx/upx, match: upx.+-arm64_linux\.tar\.xz, extract: { upx: '{pkg_root_path}/bin/upx' } } windows-x86_64: { type: ghrel, repo: upx/upx, match: upx.+-win64\.zip, extract: { upx.exe: '{pkg_root_path}/bin/upx.exe' } } + tool: + provides: + - upx + provides@windows: + - upx.exe + binary-subdir: bin diff --git a/config/pkg/target/vswhere.yml b/config/pkg/tool/vswhere.yml similarity index 71% rename from config/pkg/target/vswhere.yml rename to config/pkg/tool/vswhere.yml index d7f8670c..f4253376 100644 --- a/config/pkg/target/vswhere.yml +++ b/config/pkg/tool/vswhere.yml @@ -1,5 +1,9 @@ vswhere: - type: target + type: tool artifact: binary: windows-x86_64: { type: url, url: 'https://github.com/microsoft/vswhere/releases/download/3.1.7/vswhere.exe', extract: '{pkg_root_path}/bin/vswhere.exe' } + tool: + provides: + - vswhere.exe + binary-subdir: bin diff --git a/config/pkg/tool/zig.yml b/config/pkg/tool/zig.yml new file mode 100644 index 00000000..0f243ebf --- /dev/null +++ b/config/pkg/tool/zig.yml @@ -0,0 +1,14 @@ +zig: + type: tool + artifact: + binary: custom + tool: + provides: + - zig + - zig-cc + - zig-c++ + - zig-ar + - zig-ld.lld + - zig-ranlib + - zig-objcopy + binary-subdir: zig diff --git a/src/Package/Target/pkgconfig.php b/src/Package/Target/pkgconfig.php deleted file mode 100644 index aa75fc88..00000000 --- a/src/Package/Target/pkgconfig.php +++ /dev/null @@ -1,45 +0,0 @@ -appendEnv([ - 'CFLAGS' => '-Wimplicit-function-declaration -Wno-int-conversion', - 'LDFLAGS' => $toolchain->isStatic() ? '--static' : '', - ]) - ->configure( - '--with-internal-glib', - '--disable-host-tool', - '--without-sysroot', - '--without-system-include-path', - '--without-system-library-path', - '--without-pc-path', - ) - ->make(with_install: 'install-exec'); - - shell()->exec("strip {$package->getBinDir()}/pkg-config"); - } -} diff --git a/src/StaticPHP/Package/ToolVersionRegistry.php b/src/StaticPHP/Package/ToolVersionRegistry.php new file mode 100644 index 00000000..98564db5 --- /dev/null +++ b/src/StaticPHP/Package/ToolVersionRegistry.php @@ -0,0 +1,79 @@ + */ + private static ?array $data = null; + + /** + * Get the recorded installed version for a tool, or null if never recorded (not a tool + * package, not installed yet, or the artifact doesn't expose a version). + */ + public static function get(string $tool_name): ?string + { + self::load(); + return self::$data[$tool_name]['version'] ?? null; + } + + /** + * Record the version currently installed for a tool. Called after a tool package's binary + * has been (re-)installed, regardless of whether extraction actually ran (keeps the registry + * self-healing if it was deleted separately from the installed files). + */ + public static function record(string $tool_name, ?string $version): void + { + self::load(); + self::$data[$tool_name] = [ + 'version' => $version, + 'platform' => SystemTarget::getCurrentPlatformString(), + 'installed_at' => date('c'), + ]; + self::save(); + } + + private static function getPath(): string + { + return PKG_ROOT_PATH . '/.spc-tool-versions.json'; + } + + private static function load(): void + { + if (self::$data !== null) { + return; + } + $path = self::getPath(); + if (!file_exists($path)) { + self::$data = []; + return; + } + $content = file_get_contents($path); + self::$data = is_string($content) ? (json_decode($content, true) ?: []) : []; + } + + private static function save(): void + { + $path = self::getPath(); + $dir = dirname($path); + if (!is_dir($dir)) { + @mkdir($dir, 0755, true); + } + file_put_contents($path, json_encode(self::$data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); + } +}