From f8c488cded81ae0500125ff823ab4700b8ba39f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sat, 10 Oct 2026 18:56:54 +0200 Subject: [PATCH] Link mimalloc into binaries embedding PHP Since the link closure only walks dependencies of the target, and nothing depends on mimalloc, MIMALLOC builds compiled libmimalloc.a but never linked it, so the binaries kept the system allocator. --- src/StaticPHP/Util/SPCConfigUtil.php | 4 ++++ tests/StaticPHP/Util/SPCConfigUtilTest.php | 24 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/StaticPHP/Util/SPCConfigUtil.php b/src/StaticPHP/Util/SPCConfigUtil.php index 3c9fa37dd..78232b135 100644 --- a/src/StaticPHP/Util/SPCConfigUtil.php +++ b/src/StaticPHP/Util/SPCConfigUtil.php @@ -81,6 +81,10 @@ public function configForResolvedBuild(array $package_names, PackageInstaller $i $php_link_packages[] = $target->getName(); } } + // nothing depends on the allocator, so link it into every binary embedding PHP + if (isset($installer->getResolvedPackages()['mimalloc'])) { + $php_link_packages[] = 'mimalloc'; + } $dependency_overrides['php'] = $php_link_packages; } diff --git a/tests/StaticPHP/Util/SPCConfigUtilTest.php b/tests/StaticPHP/Util/SPCConfigUtilTest.php index 987104991..13da94da8 100644 --- a/tests/StaticPHP/Util/SPCConfigUtilTest.php +++ b/tests/StaticPHP/Util/SPCConfigUtilTest.php @@ -101,6 +101,30 @@ public function testResolvedConfigSupportsExplicitPhpLinkClosureOverrides(): voi $this->assertStringContainsString('/fixtures/libfpm.a', $config['libs']); } + public function testResolvedConfigLinksMimallocIntoPhpOnly(): void + { + $this->loadConfig([ + 'php' => ['type' => 'target', 'depends' => ['core']], + 'core' => ['type' => 'library', 'static-libs' => ['/fixtures/libcore.a']], + 'ext-demo' => ['type' => 'php-extension', 'depends' => ['ext-lib']], + 'ext-lib' => ['type' => 'library', 'static-libs' => ['/fixtures/libext.a']], + 'mimalloc' => ['type' => 'library', 'static-libs' => ['/fixtures/libmimalloc.a']], + ]); + $installer = $this->createInstaller([ + 'core' => 'library', + 'ext-lib' => 'library', + 'ext-demo' => 'static-extension', + 'mimalloc' => 'library', + 'php' => 'target', + ]); + + $php = new SPCConfigUtil(['libs_only_deps' => true])->configForResolvedBuild(['php'], $installer); + $extension = new SPCConfigUtil()->configForResolvedBuild(['ext-demo'], $installer); + + $this->assertStringContainsString('/fixtures/libmimalloc.a', $php['libs']); + $this->assertStringNotContainsString('/fixtures/libmimalloc.a', $extension['libs']); + } + public function testResolvedConfigRejectsRootOutsideResolvedSet(): void { $this->loadLinkFixture();