File tree Expand file tree Collapse file tree 3 files changed +40
-6
lines changed
Expand file tree Collapse file tree 3 files changed +40
-6
lines changed Original file line number Diff line number Diff line change @@ -108,9 +108,6 @@ SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS=""
108108; EXTRA_LDFLAGS_PROGRAM for `make` php
109109SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM =" -all-static -pie"
110110
111- # Zig
112- ZIG_SHARED_EXTENSION_EXTRA_OBJECTS =" /usr/lib/gcc/x86_64-redhat-linux/14/crtbeginS.o /usr/lib/gcc/x86_64-redhat-linux/14/crtendS.o"
113-
114111[macos]
115112; compiler environments
116113CC =clang
Original file line number Diff line number Diff line change 44
55namespace SPC \builder ;
66
7+ use SPC \builder \linux \SystemUtil ;
78use SPC \exception \FileSystemException ;
89use SPC \exception \RuntimeException ;
910use SPC \exception \WrongUsageException ;
@@ -215,13 +216,13 @@ public function patchBeforeSharedConfigure(): bool
215216 */
216217 public function patchBeforeSharedMake (): bool
217218 {
218- if (!str_contains (getenv ('CC ' ), 'zig ' )) {
219+ $ extra = SystemUtil::getExtraRuntimeObjects ();
220+ if (!$ extra ) {
219221 return false ;
220222 }
221- $ extra = getenv ('ZIG_SHARED_EXTENSION_EXTRA_OBJECTS ' );
222223 FileSystem::replaceFileRegex (
223224 $ this ->source_dir . '/Makefile ' ,
224- "/^(shared_objects_ {$ this ->getName ()}\s*=.*)$/m " ,
225+ "/^(shared_objects_ {$ this ->getName ()}\\ s*=.*)$/m " ,
225226 "$1 {$ extra }" ,
226227 );
227228 return true ;
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ class SystemUtil
1313
1414 public static ?string $ libc_version = null ;
1515
16+ private static ?string $ extra_runtime_objects = null ;
17+
1618 /** @noinspection PhpMissingBreakStatementInspection */
1719 public static function getOSRelease (): array
1820 {
@@ -226,4 +228,38 @@ public static function getLibcVersionIfExists(): ?string
226228 }
227229 return null ;
228230 }
231+
232+ public static function getExtraRuntimeObjects (): string
233+ {
234+ $ cc = getenv ('CC ' );
235+ if (!$ cc || !str_contains ($ cc , 'zig ' )) {
236+ return '' ;
237+ }
238+
239+ if (self ::$ extra_runtime_objects !== null ) {
240+ return self ::$ extra_runtime_objects ;
241+ }
242+
243+ $ paths = ['/usr/lib/gcc ' , '/usr/local/lib/gcc ' ];
244+ $ objects = ['crtbeginS.o ' , 'crtendS.o ' ];
245+ $ found = [];
246+
247+ foreach ($ objects as $ obj ) {
248+ $ located = null ;
249+ foreach ($ paths as $ base ) {
250+ $ output = shell_exec ("find {$ base } -name {$ obj } -print -quit 2>/dev/null " );
251+ $ line = trim ((string ) $ output );
252+ if ($ line !== '' ) {
253+ $ located = $ line ;
254+ break ;
255+ }
256+ }
257+ if ($ located ) {
258+ $ found [] = escapeshellarg ($ located );
259+ }
260+ }
261+
262+ self ::$ extra_runtime_objects = implode (' ' , $ found );
263+ return implode (' ' , $ found );
264+ }
229265}
You can’t perform that action at this time.
0 commit comments