fix(build): use Mach-O archive section and preserve Composer entrypoint

master
韩天峰 3 weeks ago
parent 5bfe58c0f8
commit c6453746c5
  1. 2
      phpunit/src/Build/IncrementalDeclarationTest.php
  2. 14
      phpunit/src/PreprocessorTest.php
  3. 7
      src/Build/SourcePipelineTrait.php
  4. 6
      src/compiler.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));

@ -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));
}
// ========================================================================

@ -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()) {

@ -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) {

Loading…
Cancel
Save