Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ A tool for building and packaging PHP and shared extensions with static-php-cli.

1. Clone the repository:
```
git clone https://github.com/static-php/spc-packages.git
git clone https://github.com/static-php/packages.git
cd spc-packages
```

Expand Down
32 changes: 28 additions & 4 deletions bin/createrepo_static
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,36 @@ def parse_rpm_info(filename):
stream = f"8.{php_patch[-1]}"
return name, version, release, arch, stream

# Match static-php
match_static = re.match(r'(static-php)-(?P<version>\d+)-(?P<release>\d+)\.(?P<arch>[^.]+)\.rpm', basename)
if match_static:
name = match_static.group(1)
version = match_static.group("version")
release = match_static.group("release")
arch = match_static.group("arch")
stream = "common"
return name, version, release, arch, stream

return None

def build_module_structure(rpm_map, platform):
documents = []
timestamp = int(datetime.now(timezone.utc).strftime('%Y%m%d'))

# Collect common artifacts (static-php)
common_artifacts = []
if "common" in rpm_map:
for pkg in rpm_map["common"]:
info = parse_rpm_info(pkg)
if info:
name, version, release, arch, _ = info
common_artifacts.append(f"{name}-0:{version}-{release}.{arch}")

for stream, pkg_list in sorted(rpm_map.items()):
artifacts = []
if stream == "common":
continue

artifacts = common_artifacts.copy()

for pkg in sorted(pkg_list):
info = parse_rpm_info(pkg)
Expand Down Expand Up @@ -128,10 +150,12 @@ for rpm in rpm_files:
# Build modules.yaml
modules_yaml = build_module_structure(rpm_map, platform)

# Determine highest stream for default
# Determine highest stream for default (exclude "common")
if rpm_map:
default_stream = sorted(rpm_map.keys())[-1] # Use highest PHP version
modules_yaml.append(build_defaults_document(default_stream))
streams = [s for s in rpm_map.keys() if s != "common"]
if streams:
default_stream = sorted(streams)[-1]
modules_yaml.append(build_defaults_document(default_stream))

output_path = os.path.join(os.getcwd(), "modules.yaml")
with open(output_path, "w") as f:
Expand Down
49 changes: 45 additions & 4 deletions bin/spp
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#!/usr/bin/env php
<?php

// Main entrypoint for SPC Packages
// Uses Symfony Console for command-line parsing

// Define constants
define('BASE_PATH', dirname(__DIR__));
const INI_PATH = BASE_PATH . '/src/ini';
const DIST_PATH = BASE_PATH . '/dist';
const DIST_RPM_PATH = DIST_PATH . '/rpm';
const DIST_DEB_PATH = DIST_PATH . '/deb';
const DIST_APK_PATH = DIST_PATH . '/apk';
define('TEMP_DIR', sys_get_temp_dir() . '/spc-packages');


Expand Down Expand Up @@ -74,5 +72,48 @@ function getLibdir(): string

function getConfdir(): string
{
return '/etc/' . \staticphp\step\CreatePackages::getPrefix();
// Get the prefix which is package-type aware (php-zts for RPM, php-zts8.3 for DEB, php-zts83 for APK)
$prefix = \staticphp\step\CreatePackages::getPrefix();
return '/etc/' . $prefix;
}

function getModuledir(): string
{
// Get the prefix which is package-type aware
$prefix = \staticphp\step\CreatePackages::getPrefix();
return getLibdir() . '/' . $prefix . '/modules';
}

function getPhpLibdir(): string
{
// Get the prefix which is package-type aware
$prefix = \staticphp\step\CreatePackages::getPrefix();
return getLibdir() . '/' . $prefix;
}

function getBinarySuffix(): string
{
// Get the suffix for binaries based on package type
// RPM: -zts, DEB: -zts8.3, APK: -zts83
$prefix = \staticphp\step\CreatePackages::getPrefix();

// Extract the version suffix from the prefix
// php-zts -> -zts
// php-zts8.3 -> -zts8.3
// php-zts83 -> -zts83
return str_replace('php', '', $prefix);
}

function getVarLibdir(): string
{
// Get /var/lib/{prefix} path
$prefix = \staticphp\step\CreatePackages::getPrefix();
return '/var/lib/' . $prefix;
}

function getSharedir(): string
{
// Get /usr/share/{prefix} path
$prefix = \staticphp\step\CreatePackages::getPrefix();
return '/usr/share/' . $prefix;
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
"prefer-stable": true,
"require": {
"php": ">=8.4",
"ext-yaml": "*",
"ext-zlib": "*",
"crazywhalecc/static-php-cli": "dev-henderkes-patch-1",
"laravel/helpers": "^1.7",
"ext-zlib": "*",
"twig/twig": "^3.0"
},
"require-dev": {
Expand Down
18 changes: 9 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions config/static-php.repo
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ baseurl=https://rpm.henderkes.com/\$basearch/el\$releasever
enabled=1
gpgcheck=1
gpgkey=https://key.henderkes.com/static-php.gpg
excludepkgs=*-debuginfo

[static-php-debuginfo]
name=Static PHP repository - Debuginfo
baseurl=https://rpm.henderkes.com/$basearch/el$releasever
enabled=0
gpgcheck=1
gpgkey=https://key.henderkes.com/static-php.asc
includepkgs=*-debuginfo
8 changes: 2 additions & 6 deletions config/templates/craft.yml.twig
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ download-options:
no-alt: false
shallow-clone: true
{% if php_version == '8.5' %}
ignore-cache-sources: 'php-src,swoole,apcu,pdo_sqlsrv'
custom-url:
- 'pdo_sqlsrv:https://github.com/stancl/msphpsql/archive/refs/heads/push-posxmnwpksqv.tar.gz'
- 'swoole:https://github.com/swoole/swoole-src/archive/eb726b72b6caf4a86bf0af2d29fca40b56d352e9.tar.gz'
- 'amqp:https://github.com/php-amqp/php-amqp/archive/refs/pull/595/merge.tar.gz'
ignore-cache-sources: ''
{% else -%}
ignore-cache-sources: 'php-src'
{% endif -%}
Expand Down Expand Up @@ -87,7 +83,7 @@ extra-env:
{% else -%}
SPC_TARGET: '{{ target }}'
{% endif -%}
EXTENSION_DIR: "{{ is_rhel ? '/usr/lib64/php-zts/modules' : '/usr/lib/php-zts/modules' }}"
EXTENSION_DIR: "{{ moduledir }}"
SPC_CMD_VAR_PHP_EMBED_TYPE: 'shared'
SPC_MICRO_PATCHES:
SPC_DEFAULT_C_FLAGS: "{{ cflags }}"
Expand Down
2 changes: 1 addition & 1 deletion src/Command/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)

protected function createDirectories(): void
{
$paths = [BUILD_ROOT_PATH, BUILD_BIN_PATH, BUILD_LIB_PATH, BUILD_MODULES_PATH, DIST_PATH, DIST_RPM_PATH, DIST_DEB_PATH];
$paths = [BUILD_ROOT_PATH, BUILD_BIN_PATH, BUILD_LIB_PATH, BUILD_MODULES_PATH, DIST_PATH, DIST_RPM_PATH, DIST_DEB_PATH, DIST_APK_PATH];
foreach ($paths as $path) {
if (!is_dir($path) && !mkdir($path, 0755, true) && !is_dir($path)) {
throw new \RuntimeException("Failed to create directory: " . $path);
Expand Down
29 changes: 25 additions & 4 deletions src/extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,24 @@ public function getFpmConfig(): array

$depends = array_merge($depends, $ordered);

$versionedConflicts = CreatePackages::getVersionedConflicts('-' . $this->name);
return [
'config-files' => [
getConfdir() . '/conf.d/' . $this->prefix . $this->name . '.ini',
],
'depends' => $depends,
'provides' => [
'php-zts-' . $this->name,
],
'replaces' => $versionedConflicts,
'conflicts' => $versionedConflicts,
'files' => [
...($this->getIniPath() ?
[$this->getIniPath() => getConfdir() . '/conf.d/' . $this->prefix . $this->name . '.ini']
: []
),
...($this->isSharedExtension() ?
[BUILD_MODULES_PATH . '/' . $this->name . '.so' => getLibdir() . '/' . CreatePackages::getPrefix() . '/modules/' . $this->name . '.so']
[BUILD_MODULES_PATH . '/' . $this->name . '.so' => getModuledir() . '/' . $this->name . '.so']
: []
),
]
Expand All @@ -179,9 +185,24 @@ protected function getIniPath(): ?string
}
$tempIniPath = TEMP_DIR . '/' . $this->prefix . $this->name . '.ini';
$iniContent = file_get_contents($iniPath);

// Get the dynamic prefix for path replacements
$prefix = CreatePackages::getPrefix();

// Replace extension directives and versioned paths
$iniContent = str_replace(
[';extension=' . $this->name, ';zend_extension=' . $this->name],
['extension=' . $this->name, 'zend_extension=' . $this->name],
[
';extension=' . $this->name,
';zend_extension=' . $this->name,
'/usr/share/php-zts/',
'/usr/local/share/php-zts/',
],
[
'extension=' . $this->name,
'zend_extension=' . $this->name,
'/usr/share/' . $prefix . '/',
'/usr/local/share/' . $prefix . '/',
],
$iniContent
);
file_put_contents($tempIniPath, $iniContent);
Expand Down Expand Up @@ -209,7 +230,7 @@ public function getDebuginfoFpmConfig(): array
if (!file_exists($src)) {
return [];
}
$targetSo = getLibdir() . '/' . CreatePackages::getPrefix() . '/modules/' . $this->name . '.so';
$targetSo = getModuledir() . '/' . $this->name . '.so';
$target = '/usr/lib/debug' . $targetSo . '.debug';
return [
'depends' => [CreatePackages::getPrefix() . '-' . $this->name],
Expand Down
10 changes: 8 additions & 2 deletions src/package/cgi.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ public function getName(): string

public function getFpmConfig(): array
{
$versionedConflicts = CreatePackages::getVersionedConflicts('-cgi');
return [
'depends' => [
CreatePackages::getPrefix() . '-cli',
],
'provides' => [
'php-zts-cgi',
],
'replaces' => $versionedConflicts,
'conflicts' => $versionedConflicts,
'files' => [
BUILD_BIN_PATH . '/php-cgi' => '/usr/bin/php-cgi-zts',
BUILD_BIN_PATH . '/php-cgi' => '/usr/bin/php-cgi' . getBinarySuffix(),
]
];
}
Expand All @@ -38,7 +44,7 @@ public function getDebuginfoFpmConfig(): array
return [
'depends' => [CreatePackages::getPrefix() . '-cgi'],
'files' => [
$src => '/usr/lib/debug/usr/bin/php-cgi-zts.debug',
$src => '/usr/lib/debug/usr/bin/php-cgi' . getBinarySuffix() . '.debug',
],
];
}
Expand Down
Loading