diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 63dc31d04..4b5c8109f 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -434,7 +434,18 @@ public function buildUnixShared(): void logger()->info("Extension [{$this->getName()}] patched before shared configure"); } + // Parse and add SPC_EXTRA_PHP_VARS as environment variables $phpvars = getenv('SPC_EXTRA_PHP_VARS') ?: ''; + if ($phpvars !== '') { + // Parse space-separated key=value pairs + $parts = preg_split('/\s+/', trim($phpvars), -1, PREG_SPLIT_NO_EMPTY); + foreach ($parts as $part) { + if (str_contains($part, '=')) { + [$key, $value] = explode('=', $part, 2); + $env[$key] = $value; + } + } + } shell()->cd($this->source_dir) ->setEnv($env) @@ -442,7 +453,7 @@ public function buildUnixShared(): void ->exec( './configure ' . $this->getUnixConfigureArg(true) . ' --with-php-config=' . BUILD_BIN_PATH . '/php-config ' . - "--enable-shared --disable-static {$phpvars}" + '--enable-shared --disable-static' ); if ($this->patchBeforeSharedMake()) { diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index ed26d64f3..fc3c71621 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -93,14 +93,27 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void // prepare build php envs // $musl_flag = SPCTarget::getLibc() === 'musl' ? ' -D__MUSL__' : ' -U__MUSL__'; - $php_configure_env = SystemUtil::makeEnvVarString([ + $env_vars = [ 'CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'), 'CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH, // . ' -Dsomethinghere', // . $musl_flag, 'LDFLAGS' => '-L' . BUILD_LIB_PATH, // 'LIBS' => SPCTarget::getRuntimeLibs(), // do not pass static libraries here yet, they may contain polyfills for libc functions! - ]); + ]; + // Parse and add SPC_EXTRA_PHP_VARS as environment variables $phpvars = getenv('SPC_EXTRA_PHP_VARS') ?: ''; + if ($phpvars !== '') { + // Parse space-separated key=value pairs + $parts = preg_split('/\s+/', trim($phpvars), -1, PREG_SPLIT_NO_EMPTY); + foreach ($parts as $part) { + if (str_contains($part, '=')) { + [$key, $value] = explode('=', $part, 2); + $env_vars[$key] = $value; + } + } + } + + $php_configure_env = SystemUtil::makeEnvVarString($env_vars); $embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static'; if ($embed_type !== 'static' && SPCTarget::isStatic()) { @@ -123,7 +136,6 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void $json_74 . $zts . $maxExecutionTimers . - $phpvars . ' ' . $this->makeStaticExtensionArgs() . ' ' ));