Skip to content

Commit 977fbaa

Browse files
committed
Suggestions
1 parent 0598eff commit 977fbaa

30 files changed

+188
-207
lines changed

config/env.ini

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ SPC_CMD_VAR_FRANKENPHP_XCADDY_MODULES="--with github.com/dunglas/frankenphp/cadd
5656

5757
[windows]
5858
; build target: win7-static
59-
SPC_TARGET=msvc-static
59+
SPC_TARGET=native
6060
; php-sdk-binary-tools path
6161
PHP_SDK_PATH="${WORKING_DIR}\php-sdk-binary-tools"
6262
; upx executable path
@@ -75,7 +75,9 @@ SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime
7575
; - musl-static (default): pure static linking, using musl-libc, can run on any linux distro.
7676
; - musl: static linking with dynamic linking to musl-libc, can run on musl-based linux distro.
7777
; - glibc: static linking with dynamic linking to glibc, can run on glibc-based linux distro.
78-
SPC_TARGET=musl-static
78+
79+
; include PATH for musl libc.
80+
SPC_LIBC=musl
7981
; compiler environments
8082
CC=${SPC_LINUX_DEFAULT_CC}
8183
CXX=${SPC_LINUX_DEFAULT_CXX}
@@ -122,7 +124,7 @@ SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-all-static -Wl,-O1 -pie"
122124
[macos]
123125
; build target: macho or macho (possibly we could support macho-universal in the future)
124126
; Currently we do not support universal and cross-compilation for macOS.
125-
SPC_TARGET=macho
127+
SPC_TARGET=native
126128
; compiler environments
127129
CC=clang
128130
CXX=clang++

src/SPC/builder/Extension.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use SPC\store\Config;
1111
use SPC\store\FileSystem;
1212
use SPC\util\SPCConfigUtil;
13+
use SPC\util\SPCTarget;
1314

1415
class Extension
1516
{
@@ -532,6 +533,11 @@ protected function getStaticAndSharedLibs(): array
532533
$sharedLibString .= '-l' . $lib . ' ';
533534
}
534535
}
536+
// move static libstdc++ to shared if we are on non-full-static build target
537+
if (!SPCTarget::isStaticTarget() && in_array(SPCTarget::getLibc(), SPCTarget::LIBC_LIST)) {
538+
$staticLibString .= ' -lstdc++';
539+
$sharedLibString = str_replace('-lstdc++', '', $sharedLibString);
540+
}
535541
return [trim($staticLibString), trim($sharedLibString)];
536542
}
537543

src/SPC/builder/extension/imagick.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use SPC\builder\Extension;
88
use SPC\util\CustomExt;
9-
use SPC\util\SPCTarget;
109

1110
#[CustomExt('imagick')]
1211
class imagick extends Extension
@@ -16,15 +15,4 @@ public function getUnixConfigureArg(bool $shared = false): string
1615
$disable_omp = ' ac_cv_func_omp_pause_resource_all=no';
1716
return '--with-imagick=' . ($shared ? 'shared,' : '') . BUILD_ROOT_PATH . $disable_omp;
1817
}
19-
20-
protected function getStaticAndSharedLibs(): array
21-
{
22-
// on centos 7, it will use the symbol _ZTINSt6thread6_StateE, which is not defined in system libstdc++.so.6
23-
[$static, $shared] = parent::getStaticAndSharedLibs();
24-
if (SPCTarget::isTarget(SPCTarget::GLIBC)) {
25-
$static .= ' -lstdc++';
26-
$shared = str_replace('-lstdc++', '', $shared);
27-
}
28-
return [$static, $shared];
29-
}
3018
}

src/SPC/builder/linux/SystemUtil.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use SPC\builder\traits\UnixSystemUtilTrait;
88
use SPC\exception\RuntimeException;
9-
use SPC\util\SPCTarget;
109

1110
class SystemUtil
1211
{
@@ -189,12 +188,12 @@ public static function getSupportedDistros(): array
189188
/**
190189
* Get libc version string from ldd
191190
*/
192-
public static function getLibcVersionIfExists(): ?string
191+
public static function getLibcVersionIfExists(string $libc): ?string
193192
{
194193
if (self::$libc_version !== null) {
195194
return self::$libc_version;
196195
}
197-
if (SPCTarget::isTarget(SPCTarget::GLIBC)) {
196+
if ($libc === 'glibc') {
198197
$result = shell()->execWithResult('ldd --version', false);
199198
if ($result[0] !== 0) {
200199
return null;
@@ -209,7 +208,7 @@ public static function getLibcVersionIfExists(): ?string
209208
}
210209
return null;
211210
}
212-
if (SPCTarget::isTarget(SPCTarget::MUSL_STATIC)) {
211+
if ($libc === 'musl') {
213212
if (self::isMuslDist()) {
214213
$result = shell()->execWithResult('ldd 2>&1', false);
215214
} else {

src/SPC/builder/linux/library/icu.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected function build(): void
1717
{
1818
$cppflags = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1 -DPIC -fPIC"';
1919
$cxxflags = 'CXXFLAGS="-std=c++17 -DPIC -fPIC -fno-ident"';
20-
$ldflags = SPCTarget::isTarget(SPCTarget::MUSL_STATIC) ? 'LDFLAGS="-static"' : '';
20+
$ldflags = SPCTarget::isStaticTarget() ? 'LDFLAGS="-static"' : '';
2121
shell()->cd($this->source_dir . '/source')->initializeEnv($this)
2222
->exec(
2323
"{$cppflags} {$cxxflags} {$ldflags} " .

src/SPC/builder/macos/MacOSBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function __construct(array $options = [])
2929

3030
// apply global environment variables
3131
GlobalEnvManager::init();
32+
GlobalEnvManager::afterInit();
3233

3334
// ---------- set necessary compile vars ----------
3435
// concurrency

src/SPC/builder/unix/UnixBuilderBase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ protected function sanityCheck(int $build_target): void
201201
$util = new SPCConfigUtil($this);
202202
$config = $util->config($this->ext_list, $this->lib_list, $this->getOption('with-suggested-exts'), $this->getOption('with-suggested-libs'));
203203
$lens = "{$config['cflags']} {$config['ldflags']} {$config['libs']}";
204-
if (SPCTarget::isTarget(SPCTarget::MUSL_STATIC)) {
204+
if (SPCTarget::isStaticTarget()) {
205205
$lens .= ' -static';
206206
}
207207
[$ret, $out] = shell()->cd($sample_file_path)->execWithResult(getenv('CC') . ' -o embed embed.c ' . $lens);
@@ -335,7 +335,7 @@ protected function buildFrankenphp(): void
335335
$debugFlags = $this->getOption('no-strip') ? "'-w -s' " : '';
336336
$extLdFlags = "-extldflags '-pie'";
337337
$muslTags = '';
338-
if (SPCTarget::isTarget(SPCTarget::MUSL_STATIC)) {
338+
if (SPCTarget::isStaticTarget()) {
339339
$extLdFlags = "-extldflags '-static-pie -Wl,-z,stack-size=0x80000'";
340340
$muslTags = 'static_build,';
341341
}

src/SPC/builder/unix/library/imagemagick.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use SPC\exception\FileSystemException;
88
use SPC\exception\RuntimeException;
9+
use SPC\exception\WrongUsageException;
910
use SPC\store\FileSystem;
1011
use SPC\util\executor\UnixAutoconfExecutor;
1112
use SPC\util\SPCTarget;
@@ -15,6 +16,7 @@ trait imagemagick
1516
/**
1617
* @throws RuntimeException
1718
* @throws FileSystemException
19+
* @throws WrongUsageException
1820
*/
1921
protected function build(): void
2022
{
@@ -36,11 +38,11 @@ protected function build(): void
3638
'--without-x',
3739
);
3840

39-
// special: linux musl-static needs `-static`
40-
$ldflags = !SPCTarget::isTarget(SPCTarget::MUSL_STATIC) ? ('-static -ldl') : '-ldl';
41+
// special: linux-static target needs `-static`
42+
$ldflags = SPCTarget::isStaticTarget() ? ('-static -ldl') : '-ldl';
4143

4244
// special: macOS needs -iconv
43-
$libs = SPCTarget::isTarget(SPCTarget::MACHO) ? '-liconv' : '';
45+
$libs = SPCTarget::getTargetOS() === 'Darwin' ? '-liconv' : '';
4446

4547
$ac->appendEnv([
4648
'LDFLAGS' => $ldflags,

src/SPC/builder/unix/library/ldap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait ldap
1212
{
1313
public function patchBeforeBuild(): bool
1414
{
15-
$extra = SPCTarget::isTarget(SPCTarget::GLIBC) ? '-ldl -lpthread -lm -lresolv -lutil' : '';
15+
$extra = SPCTarget::getLibc() === 'glibc' ? '-ldl -lpthread -lm -lresolv -lutil' : '';
1616
FileSystem::replaceFileStr($this->source_dir . '/configure', '"-lssl -lcrypto', '"-lssl -lcrypto -lz ' . $extra);
1717
return true;
1818
}

src/SPC/builder/unix/library/mimalloc.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ protected function build(): void
1414
$cmake = UnixCMakeExecutor::create($this)
1515
->addConfigureArgs(
1616
'-DMI_BUILD_SHARED=OFF',
17-
'-DMI_INSTALL_TOPLEVEL=ON'
17+
'-DMI_INSTALL_TOPLEVEL=ON',
1818
);
19-
if (SPCTarget::isTarget(SPCTarget::MUSL) || SPCTarget::isTarget(SPCTarget::MUSL_STATIC)) {
19+
if (SPCTarget::getLibc() === 'musl') {
2020
$cmake->addConfigureArgs('-DMI_LIBC_MUSL=ON');
2121
}
2222
$cmake->build();

0 commit comments

Comments
 (0)