@@ -30,7 +30,7 @@ public function configure(): void
3030 $ this ->addArgument ('sources ' , InputArgument::REQUIRED , 'The sources will be compiled, comma separated ' );
3131 $ this ->addOption ('shallow-clone ' , null , null , 'Clone shallow ' );
3232 $ this ->addOption ('with-openssl11 ' , null , null , 'Use openssl 1.1 ' );
33- $ this ->addOption ('with-php ' , null , InputOption::VALUE_REQUIRED , 'version in major.minor format (default 8.4) ' , '8.4 ' );
33+ $ this ->addOption ('with-php ' , null , InputOption::VALUE_REQUIRED , 'version in major.minor format, comma-separated for multiple versions (default 8.4) ' , '8.4 ' );
3434 $ this ->addOption ('clean ' , null , null , 'Clean old download cache and source before fetch ' );
3535 $ this ->addOption ('all ' , 'A ' , null , 'Fetch all sources that static-php-cli needed ' );
3636 $ this ->addOption ('custom-url ' , 'U ' , InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED , 'Specify custom source download url, e.g "php-src:https://downloads.php.net/~eric/php-8.3.0beta1.tar.gz" ' );
@@ -94,17 +94,25 @@ public function handle(): int
9494 return $ this ->downloadFromZip ($ path );
9595 }
9696
97- // Define PHP major version
98- $ ver = $ this ->php_major_ver = $ this ->getOption ('with-php ' );
99- define ('SPC_BUILD_PHP_VERSION ' , $ ver );
100- if ($ ver !== 'git ' && !preg_match ('/^\d+\.\d+$/ ' , $ ver )) {
101- // If not git, we need to check the version format
102- if (!preg_match ('/^\d+\.\d+(\.\d+)?$/ ' , $ ver )) {
103- logger ()->error ("bad version arg: {$ ver }, x.y or x.y.z required! " );
104- return static ::FAILURE ;
97+ // Define PHP major version(s)
98+ $ php_versions_str = $ this ->getOption ('with-php ' );
99+ $ php_versions = array_map ('trim ' , explode (', ' , $ php_versions_str ));
100+
101+ // Validate all versions
102+ foreach ($ php_versions as $ ver ) {
103+ if ($ ver !== 'git ' && !preg_match ('/^\d+\.\d+$/ ' , $ ver )) {
104+ // If not git, we need to check the version format
105+ if (!preg_match ('/^\d+\.\d+(\.\d+)?$/ ' , $ ver )) {
106+ logger ()->error ("bad version arg: {$ ver }, x.y or x.y.z required! " );
107+ return static ::FAILURE ;
108+ }
105109 }
106110 }
107111
112+ // Set the first version as the default for backward compatibility
113+ $ this ->php_major_ver = $ php_versions [0 ];
114+ define ('SPC_BUILD_PHP_VERSION ' , $ this ->php_major_ver );
115+
108116 // retry
109117 $ retry = (int ) $ this ->getOption ('retry ' );
110118 f_putenv ('SPC_DOWNLOAD_RETRIES= ' . $ retry );
@@ -125,6 +133,20 @@ public function handle(): int
125133
126134 $ chosen_sources = array_map ('trim ' , array_filter (explode (', ' , $ this ->getArgument ('sources ' ))));
127135
136+ // Handle multiple PHP versions
137+ // If php-src is in the sources, replace it with version-specific sources
138+ if (in_array ('php-src ' , $ chosen_sources )) {
139+ // Remove php-src from the list
140+ $ chosen_sources = array_diff ($ chosen_sources , ['php-src ' ]);
141+ // Add version-specific php-src for each version
142+ foreach ($ php_versions as $ ver ) {
143+ $ version_specific_name = "php-src- {$ ver }" ;
144+ $ chosen_sources [] = $ version_specific_name ;
145+ // Store the version for this specific php-src
146+ f_putenv ("SPC_PHP_VERSION_ {$ version_specific_name }= {$ ver }" );
147+ }
148+ }
149+
128150 $ sss = $ this ->getOption ('ignore-cache-sources ' );
129151 if ($ sss === false ) {
130152 // false is no-any-ignores, that is, default.
@@ -201,7 +223,16 @@ public function handle(): int
201223 logger ()->info ("[ {$ ni }/ {$ cnt }] Downloading source {$ source } from custom git: {$ new_config ['url ' ]}" );
202224 Downloader::downloadSource ($ source , $ new_config , true );
203225 } else {
204- $ config = Config::getSource ($ source );
226+ // Handle version-specific php-src (php-src-8.2, php-src-8.3, etc.)
227+ if (preg_match ('/^php-src-[\d.]+$/ ' , $ source )) {
228+ $ config = Config::getSource ('php-src ' );
229+ if ($ config === null ) {
230+ logger ()->error ('php-src configuration not found in source.json ' );
231+ return static ::FAILURE ;
232+ }
233+ } else {
234+ $ config = Config::getSource ($ source );
235+ }
205236 // Prefer pre-built, we need to search pre-built library
206237 if ($ this ->getOption ('prefer-pre-built ' ) && ($ config ['provide-pre-built ' ] ?? false ) === true ) {
207238 // We need to replace pattern
0 commit comments