Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4f76942
toolchain fixes forward port from v2-pgo
henderkes May 10, 2026
6e32672
better deduplicate_flags
henderkes May 11, 2026
efdd2a7
update libraries to honour user flags
henderkes May 11, 2026
743934d
use resolved dependency tree instead of asking for with_suggests ever…
henderkes May 11, 2026
7e6e9d8
add pgo capabilities v3 style
henderkes May 11, 2026
bfaa7eb
Merge remote-tracking branch 'origin/v3' into feat/pgo-v3
henderkes May 11, 2026
a585359
reset registry
henderkes May 11, 2026
4172508
use {pkg_root_path} for packages, otherwise containers get confused w…
henderkes May 12, 2026
270e2d6
cant reset it because of the same reason x(
henderkes May 12, 2026
c1c34d8
trust filesystem, not downloads
henderkes May 12, 2026
8453f69
fix BUILD_CC=cc workaround root cause (minijit trips zig default unde…
henderkes May 12, 2026
57ef042
fix phpunit failure
henderkes May 12, 2026
defd50f
wrong exception type
henderkes May 12, 2026
814014e
array
henderkes May 12, 2026
2415b7d
we don't need this anymore
henderkes May 12, 2026
4754faf
also build curl exe on windows
henderkes May 12, 2026
445c0b3
don't add fno-sanitize=undefined for library builds
henderkes May 12, 2026
9addbe2
oops
henderkes May 12, 2026
b880ef7
allow * stage to subscribe to everything
henderkes May 12, 2026
db794bf
strange shit
henderkes May 12, 2026
09de4c9
drop ldflags fron watcher-c
henderkes May 15, 2026
6fda358
--build-frankenphp didn't actually build frankenphp
henderkes May 15, 2026
a88e426
clean cgo cache before rebuilding frankenphp (reports wrong version f…
henderkes May 15, 2026
70e717a
fix version reevaluating regression from v2
henderkes May 15, 2026
1707d21
don't extract local sources
henderkes May 15, 2026
4b19f4e
forward port #1138
henderkes May 15, 2026
07aae79
forward port #1142
henderkes May 16, 2026
19d1379
better cross compile compatibility
henderkes May 17, 2026
697040b
Trim base namespace for registry
crazywhalecc May 18, 2026
fdc75cb
Allow vendor mode loading default registry file
crazywhalecc May 18, 2026
ce70c0d
Register artifacts dynamically if not already initialized
crazywhalecc May 18, 2026
f27ec77
Refactor clang runtime bits support for zig integration
crazywhalecc May 18, 2026
32da708
Change gettext-win base to 0.18 (master is 1.0 now)
crazywhalecc May 18, 2026
3eca044
Whoops
crazywhalecc May 18, 2026
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
8 changes: 7 additions & 1 deletion config/env.ini
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ SPC_TARGET=${GNU_ARCH}-linux-musl
CC=${SPC_DEFAULT_CC}
CXX=${SPC_DEFAULT_CXX}
AR=${SPC_DEFAULT_AR}
RANLIB=${SPC_DEFAULT_RANLIB}
LD=${SPC_DEFAULT_LD}
; default compiler flags, used in CMake toolchain file, openssl and pkg-config build
SPC_DEFAULT_CFLAGS="-fPIC -O3 -pipe -fno-plt -fno-semantic-interposition -fstack-clash-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -ffunction-sections -fdata-sections"
SPC_DEFAULT_CFLAGS="-fPIC -O3 -pipe -fno-plt -fno-semantic-interposition -fstack-clash-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -ffunction-sections -fdata-sections -Wno-unused-command-line-argument"
SPC_DEFAULT_CXXFLAGS="${SPC_DEFAULT_CFLAGS}"
SPC_DEFAULT_LDFLAGS="-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -Wl,-z,noexecstack -Wl,--gc-sections"
; upx executable path
Expand All @@ -125,6 +126,8 @@ SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE
SPC_CMD_VAR_PHP_MAKE_EXTRA_CXXFLAGS="-g -fstack-protector-strong -fno-ident -fPIE -fvisibility=hidden -fvisibility-inlines-hidden ${SPC_DEFAULT_CXXFLAGS}"
; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS=""
; EXTRA_LDFLAGS_PROGRAM for `make` php; appended only to SAPI executable links (cli/fpm/cgi/micro/embed). Used by PGO to inject -fprofile-use= without polluting libphp.{a,so}.
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM=""

; optional, path to openssl conf. This affects where openssl will look for the default CA.
; default on Debian/Alpine: /etc/ssl, default on RHEL: /etc/pki/tls
Expand All @@ -140,6 +143,7 @@ SPC_USE_LLVM=system
CC=${SPC_DEFAULT_CC}
CXX=${SPC_DEFAULT_CXX}
AR=${SPC_DEFAULT_AR}
RANLIB=${SPC_DEFAULT_RANLIB}
LD=${SPC_DEFAULT_LD}
; default compiler flags, used in CMake toolchain file, openssl and pkg-config build
SPC_DEFAULT_CFLAGS="--target=${MAC_ARCH}-apple-darwin -O3 -fno-plt -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -ffunction-sections -fdata-sections"
Expand All @@ -163,5 +167,7 @@ SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fpic -fpie -fvis
SPC_CMD_VAR_PHP_MAKE_EXTRA_CXXFLAGS="-g -fstack-protector-strong -fno-ident -fpie -fvisibility=hidden -fvisibility-inlines-hidden -Werror=unknown-warning-option ${SPC_DEFAULT_CXXFLAGS}"
; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.dylib
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS=""
; EXTRA_LDFLAGS_PROGRAM for `make` php; appended only to SAPI executable links (cli/fpm/cgi/micro/embed). Used by PGO to inject -fprofile-use= without polluting libphp.{a,dylib}.
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM=""
; minimum compatible macOS version (LLVM vars, availability not guaranteed)
MACOSX_DEPLOYMENT_TARGET=12.0
1 change: 1 addition & 0 deletions config/pkg/ext/builtin-extensions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ ext-password-argon2:
type: php-extension
depends:
- libargon2
suggests:
- ext-openssl
php-extension:
os:
Expand Down
2 changes: 1 addition & 1 deletion config/pkg/lib/gettext-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ gettext-win:
source:
type: git
url: 'https://github.com/winlibs/gettext.git'
rev: master
rev: '0.18'
static-libs@windows:
- libintl_a.lib
4 changes: 4 additions & 0 deletions config/pkg/target/clang-runtime-bits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
clang-runtime-bits:
type: target
artifact:
binary: custom
163 changes: 163 additions & 0 deletions src/Package/Artifact/clang_runtime_bits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?php

declare(strict_types=1);

namespace Package\Artifact;

use StaticPHP\Artifact\ArtifactDownloader;
use StaticPHP\Artifact\Downloader\DownloadResult;
use StaticPHP\Artifact\Downloader\Type\CheckUpdateResult;
use StaticPHP\Attribute\Artifact\AfterBinaryExtract;
use StaticPHP\Attribute\Artifact\CustomBinary;
use StaticPHP\Attribute\Artifact\CustomBinaryCheckUpdate;
use StaticPHP\Exception\DownloaderException;

class clang_runtime_bits
{
#[CustomBinary('clang-runtime-bits', [
'linux-x86_64',
'linux-aarch64',
])]
public function downBinary(ArtifactDownloader $downloader): DownloadResult
{
$llvmVersion = $this->detectZigLlvmVersion()
?? throw new DownloaderException('Could not detect bundled clang version from zig cc --version; ensure zig is installed');
$tarball = "compiler-rt-{$llvmVersion}.src.tar.xz";
$url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-{$llvmVersion}/{$tarball}";
$tarballPath = DOWNLOAD_PATH . '/' . $tarball;
default_shell()->executeCurlDownload($url, $tarballPath, retries: $downloader->getRetry());
return DownloadResult::archive($tarball, ['url' => $url, 'version' => $llvmVersion], extract: '{pkg_root_path}/clang-runtime-bits', verified: false, version: $llvmVersion);
}

#[CustomBinaryCheckUpdate('clang-runtime-bits', [
'linux-x86_64',
'linux-aarch64',
])]
public function checkUpdateBinary(?string $old_version, ArtifactDownloader $downloader): CheckUpdateResult
{
$llvmVersion = $this->detectZigLlvmVersion()
?? throw new DownloaderException('Could not detect bundled clang version from zig cc --version; ensure zig is installed');
return new CheckUpdateResult(
old: $old_version,
new: $llvmVersion,
needUpdate: $old_version === null || $llvmVersion !== $old_version,
);
}

#[AfterBinaryExtract('clang-runtime-bits', [
'linux-x86_64',
'linux-aarch64',
])]
public function postExtract(string $target_path): void
{
$zig = PKG_ROOT_PATH . '/zig/zig';
$libDir = PKG_ROOT_PATH . '/zig/lib';
$profileLib = "{$libDir}/libclang_rt.profile.a";
$crtBegin = "{$libDir}/clang_rt.crtbegin.o";
$crtEnd = "{$libDir}/clang_rt.crtend.o";
if (file_exists($profileLib) && file_exists($crtBegin) && file_exists($crtEnd)) {
return;
}

$llvmVersion = $this->detectZigLlvmVersion();
if ($llvmVersion === null) {
logger()->warning('[clang-runtime-bits] could not detect bundled clang version; skipping runtime bit build (PGO + shared libs without __dso_handle will fail to link)');
return;
}
logger()->info("Building clang runtime bits for LLVM {$llvmVersion} (zig's bundled clang)");

f_mkdir($libDir, recursive: true);
if (!file_exists($profileLib)) {
$this->buildProfileRuntime($zig, $target_path, $profileLib);
}
if (!file_exists($crtBegin) || !file_exists($crtEnd)) {
$this->buildCrtObjects($zig, $target_path, $crtBegin, $crtEnd);
}
}

private function buildProfileRuntime(string $zig, string $srcRoot, string $libPath): void
{
$profileSrc = "{$srcRoot}/lib/profile";
$profileInc = "{$srcRoot}/include";
if (!is_dir($profileSrc)) {
logger()->warning("[clang-runtime-bits] profile src dir missing at {$profileSrc} — PGO will not work");
return;
}
$sources = array_merge(
glob("{$profileSrc}/*.c") ?: [],
glob("{$profileSrc}/*.cpp") ?: []
);
// Keep Linux-only compilation units; the others bring in OS-specific headers
// we can't satisfy without their respective SDKs.
$skip = ['/PlatformAIX', '/PlatformDarwin', '/PlatformFuchsia', '/PlatformOther', '/PlatformWindows', '/WindowsMMap'];
$sources = array_filter($sources, function ($f) use ($skip) {
foreach ($skip as $s) {
if (str_contains($f, $s)) {
return false;
}
}
return true;
});

$objDir = "{$srcRoot}/obj-profile";
f_mkdir($objDir, recursive: true);
$cflags = '-c -O2 -fPIC -fvisibility=hidden ' .
'-I' . escapeshellarg($profileInc) . ' ' .
'-DCOMPILER_RT_HAS_ATOMICS=1 -DCOMPILER_RT_HAS_FCNTL_LCK=1 -DCOMPILER_RT_HAS_UNAME=1';
$objs = [];
foreach ($sources as $src) {
$obj = $objDir . '/' . pathinfo($src, PATHINFO_FILENAME) . '.o';
$cmd = escapeshellarg($zig) . ' cc ' . $cflags . ' -o ' . escapeshellarg($obj) . ' ' . escapeshellarg($src) . ' 2>&1';
if (!$this->runZigCmd($cmd, $obj, "failed to compile {$src}")) {
return;
}
$objs[] = $obj;
}
$arCmd = escapeshellarg($zig) . ' ar rcs ' . escapeshellarg($libPath) . ' ' . implode(' ', array_map('escapeshellarg', $objs)) . ' 2>&1';
if (!$this->runZigCmd($arCmd, $libPath, 'zig ar failed')) {
return;
}
logger()->info('[clang-runtime-bits] libclang_rt.profile.a installed (' . filesize($libPath) . ' bytes)');
}

private function buildCrtObjects(string $zig, string $srcRoot, string $crtBegin, string $crtEnd): void
{
$beginSrc = "{$srcRoot}/lib/builtins/crtbegin.c";
$endSrc = "{$srcRoot}/lib/builtins/crtend.c";
if (!is_file($beginSrc) || !is_file($endSrc)) {
logger()->error("[clang-runtime-bits] crtbegin/crtend source missing under {$srcRoot}/lib/builtins — shared libs will lack __dso_handle");
return;
}
$cflags = '-c -O2 -fPIC -fvisibility=hidden -DCRT_HAS_INITFINI_ARRAY';
foreach ([[$beginSrc, $crtBegin], [$endSrc, $crtEnd]] as [$src, $dst]) {
$cmd = escapeshellarg($zig) . ' cc ' . $cflags . ' -o ' . escapeshellarg($dst) . ' ' . escapeshellarg($src) . ' 2>&1';
if (!$this->runZigCmd($cmd, $dst, "failed to compile {$src}")) {
return;
}
}
logger()->info('[clang-runtime-bits] clang_rt.crtbegin.o + clang_rt.crtend.o installed (' . filesize($crtBegin) . ' + ' . filesize($crtEnd) . ' bytes)');
}

private function runZigCmd(string $cmd, string $dst, string $errPrefix): bool
{
exec($cmd, $out, $rc);
if ($rc !== 0 || !is_file($dst)) {
logger()->warning("[clang-runtime-bits] {$errPrefix}: " . implode("\n", $out));
return false;
}
return true;
}

private function detectZigLlvmVersion(): ?string
{
$zig = PKG_ROOT_PATH . '/zig/zig';
if (!is_file($zig)) {
return null;
}
$verLine = trim((string) shell_exec(escapeshellarg($zig) . ' cc --version 2>/dev/null'));
if (!preg_match('/clang version (\d+\.\d+\.\d+)/', $verLine, $m)) {
return null;
}
return $m[1];
}
}
4 changes: 1 addition & 3 deletions src/Package/Artifact/go_win.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class go_win
])]
public function downBinary(ArtifactDownloader $downloader): DownloadResult
{
$pkgroot = PKG_ROOT_PATH;

// get version
[$version] = explode("\n", default_shell()->executeCurl('https://go.dev/VERSION?m=text', retries: $downloader->getRetry()) ?: '');
if ($version === '') {
Expand Down Expand Up @@ -52,7 +50,7 @@ public function downBinary(ArtifactDownloader $downloader): DownloadResult
throw new DownloaderException("Hash mismatch for downloaded go-win binary. Expected {$hash}, got {$file_hash}");
}

return DownloadResult::archive(basename($path), ['url' => $url, 'version' => $version], extract: "{$pkgroot}/go-win", verified: true, version: $version);
return DownloadResult::archive(basename($path), ['url' => $url, 'version' => $version], extract: '{pkg_root_path}/go-win', verified: true, version: $version);
}

#[CustomBinaryCheckUpdate('go-win', ['windows-x86_64'])]
Expand Down
5 changes: 2 additions & 3 deletions src/Package/Artifact/go_xcaddy.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class go_xcaddy
])]
public function downBinary(ArtifactDownloader $downloader): DownloadResult
{
$pkgroot = PKG_ROOT_PATH;
$name = SystemTarget::getCurrentPlatformString();
$arch = match (explode('-', $name)[1]) {
'x86_64' => 'amd64',
Expand Down Expand Up @@ -64,7 +63,7 @@ public function downBinary(ArtifactDownloader $downloader): DownloadResult
if ($file_hash !== $hash) {
throw new DownloaderException("Hash mismatch for downloaded go-xcaddy binary. Expected {$hash}, got {$file_hash}");
}
return DownloadResult::archive(basename($path), ['url' => $url, 'version' => $version], extract: "{$pkgroot}/go-xcaddy", verified: true, version: $version);
return DownloadResult::archive(basename($path), ['url' => $url, 'version' => $version], extract: '{pkg_root_path}/go-xcaddy', verified: true, version: $version);
}

#[CustomBinaryCheckUpdate('go-xcaddy', [
Expand Down Expand Up @@ -109,7 +108,7 @@ public function afterExtract(string $target_path): void
'GOROOT' => "{$target_path}",
'GOBIN' => "{$target_path}/bin",
'GOPATH' => "{$target_path}/go",
])->exec('CC=cc go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest');
])->exec('CGO_ENABLED=0 go install github.com/caddyserver/xcaddy/cmd/xcaddy@master');
GlobalEnvManager::addPathIfNotExists("{$target_path}/bin");
}
}
2 changes: 1 addition & 1 deletion src/Package/Artifact/rust.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function downBinary(ArtifactDownloader $downloader): DownloadResult
$download_url = "https://static.rust-lang.org/dist/rust-{$latest_version}-{$arch}-unknown-linux-{$distro}.tar.xz";
$path = DOWNLOAD_PATH . DIRECTORY_SEPARATOR . basename($download_url);
default_shell()->executeCurlDownload($download_url, $path, retries: $downloader->getRetry());
return DownloadResult::archive(basename($path), ['url' => $download_url, 'version' => $latest_version], extract: PKG_ROOT_PATH . '/rust-install', verified: false, version: $latest_version);
return DownloadResult::archive(basename($path), ['url' => $download_url, 'version' => $latest_version], extract: '{pkg_root_path}/rust-install', verified: false, version: $latest_version);
}

#[CustomBinaryCheckUpdate('rust', [
Expand Down
2 changes: 1 addition & 1 deletion src/Package/Artifact/zig.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function downBinary(ArtifactDownloader $downloader): DownloadResult
if ($file_hash !== $sha256) {
throw new DownloaderException("Hash mismatch for downloaded Zig binary. Expected {$sha256}, got {$file_hash}");
}
return DownloadResult::archive(basename($path), ['url' => $url, 'version' => $latest_version], extract: PKG_ROOT_PATH . '/zig', verified: true, version: $latest_version);
return DownloadResult::archive(basename($path), ['url' => $url, 'version' => $latest_version], extract: '{pkg_root_path}/zig', verified: true, version: $latest_version);
}

#[CustomBinaryCheckUpdate('zig', [
Expand Down
6 changes: 5 additions & 1 deletion src/Package/Extension/opcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public function getUnixConfigureArg(bool $shared, PackageBuilder $builder): stri
) {
$opcache_jit = ' --disable-opcache-jit';
}
return '--enable-opcache' . ($shared ? '=shared' : '') . $opcache_jit;
// PHP 8.5+ has opcache built-in
if ($phpVersionID < 80500) {
return '--enable-opcache' . ($shared ? '=shared' : '') . $opcache_jit;
}
return trim($opcache_jit);
}
}
2 changes: 1 addition & 1 deletion src/Package/Extension/password_argon2.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function runSmokeTestCliUnix(): void
#[CustomPhpConfigureArg('Darwin')]
public function getConfigureArg(PackageInstaller $installer, PackageBuilder $builder): string
{
if ($installer->getLibraryPackage('openssl') !== null) {
if ($installer->getPhpExtensionPackage('openssl')?->isBuildStatic() || $this->isBuildShared()) {
if (php::getPHPVersionID() >= 80500 || (php::getPHPVersionID() >= 80400 && !$builder->getOption('enable-zts'))) {
return '--without-password-argon2'; // use --with-openssl-argon2 in openssl extension instead
}
Expand Down
2 changes: 1 addition & 1 deletion src/Package/Extension/pgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class pgsql extends PhpExtensionPackage
public function getUnixConfigureArg(bool $shared, PackageBuilder $builder, PackageInstaller $installer): string
{
if (php::getPHPVersionID() >= 80400) {
$libfiles = new SPCConfigUtil(['libs_only_deps' => true, 'absolute_libs' => true])->getPackageDepsConfig('postgresql', array_keys($installer->getResolvedPackages()), $builder->getOption('with-suggests'))['libs'];
$libfiles = new SPCConfigUtil(['libs_only_deps' => true, 'absolute_libs' => true])->getPackageDepsConfig('postgresql', array_keys($installer->getResolvedPackages()))['libs'];
$libfiles = str_replace("{$builder->getLibDir()}/lib", '-l', $libfiles);
$libfiles = str_replace('.a', '', $libfiles);
return '--with-pgsql' . ($shared ? '=shared' : '') .
Expand Down
13 changes: 13 additions & 0 deletions src/Package/Extension/spx.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,27 @@

use Package\Target\php;
use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\CustomPhpConfigureArg;
use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Package\PackageInstaller;
use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Util\FileSystem;

#[Extension('spx')]
class spx extends PhpExtensionPackage
{
#[CustomPhpConfigureArg('Linux')]
#[CustomPhpConfigureArg('Darwin')]
public function getUnixConfigureArg(bool $shared, PackageInstaller $installer): string
{
$arg = '--enable-SPX' . ($shared ? '=shared' : '');
if ($installer->getLibraryPackage('zlib') !== null) {
$arg .= ' --with-zlib-dir=' . BUILD_ROOT_PATH;
}
return $arg;
}

#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-spx')]
#[PatchDescription('Fix spx extension compile error when building as static')]
public function patchBeforeBuildconf(): bool
Expand Down
4 changes: 3 additions & 1 deletion src/Package/Library/bzip2.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class bzip2
#[PatchBeforeBuild]
public function patchBeforeBuild(LibraryPackage $lib): void
{
FileSystem::replaceFileStr($lib->getSourceDir() . '/Makefile', 'CFLAGS=-Wall', 'CFLAGS=-fPIC -Wall');
// Makefile pins -O2 -fPIC; inject SPC_DEFAULT_CFLAGS
$extra = deduplicate_flags(trim((string) getenv('SPC_DEFAULT_CFLAGS')) . ' -fPIC -Wall');
FileSystem::replaceFileStr($lib->getSourceDir() . '/Makefile', 'CFLAGS=-Wall', "CFLAGS={$extra}");
}

#[BuildFor('Windows')]
Expand Down
4 changes: 3 additions & 1 deletion src/Package/Library/fastlz.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ public function build(LibraryPackage $lib): void
{
$cc = getenv('CC') ?: 'cc';
$ar = getenv('AR') ?: 'ar';
$extra = trim((string) getenv('SPC_DEFAULT_CFLAGS'));
$extra = $extra !== '' ? $extra . ' -fPIC' : '-O3 -fPIC';

shell()->cd($lib->getSourceDir())->initializeEnv($lib)
->exec("{$cc} -c -O3 -fPIC fastlz.c -o fastlz.o")
->exec("{$cc} -c {$extra} fastlz.c -o fastlz.o")
->exec("{$ar} rcs libfastlz.a fastlz.o");

// Copy header file
Expand Down
7 changes: 5 additions & 2 deletions src/Package/Library/icu.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ public function beforePack(LibraryPackage $lib): void
#[BuildFor('Linux')]
public function buildLinux(LibraryPackage $lib, ToolchainInterface $toolchain, PackageBuilder $builder): void
{
// runConfigureICU bakes CXXFLAGS/LDFLAGS, apply user flags too
$userCxxFlags = trim((string) getenv('SPC_DEFAULT_CXXFLAGS'));
$userLdFlags = trim((string) getenv('SPC_DEFAULT_LDFLAGS'));
$cppflags = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1 -DPIC -fPIC"';
$cxxflags = 'CXXFLAGS="-std=c++17 -DPIC -fPIC -fno-ident"';
$ldflags = $toolchain->isStatic() ? 'LDFLAGS="-static"' : '';
$cxxflags = "CXXFLAGS=\"-std=c++17 -DPIC -fPIC -fno-ident {$userCxxFlags}\"";
$ldflags = $toolchain->isStatic() ? "LDFLAGS=\"-static {$userLdFlags}\"" : "LDFLAGS=\"{$userLdFlags}\"";
shell()->cd($lib->getSourceDir() . '/source')->initializeEnv($lib)
->exec(
"{$cppflags} {$cxxflags} {$ldflags} " .
Expand Down
4 changes: 3 additions & 1 deletion src/Package/Library/jbig.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class jbig
#[PatchBeforeBuild]
public function patchBeforeBuild(LibraryPackage $lib): void
{
FileSystem::replaceFileStr($lib->getSourceDir() . '/Makefile', 'CFLAGS = -O2 -W -Wno-unused-result', 'CFLAGS = -O2 -W -Wno-unused-result -fPIC');
$extra = trim((string) getenv('SPC_DEFAULT_CFLAGS'));
$cflags = ($extra !== '' ? $extra : '-O2') . ' -W -Wno-unused-result -fPIC';
FileSystem::replaceFileStr($lib->getSourceDir() . '/Makefile', 'CFLAGS = -O2 -W -Wno-unused-result', "CFLAGS = {$cflags}");
}

#[BuildFor('Darwin')]
Expand Down
Loading
Loading