Skip to content

Commit a3220fe

Browse files
committed
remove musl libc stuff on ubuntu
1 parent 5b792f9 commit a3220fe

File tree

22 files changed

+53
-346
lines changed

22 files changed

+53
-346
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ jobs:
105105
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
106106

107107
- name: "Run PHPUnit Tests"
108-
run: SPC_LIBC=glibc vendor/bin/phpunit tests/ --no-coverage
108+
run: vendor/bin/phpunit tests/ --no-coverage
109109

110110
define-matrix:
111111
name: "Define Matrix"

bin/build-static-frankenphp

Lines changed: 0 additions & 158 deletions
This file was deleted.

bin/spc-gnu-docker

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ ADD ./bin/spc /app/bin/spc
108108
RUN /app/bin/setup-runtime
109109
RUN /app/bin/php /app/bin/composer install --no-dev
110110
ENV PATH="/app/bin:/cmake/bin:$PATH"
111-
ENV SPC_LIBC=glibc
112111
113112
ADD ./config/env.ini /app/config/env.ini
114113
RUN CC=gcc bin/spc doctor --auto-fix --debug
@@ -159,7 +158,6 @@ echo 'CXX=/opt/rh/devtoolset-10/root/usr/bin/g++' >> /tmp/spc-gnu-docker.env
159158
echo 'AR=/opt/rh/devtoolset-10/root/usr/bin/ar' >> /tmp/spc-gnu-docker.env
160159
echo 'LD=/opt/rh/devtoolset-10/root/usr/bin/ld' >> /tmp/spc-gnu-docker.env
161160
echo 'SPC_DEFAULT_C_FLAGS=-fPIC' >> /tmp/spc-gnu-docker.env
162-
echo 'SPC_LIBC=glibc' >> /tmp/spc-gnu-docker.env
163161
echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie"' >> /tmp/spc-gnu-docker.env
164162
echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil -lrt"' >> /tmp/spc-gnu-docker.env
165163

config/env.ini

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,11 @@ UPX_EXEC="${PKG_ROOT_PATH}\bin\upx.exe"
6363
SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime140,win32,zend_stream,cli_static
6464

6565
[linux]
66-
; include PATH for musl libc.
67-
SPC_LIBC=musl
6866
; compiler environments
69-
CC=${SPC_LINUX_DEFAULT_CC}
70-
CXX=${SPC_LINUX_DEFAULT_CXX}
71-
AR=${SPC_LINUX_DEFAULT_AR}
72-
LD=${SPC_LINUX_DEFAULT_LD}
67+
CC=gcc
68+
CXX=g++
69+
AR=ar
70+
LD=ld
7371
; default compiler flags, used in CMake toolchain file, openssl and pkg-config build
7472
SPC_DEFAULT_C_FLAGS="-fPIC -Os"
7573
SPC_DEFAULT_CXX_FLAGS="-fPIC -Os"
@@ -78,7 +76,7 @@ SPC_EXTRA_LIBS=
7876
; upx executable path
7977
UPX_EXEC=${PKG_ROOT_PATH}/bin/upx
8078
; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches
81-
SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime140,win32,zend_stream
79+
SPC_MICRO_PATCHES=cli_checks,disable_huge_page,zend_stream
8280

8381
; *** default build command for building php ***
8482
; buildconf command

src/SPC/builder/extension/imagick.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function patchBeforeMake(): bool
1515
if (PHP_OS_FAMILY !== 'Linux') {
1616
return false;
1717
}
18-
if (getenv('SPC_LIBC') === 'glibc' && str_contains(getenv('CC'), 'devtoolset-10')) {
18+
if (getenv('NO_LIBGOMP')) {
1919
return false;
2020
}
2121
// imagick with calls omp_pause_all, which requires openmp, on non-musl we build imagick without openmp
@@ -26,15 +26,15 @@ public function patchBeforeMake(): bool
2626

2727
public function getUnixConfigureArg(bool $shared = false): string
2828
{
29-
$disable_omp = !(getenv('SPC_LIBC') === 'glibc' && str_contains(getenv('CC'), 'devtoolset-10')) ? '' : ' ac_cv_func_omp_pause_resource_all=no';
29+
$disable_omp = !(getenv('NO_LIBGOMP')) ? '' : ' ac_cv_func_omp_pause_resource_all=no';
3030
return '--with-imagick=' . ($shared ? 'shared,' : '') . BUILD_ROOT_PATH . $disable_omp;
3131
}
3232

3333
protected function getStaticAndSharedLibs(): array
3434
{
3535
// on centos 7, it will use the symbol _ZTINSt6thread6_StateE, which is not defined in system libstdc++.so.6
3636
[$static, $shared] = parent::getStaticAndSharedLibs();
37-
if (getenv('SPC_LIBC') === 'glibc' && str_contains(getenv('CC'), 'devtoolset-10')) {
37+
if (str_contains(getenv('CC'), 'devtoolset-10')) {
3838
$static .= ' -lstdc++';
3939
$shared = str_replace('-lstdc++', '', $shared);
4040
}

src/SPC/builder/linux/LinuxBuilder.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@ public function __construct(array $options = [])
3030

3131
GlobalEnvManager::init($this);
3232

33-
if (getenv('SPC_LIBC') === 'musl' && !SystemUtil::isMuslDist()) {
34-
$this->setOptionIfNotExist('library_path', "LIBRARY_PATH=\"/usr/local/musl/{$arch}-linux-musl/lib\"");
35-
$this->setOptionIfNotExist('ld_library_path', "LD_LIBRARY_PATH=\"/usr/local/musl/{$arch}-linux-musl/lib\"");
36-
$configure = getenv('SPC_CMD_PREFIX_PHP_CONFIGURE');
37-
$configure = "LD_LIBRARY_PATH=\"/usr/local/musl/{$arch}-linux-musl/lib\" " . $configure;
38-
GlobalEnvManager::putenv("SPC_CMD_PREFIX_PHP_CONFIGURE={$configure}");
39-
40-
if (!file_exists("/usr/local/musl/{$arch}-linux-musl/lib/libc.a")) {
41-
throw new WrongUsageException('You are building with musl-libc target in glibc distro, but musl-toolchain is not installed, please install musl-toolchain first. (You can use `doctor` command to install it)');
42-
}
43-
}
44-
4533
// concurrency
4634
$this->concurrency = intval(getenv('SPC_CONCURRENCY'));
4735
// cflags

src/SPC/builder/linux/SystemUtil.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public static function isMuslDist(): bool
6262
return static::getOSRelease()['dist'] === 'alpine';
6363
}
6464

65+
public static function isGlibcDist(): bool
66+
{
67+
return PHP_OS_FAMILY === 'Linux' && static::getOSRelease()['dist'] !== 'alpine';
68+
}
69+
6570
public static function getCpuCount(): int
6671
{
6772
$ncpu = 1;
@@ -193,7 +198,7 @@ public static function getLibcVersionIfExists(): ?string
193198
if (self::$libc_version !== null) {
194199
return self::$libc_version;
195200
}
196-
if (PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') === 'glibc') {
201+
if (PHP_OS_FAMILY === 'Linux' && !SystemUtil::isMuslDist()) {
197202
$result = shell()->execWithResult('ldd --version', false);
198203
if ($result[0] !== 0) {
199204
return null;
@@ -208,12 +213,8 @@ public static function getLibcVersionIfExists(): ?string
208213
}
209214
return null;
210215
}
211-
if (PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') === 'musl') {
212-
if (self::isMuslDist()) {
213-
$result = shell()->execWithResult('ldd 2>&1', false);
214-
} else {
215-
$result = shell()->execWithResult('/usr/local/musl/lib/libc.so 2>&1', false);
216-
}
216+
if (PHP_OS_FAMILY === 'Linux' && SystemUtil::isMuslDist()) {
217+
$result = shell()->execWithResult('ldd 2>&1', false);
217218
// Match Version * line
218219
// match ldd version: "Version 1.2.3" match 1.2.3
219220
$pattern = '/Version\s+(\d+\.\d+\.\d+)/';
@@ -224,4 +225,15 @@ public static function getLibcVersionIfExists(): ?string
224225
}
225226
return null;
226227
}
228+
229+
public static function getLibcName()
230+
{
231+
if (PHP_OS_FAMILY === 'Darwin') {
232+
return 'libSystem';
233+
}
234+
if (PHP_OS_FAMILY === 'Windows') {
235+
return 'msvcrt';
236+
}
237+
return self::isMuslDist() ? 'musl' : 'glibc';
238+
}
227239
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace SPC\builder\linux\library;
66

7+
use SPC\builder\linux\SystemUtil;
78
use SPC\store\FileSystem;
89

910
class icu extends LinuxLibraryBase
@@ -16,7 +17,7 @@ protected function build(): void
1617
{
1718
$cppflags = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1 -DPIC -fPIC"';
1819
$cxxflags = 'CXXFLAGS="-std=c++17 -DPIC -fPIC -fno-ident"';
19-
$ldflags = getenv('SPC_LIBC') !== 'glibc' ? 'LDFLAGS="-static"' : '';
20+
$ldflags = SystemUtil::isMuslDist() ? 'LDFLAGS="-static"' : '';
2021
shell()->cd($this->source_dir . '/source')->initializeEnv($this)
2122
->exec(
2223
"{$cppflags} {$cxxflags} {$ldflags} " .

src/SPC/builder/unix/UnixBuilderBase.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use SPC\builder\BuilderBase;
88
use SPC\builder\freebsd\library\BSDLibraryBase;
99
use SPC\builder\linux\library\LinuxLibraryBase;
10+
use SPC\builder\linux\SystemUtil;
1011
use SPC\builder\macos\library\MacOSLibraryBase;
1112
use SPC\exception\FileSystemException;
1213
use SPC\exception\RuntimeException;
@@ -200,7 +201,7 @@ protected function sanityCheck(int $build_target): void
200201
$util = new SPCConfigUtil($this);
201202
$config = $util->config($this->ext_list, $this->lib_list, $this->getOption('with-suggested-exts'), $this->getOption('with-suggested-libs'));
202203
$lens = "{$config['cflags']} {$config['ldflags']} {$config['libs']}";
203-
if (PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') === 'musl') {
204+
if (SystemUtil::isMuslDist()) {
204205
$lens .= ' -static';
205206
}
206207
[$ret, $out] = shell()->cd($sample_file_path)->execWithResult(getenv('CC') . ' -o embed embed.c ' . $lens);
@@ -334,7 +335,7 @@ protected function buildFrankenphp(): void
334335
$debugFlags = $this->getOption('no-strip') ? "'-w -s' " : '';
335336
$extLdFlags = "-extldflags '-pie'";
336337
$muslTags = '';
337-
if (PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') === 'musl') {
338+
if (SystemUtil::isMuslDist()) {
338339
$extLdFlags = "-extldflags '-static-pie -Wl,-z,stack-size=0x80000'";
339340
$muslTags = 'static_build,';
340341
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace SPC\builder\unix\library;
66

77
use SPC\builder\linux\library\LinuxLibraryBase;
8+
use SPC\builder\linux\SystemUtil;
89
use SPC\builder\macos\library\MacOSLibraryBase;
910
use SPC\exception\FileSystemException;
1011
use SPC\exception\RuntimeException;
@@ -33,13 +34,13 @@ protected function build(): void
3334
->optionalLib('bzip2', ...ac_with_args('bzlib'))
3435
->addConfigureArgs(
3536
// TODO: glibc rh 10 toolset's libgomp.a was built without -fPIC so we can't use openmp without depending on libgomp.so
36-
getenv('SPC_LIBC') === 'glibc' && str_contains(getenv('CC'), 'devtoolset-10') ? '--disable-openmp' : '--enable-openmp',
37+
getenv('NO_LIBGOMP') ? '--disable-openmp' : '--enable-openmp',
3738
'--without-jxl',
3839
'--without-x',
3940
);
4041

4142
// special: linux musl needs `-static`
42-
$ldflags = ($this instanceof LinuxLibraryBase) && getenv('SPC_LIBC') !== 'glibc' ? ('-static -ldl') : '-ldl';
43+
$ldflags = SystemUtil::isMuslDist() ? '-static -ldl' : '-ldl';
4344

4445
// special: macOS needs -iconv
4546
$libs = $this instanceof MacOSLibraryBase ? '-liconv' : '';

0 commit comments

Comments
 (0)