From c6453746c549c5c063403ac289dda913b0467d4e Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Mon, 21 Sep 2026 09:44:39 +0800 Subject: [PATCH] fix(build): use Mach-O archive section and preserve Composer entrypoint --- phpunit/src/Build/IncrementalDeclarationTest.php | 2 +- phpunit/src/PreprocessorTest.php | 14 ++++++++++---- src/Build/SourcePipelineTrait.php | 7 +++++-- src/compiler.php | 6 +++++- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/phpunit/src/Build/IncrementalDeclarationTest.php b/phpunit/src/Build/IncrementalDeclarationTest.php index 837e388a..0f646e0e 100644 --- a/phpunit/src/Build/IncrementalDeclarationTest.php +++ b/phpunit/src/Build/IncrementalDeclarationTest.php @@ -380,7 +380,7 @@ PHP); $objects = [$firstObject, $secondObject]; $this->invoke($compiler, 'writeLinkCache', $objects, $target); self::assertFileExists( - $this->buildDirectory . '/incremental-bin.typephp-link-cache', + $this->buildDirectory . '/cache/link/incremental-bin.typephp-link-cache', ); self::assertFileDoesNotExist($target . '.typephp-link-cache'); self::assertTrue($this->invoke($compiler, 'hasLinkCache', $objects, $target)); diff --git a/phpunit/src/PreprocessorTest.php b/phpunit/src/PreprocessorTest.php index b4eef057..2e9c83d7 100644 --- a/phpunit/src/PreprocessorTest.php +++ b/phpunit/src/PreprocessorTest.php @@ -187,7 +187,10 @@ class PreprocessorTest extends TestCase $cppFile = $this->compiler->getBuildDir() . '/include/test.cc'; $result = $this->compiler->getObjectFile($cppFile); - $this->assertSame($this->compiler->getBuildDir() . '/include/test.o', $result); + $this->assertSame( + $this->compiler->getBuildDir() . '/cache/objects/generated/include/test.o', + $result, + ); } public function testGetObjectFileDifferentObjectExtension(): void @@ -204,9 +207,12 @@ class PreprocessorTest extends TestCase $cppObject = $this->compiler->getObjectFile('/some/path/foo.cpp'); $ccObject = $this->compiler->getObjectFile('/some/path/foo.cc'); - $this->assertSame('/some/path/foo.c.o', $cObject); - $this->assertSame('/some/path/foo.cpp.o', $cppObject); - $this->assertSame('/some/path/foo.cc.o', $ccObject); + $this->assertSame(dirname($cObject), dirname($cppObject)); + $this->assertSame(dirname($cObject), dirname($ccObject)); + $this->assertStringStartsWith($this->compiler->getBuildDir() . '/cache/objects/external/', $cObject); + $this->assertSame('foo.c.o', basename($cObject)); + $this->assertSame('foo.cpp.o', basename($cppObject)); + $this->assertSame('foo.cc.o', basename($ccObject)); } // ======================================================================== diff --git a/src/Build/SourcePipelineTrait.php b/src/Build/SourcePipelineTrait.php index 65557892..7db05817 100644 --- a/src/Build/SourcePipelineTrait.php +++ b/src/Build/SourcePipelineTrait.php @@ -646,7 +646,10 @@ PHP } else { $assembly = $this->getBuildDir() . '/embedded-files-' . $this->targetName . '.S'; $quotedArchive = json_encode($archive, JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR); - $asmCode = "# archive-sha256: {$archiveHash}\n.section .rodata\n#ifdef __APPLE__\n.globl _typephp_embedded_archive_start\n.p2align 4\n_typephp_embedded_archive_start:\n#else\n.globl typephp_embedded_archive_start\n.p2align 4\ntypephp_embedded_archive_start:\n#endif\n.incbin {$quotedArchive}\n"; + $section = $this->isMacos() ? '__TEXT,__const' : '.rodata'; + $symbol = $this->isMacos() + ? '_typephp_embedded_archive_start' : 'typephp_embedded_archive_start'; + $asmCode = "# archive-sha256: {$archiveHash}\n.section {$section}\n.globl {$symbol}\n.p2align 4\n{$symbol}:\n.incbin {$quotedArchive}\n"; $this->writeFile($assembly, $asmCode); $this->generatedProjectSources[$assembly] = true; $sources[] = $assembly; @@ -1111,7 +1114,7 @@ PHP // Nano keeps the ordinary statically registered Zend class/module // metadata, then adds a direct native process entry beside it. $sourceFiles[] = $this->genExtension(); - if ($this->isBuildModeEmbed() && !$this->isNanoMode()) { + if ($this->isBuildModeBin() && !$this->isNanoMode()) { array_push($sourceFiles, ...$this->genEmbeddedOpcodeTable()); } if ($this->isNanoMode()) { diff --git a/src/compiler.php b/src/compiler.php index 56e6aa3a..ccfa114b 100644 --- a/src/compiler.php +++ b/src/compiler.php @@ -28,7 +28,11 @@ function main(int $argc, array $argv): void ); } - require_once dirname(__DIR__) . '/vendor/autoload.php'; + // The PHP entrypoint already loaded Composer's project autoloader in + // bin/bootstrap.php. The native binary loads its embedded copy here. + if (!defined('TYPEPHP_PHP_SCRIPT_ENTRY')) { + require_once dirname(__DIR__) . '/vendor/autoload.php'; + } $completionStatus = CompletionCommand::execute($argv); if ($completionStatus !== null) {