Skip to content

Commit b4f3657

Browse files
authored
Remove SPC_NO_MUSL_PATH, remove --libc, use SPC_LIBC instead (#642)
* Remove SPC_NO_MUSL_PATH, remove --libc, use SPC_LIBC instead * Fix tests * Internally use GNU_ARCH for unified * Update EXTENSION_DIR comments for env.ini * Remove redundant -fPIC cflags in curl
1 parent 91a3a01 commit b4f3657

32 files changed

+78
-115
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,13 @@ jobs:
100100
path: vendor
101101
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
102102
restore-keys: |
103-
${{ runner.os }}-php-
103+
${{ runner.os }}-php
104104
105105
- name: "Install Dependencies"
106106
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
107107

108108
- name: "Run PHPUnit Tests"
109-
run: |
110-
SPC_NO_MUSL_PATH=yes vendor/bin/phpunit tests/ --no-coverage
109+
run: SPC_LIBC=glibc vendor/bin/phpunit tests/ --no-coverage
111110

112111
define-matrix:
113112
name: "Define Matrix"

bin/build-static-frankenphp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ ADD ./bin/spc /app/bin/spc
9292
RUN /app/bin/setup-runtime
9393
RUN /app/bin/php /app/bin/composer install --no-dev --classmap-authoritative
9494
ENV PATH="/app/bin:/cmake/bin:/usr/local/go/bin:$PATH"
95-
ENV SPC_SKIP_DOCTOR_CHECK_ITEMS="if musl-wrapper is installed,if musl-cross-make is installed"
95+
ENV SPC_LIBC=glibc
9696
9797
ADD ./config/env.ini /app/config/env.ini
9898
RUN bin/spc doctor --auto-fix --debug
@@ -141,13 +141,12 @@ MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/pkgroot:/app/pkgroot"
141141
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/frankenphp-dist:/frankenphp/dist"
142142

143143
# Apply env in temp env file
144-
echo 'SPC_SKIP_DOCTOR_CHECK_ITEMS=if musl-wrapper is installed,if musl-cross-make is installed' > /tmp/spc-gnu-docker.env
145-
echo 'CC=/opt/rh/devtoolset-10/root/usr/bin/gcc' >> /tmp/spc-gnu-docker.env
144+
echo 'CC=/opt/rh/devtoolset-10/root/usr/bin/gcc' > /tmp/spc-gnu-docker.env
146145
echo 'CXX=/opt/rh/devtoolset-10/root/usr/bin/g++' >> /tmp/spc-gnu-docker.env
147146
echo 'AR=/opt/rh/devtoolset-10/root/usr/bin/ar' >> /tmp/spc-gnu-docker.env
148147
echo 'LD=/opt/rh/devtoolset-10/root/usr/bin/ld' >> /tmp/spc-gnu-docker.env
149148
echo 'SPC_DEFAULT_C_FLAGS=-fPIE -fPIC' >> /tmp/spc-gnu-docker.env
150-
echo 'SPC_NO_MUSL_PATH=yes' >> /tmp/spc-gnu-docker.env
149+
echo 'SPC_LIBC=glibc' >> /tmp/spc-gnu-docker.env
151150
echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie"' >> /tmp/spc-gnu-docker.env
152151
echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil -lrt"' >> /tmp/spc-gnu-docker.env
153152

bin/spc-gnu-docker

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ ADD ./bin/spc /app/bin/spc
8888
RUN /app/bin/setup-runtime
8989
RUN /app/bin/php /app/bin/composer install --no-dev --classmap-authoritative
9090
ENV PATH="/app/bin:/cmake/bin:$PATH"
91-
ENV SPC_SKIP_DOCTOR_CHECK_ITEMS="if musl-wrapper is installed,if musl-cross-make is installed"
91+
ENV SPC_LIBC=glibc
9292
9393
ADD ./config/env.ini /app/config/env.ini
9494
RUN bin/spc doctor --auto-fix --debug
@@ -131,13 +131,12 @@ MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/downloads:/app/downloads"
131131
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/pkgroot:/app/pkgroot"
132132

133133
# Apply env in temp env file
134-
echo 'SPC_SKIP_DOCTOR_CHECK_ITEMS=if musl-wrapper is installed,if musl-cross-make is installed' > /tmp/spc-gnu-docker.env
135-
echo 'CC=/opt/rh/devtoolset-10/root/usr/bin/gcc' >> /tmp/spc-gnu-docker.env
134+
echo 'CC=/opt/rh/devtoolset-10/root/usr/bin/gcc' > /tmp/spc-gnu-docker.env
136135
echo 'CXX=/opt/rh/devtoolset-10/root/usr/bin/g++' >> /tmp/spc-gnu-docker.env
137136
echo 'AR=/opt/rh/devtoolset-10/root/usr/bin/ar' >> /tmp/spc-gnu-docker.env
138137
echo 'LD=/opt/rh/devtoolset-10/root/usr/bin/ld' >> /tmp/spc-gnu-docker.env
139138
echo 'SPC_DEFAULT_C_FLAGS=-fPIE -fPIC' >> /tmp/spc-gnu-docker.env
140-
echo 'SPC_NO_MUSL_PATH=yes' >> /tmp/spc-gnu-docker.env
139+
echo 'SPC_LIBC=glibc' >> /tmp/spc-gnu-docker.env
141140
echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM="-Wl,-O1 -pie"' >> /tmp/spc-gnu-docker.env
142141
echo 'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="-ldl -lpthread -lm -lresolv -lutil -lrt"' >> /tmp/spc-gnu-docker.env
143142

config/env.ini

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
;
88
; We need to use some pre-defined internal env vars, like `BUILD_ROOT_PATH`, `DOWNLOAD_PATH`, etc.
99
; Please note that these vars cannot be defined in this file, they are only be defined before static-php-cli running.
10-
; Here's a list of these pre-defined internal env vars, these vars are only be defined in the static-php-cli build process if not set in the shell environment:
1110
;
11+
; Here's a list of env vars, these value cannot be changed anywhere:
12+
;
13+
; WORKING_DIR: the working directory of the build process. (default: `$(pwd)`)
14+
; ROOT_DIR: the root directory of static-php-cli. (default: `/path/to/static-php-cli`, when running in phar or micro mode: `phar://path/to/spc.phar`)
1215
; BUILD_ROOT_PATH: the root path of the build process. (default: `$(pwd)/buildroot`)
1316
; BUILD_INCLUDE_PATH: the path of the include files. (default: `$BUILD_ROOT_PATH/include`)
1417
; BUILD_LIB_PATH: the path of the lib files. (default: `$BUILD_ROOT_PATH/lib`)
@@ -17,21 +20,17 @@
1720
; SOURCE_PATH: the path of the source files. (default: `$(pwd)/source`)
1821
; DOWNLOAD_PATH: the path of the download files. (default: `$(pwd)/downloads`)
1922
; CPU_COUNT: the count of the CPU cores. (default: `$(nproc)`)
23+
; SPC_ARCH: the arch of the current system, for some libraries needed `--host=XXX` args. (default: `$(uname -m)`, e.g. `x86_64`, `aarch64`, `arm64`)
2024
; GNU_ARCH: the GNU arch of the current system. (default: `$(uname -m)`, e.g. `x86_64`, `aarch64`)
2125
; MAC_ARCH: the MAC arch of the current system. (default: `$(uname -m)`, e.g. `x86_64`, `arm64`)
2226
;
23-
; Here's a list of env vars, these value cannot be changed anywhere:
24-
;
25-
; WORKING_DIR: the working directory of the build process. (default: `$(pwd)`)
26-
; ROOT_DIR: the root directory of static-php-cli. (default: `/path/to/static-php-cli`, when running in phar or micro mode: `phar://path/to/spc.phar`)
27-
;
28-
; * These vars are only be defined in Unix (macOS, Linux, FreeBSD)Builder *
27+
; * These vars are only be defined in Unix (macOS, Linux, FreeBSD)Builder and cannot be changed anywhere:
2928
; PATH: static-php-cli will add `$BUILD_BIN_PATH` to PATH.
3029
; PKG_CONFIG: static-php-cli will set `$BUILD_BIN_PATH/pkg-config` to PKG_CONFIG.
3130
; PKG_CONFIG_PATH: static-php-cli will set `$BUILD_LIB_PATH/pkgconfig` to PKG_CONFIG_PATH.
3231
; SPC_PHP_DEFAULT_OPTIMIZE_CFLAGS: the default optimization CFLAGS for compiling php. (if --no-strip option is set: `-g -O0`, else: `-g -Os`)
3332
;
34-
; * These vars are only be defined in LinuxBuilder *
33+
; * These vars are only be defined in LinuxBuilder and cannot be changed anywhere:
3534
; SPC_LINUX_DEFAULT_CC: the default compiler for linux. (For alpine linux: `gcc`, default: `$GNU_ARCH-linux-musl-gcc`)
3635
; SPC_LINUX_DEFAULT_CXX: the default c++ compiler for linux. (For alpine linux: `g++`, default: `$GNU_ARCH-linux-musl-g++`)
3736
; SPC_LINUX_DEFAULT_AR: the default archiver for linux. (For alpine linux: `ar`, default: `$GNU_ARCH-linux-musl-ar`)
@@ -45,7 +44,7 @@ SPC_SKIP_PHP_VERSION_CHECK="no"
4544
; Ignore some check item for bin/spc doctor command, comma separated (e.g. SPC_SKIP_DOCTOR_CHECK_ITEMS="if homebrew has installed")
4645
SPC_SKIP_DOCTOR_CHECK_ITEMS=""
4746
; EXTENSION_DIR where the built php will look for extension when a .ini instructs to load them
48-
; only useful for builds targeting glibc --libc=glibc
47+
; only useful for builds targeting not pure-static linking
4948
; default paths
5049
; Ubuntu/Debian: /usr/lib/php/{PHP_VERSION}/
5150
; RHEL: /usr/lib64/php/modules
@@ -63,7 +62,7 @@ SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime
6362

6463
[linux]
6564
; include PATH for musl libc.
66-
SPC_NO_MUSL_PATH=no
65+
SPC_LIBC=musl
6766
; compiler environments
6867
CC=${SPC_LINUX_DEFAULT_CC}
6968
CXX=${SPC_LINUX_DEFAULT_CXX}

docs/en/faq/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ supporting FFI extensions and loading the `xdebug.so` extension of the same PHP
3232

3333
```bash
3434
bin/spc-gnu-docker download --for-extensions=ffi,xml --with-php=8.4
35-
bin/spc-gnu-docker build --libc=glibc ffi,xml --build-cli --debug
35+
bin/spc-gnu-docker build ffi,xml --build-cli --debug
3636

3737
buildroot/bin/php -d "zend_extension=/path/to/php{PHP_VER}-{ts/nts}/xdebug.so" --ri xdebug
3838
```

docs/en/guide/build-with-glibc.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ After the image is built, you will see the same command help menu as `bin/spc`,
4646
After the container is ready, you can refer to the [local build](./manual-build) section to build your PHP static binary.
4747
Just replace `bin/spc` or `./spc` with `bin/spc-gnu-docker`.
4848

49-
Unlike the default build, when building in the glibc environment, you **must** add the parameter `--libc=glibc`, such as:
50-
5149
```bash
52-
bin/spc-gnu-docker --libc=glibc build bcmath,ctype,openssl,pdo,phar,posix,session,tokenizer,xml,zip --build-cli --debug
50+
bin/spc-gnu-docker build bcmath,ctype,openssl,pdo,phar,posix,session,tokenizer,xml,zip --build-cli --debug
5351
```
5452

5553
## Notes

docs/zh/faq/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ PHP 默认也会从 [其他标准位置](https://www.php.net/manual/zh/configura
2929

3030
```bash
3131
bin/spc-gnu-docker download --for-extensions=ffi,xml --with-php=8.4
32-
bin/spc-gnu-docker build --libc=glibc ffi,xml --build-cli --debug
32+
bin/spc-gnu-docker build ffi,xml --build-cli --debug
3333

3434
buildroot/bin/php -d "zend_extension=/path/to/php{PHP_VER}-{ts/nts}/xdebug.so" --ri xdebug
3535
```

docs/zh/guide/build-with-glibc.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ bin/spc-gnu-docker
3939

4040
在容器准备好后,你可以参考 [本地构建](./manual-build) 章节的内容,构建你的 PHP 静态二进制文件。仅需要把 `bin/spc``./spc` 替换为 `bin/spc-gnu-docker` 即可。
4141

42-
与默认构建不同的是,在 glibc 环境构建时**必须添加**参数 `--libc=glibc`,如:
43-
4442
```bash
45-
bin/spc-gnu-docker --libc=glibc build bcmath,ctype,openssl,pdo,phar,posix,session,tokenizer,xml,zip --build-cli --debug
43+
bin/spc-gnu-docker build bcmath,ctype,openssl,pdo,phar,posix,session,tokenizer,xml,zip --build-cli --debug
4644
```
4745

4846
## 注意事项

src/SPC/ConsoleApplication.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace SPC;
66

7-
use SPC\command\BuildCliCommand;
87
use SPC\command\BuildLibsCommand;
8+
use SPC\command\BuildPHPCommand;
99
use SPC\command\DeleteDownloadCommand;
1010
use SPC\command\dev\AllExtCommand;
1111
use SPC\command\dev\ExtVerCommand;
@@ -44,7 +44,7 @@ public function __construct()
4444
$this->addCommands(
4545
[
4646
// Common commands
47-
new BuildCliCommand(),
47+
new BuildPHPCommand(),
4848
new BuildLibsCommand(),
4949
new DoctorCommand(),
5050
new DownloadCommand(),

src/SPC/builder/linux/LinuxBuilder.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
class LinuxBuilder extends UnixBuilderBase
1717
{
18-
public string $libc;
19-
2018
/** @var bool Micro patch phar flag */
2119
private bool $phar_patched = false;
2220

@@ -27,27 +25,23 @@ class LinuxBuilder extends UnixBuilderBase
2725
public function __construct(array $options = [])
2826
{
2927
$this->options = $options;
30-
SystemUtil::initLibcVar($this->options['libc'] ?? null);
31-
32-
$this->libc = getenv('SPC_LIBC') ?: LIBC_MUSL_WRAPPER;
3328

3429
// check musl-cross make installed if we use musl-cross-make
3530
$arch = arch2gnu(php_uname('m'));
3631

3732
GlobalEnvManager::init($this);
3833

39-
// set library path, some libraries need it. (We cannot use `putenv` here, because cmake will be confused)
40-
if (!filter_var(getenv('SPC_NO_MUSL_PATH'), FILTER_VALIDATE_BOOLEAN) && $this->libc !== LIBC_GLIBC) {
34+
if (getenv('SPC_LIBC') === 'musl' && !SystemUtil::isMuslDist()) {
4135
$this->setOptionIfNotExist('library_path', "LIBRARY_PATH=\"/usr/local/musl/{$arch}-linux-musl/lib\"");
4236
$this->setOptionIfNotExist('ld_library_path', "LD_LIBRARY_PATH=\"/usr/local/musl/{$arch}-linux-musl/lib\"");
4337
GlobalEnvManager::putenv("PATH=/usr/local/musl/bin:/usr/local/musl/{$arch}-linux-musl/bin:" . getenv('PATH'));
4438
$configure = getenv('SPC_CMD_PREFIX_PHP_CONFIGURE');
4539
$configure = "LD_LIBRARY_PATH=\"/usr/local/musl/{$arch}-linux-musl/lib\" " . $configure;
4640
GlobalEnvManager::putenv("SPC_CMD_PREFIX_PHP_CONFIGURE={$configure}");
47-
}
4841

49-
if (str_ends_with(getenv('CC'), 'linux-musl-gcc') && !file_exists("/usr/local/musl/bin/{$arch}-linux-musl-gcc") && (getenv('SPC_NO_MUSL_PATH') !== 'yes')) {
50-
throw new WrongUsageException('musl-cross-make not installed, please install it first. (You can use `doctor` command to install it)');
42+
if (!file_exists("/usr/local/musl/{$arch}-linux-musl/lib/libc.a")) {
43+
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)');
44+
}
5145
}
5246

5347
// concurrency
@@ -216,10 +210,8 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
216210
$this->buildEmbed();
217211
}
218212

219-
if (php_uname('m') === $this->getOption('arch')) {
220-
$this->emitPatchPoint('before-sanity-check');
221-
$this->sanityCheck($build_target);
222-
}
213+
$this->emitPatchPoint('before-sanity-check');
214+
$this->sanityCheck($build_target);
223215
}
224216

225217
/**

0 commit comments

Comments
 (0)